Created
August 31, 2025 06:46
-
-
Save yohlime/50e9def4aa9a0baf4cd69d777248e78c to your computer and use it in GitHub Desktop.
Minimal Node.js and pnpm GitHub Actions workflow for continuous integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Push | |
| on: | |
| workflow_run: | |
| workflows: ['Test'] | |
| types: | |
| - completed | |
| branches: | |
| - build | |
| - dev | |
| env: | |
| IMG_REGISTRY: ghcr.io | |
| jobs: | |
| build_and_push: | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_branch }} | |
| - name: Install qemu dependency | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y qemu-user-static | |
| - name: Build variables | |
| id: vars | |
| run: | | |
| PKG_NAME=$(jq -r '.name' package.json) | |
| echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_OUTPUT | |
| PKG_VER=$(jq -r '.version' package.json) | |
| echo "PKG_VER=${PKG_VER}" >> $GITHUB_OUTPUT | |
| SHORT_SHA=$(git rev-parse --short=7 ${{ github.sha }}) | |
| echo "SHORT_SHA=${SHORT_SHA}" >> $GITHUB_OUTPUT | |
| BRANCH="${{ github.event.workflow_run.head_branch }}" | |
| if [[ "$BRANCH" == "dev" ]]; then | |
| TAG_SUFFIX=-dev | |
| LATEST_TAG=latest-dev | |
| echo "APP_SITE=" >> $GITHUB_ENV | |
| else | |
| TAG_SUFFIX= | |
| LATEST_TAG=latest | |
| fi | |
| echo "LATEST_TAG=${LATEST_TAG}" >> $GITHUB_OUTPUT | |
| FULL_TAG="${PKG_VER}${TAG_SUFFIX}-${SHORT_SHA}" | |
| echo "FULL_TAG=${FULL_TAG}" >> $GITHUB_OUTPUT | |
| - name: Build image | |
| id: build_image | |
| uses: redhat-actions/buildah-build@v2 | |
| with: | |
| image: ${{ github.repository_owner }}/${{ steps.vars.outputs.PKG_NAME }} | |
| tags: | | |
| ${{ steps.vars.outputs.LATEST_TAG }} | |
| ${{ steps.vars.outputs.FULL_TAG }} | |
| platforms: linux/amd64, linux/arm64 | |
| containerfiles: ./Dockerfile | |
| - name: Echo Outputs | |
| run: | | |
| echo "Image: ${{ steps.build_image.outputs.image }}" | |
| echo "Tags: ${{ steps.build_image.outputs.tags }}" | |
| echo "Tagged Image: ${{ steps.build_image.outputs.image-with-tag }}" | |
| - name: Check images created | |
| run: buildah images | grep '${{ steps.vars.outputs.PKG_NAME }}' | |
| - name: Check manifest | |
| run: | | |
| set -x | |
| buildah manifest inspect ${{ steps.build_image.outputs.image }}:${{ steps.vars.outputs.LATEST_TAG }} | |
| - name: Log in to GHCR | |
| uses: redhat-actions/podman-login@v1 | |
| with: | |
| registry: ${{ env.IMG_REGISTRY }} | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Push image | |
| uses: redhat-actions/push-to-registry@v2 | |
| with: | |
| registry: ${{ env.IMG_REGISTRY }} | |
| image: ${{ github.repository_owner }}/${{ steps.vars.outputs.PKG_NAME }} | |
| tags: | | |
| ${{ steps.vars.outputs.LATEST_TAG }} | |
| ${{ steps.vars.outputs.FULL_TAG }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test | |
| on: | |
| push: | |
| pull_request: | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| run_install: false | |
| - name: Setup NodeJS | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: 'pnpm' | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Run tests | |
| run: pnpm test:unit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment