# Requires repo secret: PERSONAL_ACCESS_TOKEN with permissions: # Contents: read and write # Pull Requests: read and write name: Node Native Addons Prebuild on: # Note: dorny/paths-filter can't use 'pull_request' with the 'base' option push: branches-ignore: - 'main' # Don't prebuild on version bump PRs - '*/[0-9]+.[0-9]+.[0-9]+' workflow_dispatch: inputs: ref: description: 'Git branch' required: true type: string concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true env: ref: ${{ inputs.ref || github.head_ref }} jobs: path-filter: if: ${{ github.actor == 'emmercm' }} permissions: pull-requests: read runs-on: ubuntu-latest outputs: changes: ${{ steps.change-filter.outputs.changes == 'true' && steps.commit-filter.outputs.changes == 'false' && 'true' || 'false' }} steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 with: ref: ${{ env.ref }} # Prebuild if any relevant source file has changed - id: change-filter uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 with: filters: | changes: - '.github/workflows/napi-prebuild.yml' - 'packages/zlib*/**' - 'packages/zstd*/**' - 'package*.json' # DON'T prebuild if the last commit was prebuilds - id: commit-filter uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 with: base: ${{ github.ref }} filters: | changes: - 'packages/*/addon*/**' - 'packages/*/prebuilds*/**' prebuild: needs: - path-filter if: ${{ needs.path-filter.outputs.changes == 'true' || github.event_name == 'workflow_dispatch' }} runs-on: ${{ matrix.os }} defaults: run: shell: bash timeout-minutes: 30 # QEMU cross-builds name: prebuildify (${{ matrix.os }}, ${{ matrix.docker_arch || 'default' }}) strategy: fail-fast: false matrix: include: # docker manifest inspect node: | jq '.manifests[].platform' - os: ubuntu-latest docker_arch: linux/amd64 - os: ubuntu-24.04-arm docker_arch: linux/arm64/v8 - os: macos-13 - os: macos-latest - os: windows-latest # TODO(cemmer): Node.js didn't start publishing Windows ARM64 images until v20 #- os: windows-11-arm steps: # Setup and install - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 with: ref: ${{ env.ref }} submodules: 'recursive' - uses: volta-cli/action@5c175f92dea6f48441c436471e6479dbc192e194 # v4.2.1 with: node-version: 18 - uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 with: path: | ~/.npm ~\AppData\Roaming\npm-cache key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-npm- ${{ runner.os }}- # Prebuild - shell: bash run: | npm ci --ignore-scripts - if: ${{ startsWith(matrix.os, 'ubuntu') }} uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0 - id: linux-vars if: ${{ startsWith(matrix.os, 'ubuntu') }} run: | set -x echo "VERSIONS_NODE=$(node --print 'process.versions.node')" >> "${GITHUB_OUTPUT}" DOCKER_ARCH=${{ matrix.docker_arch }} DOCKER_ARCH=${DOCKER_ARCH/linux\//} DOCKER_ARCH=${DOCKER_ARCH//\//} echo "DOCKER_ARCH=${DOCKER_ARCH}" >> "${GITHUB_OUTPUT}" - if: ${{ startsWith(matrix.os, 'ubuntu') }} id: build-docker uses: addnab/docker-run-action@v3 with: image: node:${{ steps.linux-vars.outputs.VERSIONS_NODE }} shell: bash options: | --platform ${{ matrix.docker_arch }} --volume ${{ github.workspace }}:/build --workdir /build run: | set -x node --print 'process' find packages -maxdepth 1 -type d \( -name "zlib*" -o -name "zstd*" \) | while IFS= read -r dir; do cd "${dir}" rm -rf addon* prebuilds* ../../node_modules/.bin/prebuildify --target "$(node --print 'process.versions.node')" --napi --strip --out "addon-$(basename "$(pwd)")" cd ../.. done find packages/*/addon* -type f -print0 | xargs -0 ls -al # Test the build rm -rf packages/*/build npm ci --foreground-scripts npm run test:unit packages - if: ${{ !startsWith(matrix.os, 'ubuntu') }} id: build run: | set -x node --print 'process' find packages -maxdepth 1 -type d \( -name "zlib*" -o -name "zstd*" \) | while IFS= read -r dir; do cd "${dir}" rm -rf addon* prebuilds* ../../node_modules/.bin/prebuildify --target "$(node --print 'process.versions.node')" --napi --strip --out "addon-$(basename "$(pwd)")" cd ../.. done find packages/*/addon* -type f -print0 | xargs -0 ls -al # Test the build rm -rf packages/*/build npm ci --foreground-scripts npm run test:unit packages - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: prebuild-${{ matrix.os }}-${{ steps.linux-vars.outputs.DOCKER_ARCH }} path: packages/*/addon*/ include-hidden-files: true if-no-files-found: error retention-days: 7 commit: needs: - prebuild runs-on: ubuntu-latest steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 with: ref: ${{ env.ref }} # Token needed to trigger Actions on push token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} - run: | set -x find packages/*/addon* -type f -print0 | xargs -0 ls -al rm -rf packages/*/addon*/ packages/*/prebuilds*/ find packages/*/addon* -type f -print0 | xargs -0 ls -al - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 with: path: packages/ merge-multiple: true - id: bump-and-commit run: | set -x find packages/*/addon* -type f -print0 | xargs -0 ls -al git add --all packages git status USER_EMAIL="${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com" echo "USER_EMAIL=${USER_EMAIL}" >> "${GITHUB_OUTPUT}" git config --global user.email "${USER_EMAIL}" USER_NAME="$(gh api "/users/${GITHUB_ACTOR}" | jq .name -r)" echo "USER_NAME=${USER_NAME}" >> "${GITHUB_OUTPUT}" git config --global user.name "${USER_NAME}" git commit -m "prebuilds @ https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}" || exit 0 git push env: GH_TOKEN: ${{ github.token }}