name: Node.js Test Package on: # pull_request_target required for pull-requests:write permission on fork PRs pull_request: types: # Types run for by default - opened - reopened - synchronize # Merged - closed push: branches: - 'main' concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} cancel-in-progress: true jobs: path-filter: permissions: pull-requests: read runs-on: ubuntu-latest outputs: changes: ${{ steps.filter.outputs.changes }} steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 with: ref: ${{ env.ref }} - id: filter uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 with: filters: | changes: - '.github/workflows/node-test-package.yml' - 'packages/**' - 'src/**' - '*' pkg-pr-new: needs: - path-filter if: ${{ needs.path-filter.outputs.changes == 'true' }} runs-on: ubuntu-latest outputs: package_name: ${{ steps.pkg-pr-new.outputs.PACKAGE_NAME }} package_url: ${{ steps.pkg-pr-new.outputs.PACKAGE_URL }} steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 with: submodules: 'recursive' - uses: volta-cli/action@5c175f92dea6f48441c436471e6479dbc192e194 # v4.2.1 - 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 }}- - id: pkg-pr-new run: | set -x npm ci npx --yes pkg-pr-new publish --compact --json pkg.json --comment=off cat pkg.json echo "PACKAGE_NAME=$(jq --raw-output '.packages[0].name' pkg.json)" >> "${GITHUB_OUTPUT}" echo "PACKAGE_URL=$(jq --raw-output '.packages[0].url' pkg.json)" >> "${GITHUB_OUTPUT}" test-npx: if: ${{ startsWith(github.event_name, 'pull_request') && github.event.action != 'closed' }} needs: - pkg-pr-new name: test-npx (${{ matrix.os }}) runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: - ubuntu-latest - ubuntu-24.04-arm - macos-latest - macos-13 - windows-latest - windows-11-arm steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 - uses: volta-cli/action@5c175f92dea6f48441c436471e6479dbc192e194 # v4.2.1 - run: | #npx --yes "${{ needs.pkg-pr-new.outputs.package_url }}" --help npm exec --yes --foreground-scripts "${{ needs.pkg-pr-new.outputs.package_url }}" -- --help test-npm-install-global: if: ${{ startsWith(github.event_name, 'pull_request') && github.event.action != 'closed' }} needs: - pkg-pr-new name: test-npm-install-global (${{ matrix.os }}) runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: - ubuntu-latest - ubuntu-24.04-arm - macos-latest - macos-13 - windows-latest - windows-11-arm steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 - uses: volta-cli/action@5c175f92dea6f48441c436471e6479dbc192e194 # v4.2.1 - shell: bash run: | set -x npm install --global --foreground-scripts "${{ needs.pkg-pr-new.outputs.package_url }}" PATH="$(npm get prefix --global)/bin:$PATH" export PATH igir --help # !!! This check should be required by GitHub !!! test-package-status-check: if: always() needs: - pkg-pr-new - test-npx - test-npm-install-global runs-on: ubuntu-latest steps: - uses: re-actors/alls-green@release/v1 with: jobs: ${{ toJSON(needs) }} allowed-skips: pkg-pr-new, test-npx, test-npm-install-global npm-exec-branch-comment: if: ${{ startsWith(github.event_name, 'pull_request') && github.event.action != 'closed' }} needs: - pkg-pr-new - test-npx - test-npm-install-global permissions: pull-requests: write runs-on: ubuntu-latest steps: - uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1 with: message: | ## :test_tube: Package testing instructions This pull request can be tested locally with the following command: ```shell npx --yes "${{ needs.pkg-pr-new.outputs.package_url }}" [commands..] [options] ``` _Comment generated by the [${{ github.workflow }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}) workflow._ comment-tag: npm-exec npm-exec-merge-comment: needs: - path-filter if: ${{ needs.path-filter.outputs.changes == 'true' && startsWith(github.event_name, 'pull_request') && github.event.action == 'closed' && github.event.pull_request.merged && github.event.pull_request.base.ref == 'main' }} permissions: pull-requests: write runs-on: ubuntu-latest steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 - uses: volta-cli/action@5c175f92dea6f48441c436471e6479dbc192e194 # v4.2.1 - id: package run: | echo "PACKAGE_NAME=$(jq --raw-output '.name' package.json)" >> "${GITHUB_OUTPUT}" - run: | npx --yes "https://pkg.pr.new/${{ steps.package.outputs.PACKAGE_NAME }}@${{ github.event.pull_request.base.ref }}" --help - uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1 with: message: | ## :test_tube: Package testing instructions This pull request has been merged, its base branch can be tested locally with the following command: ```shell npx --yes "https://pkg.pr.new/${{ steps.package.outputs.PACKAGE_NAME }}@${{ github.event.pull_request.base.ref }}" [commands..] [options] ``` _Comment generated by the [${{ github.workflow }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}) workflow._ comment-tag: npm-exec mode: recreate