diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index 1b62975..0f425cf 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -26,19 +26,25 @@ concurrency: cancel-in-progress: false jobs: - prerelease: - name: Publish Prerelease Snapshot + # Tests run without id-token: write, so code on the pushed branch never runs + # next to the publish identity unless a reviewer approves the publish job. + test: + name: Test Prerelease Candidate runs-on: ubuntu-latest timeout-minutes: 20 permissions: contents: read - id-token: write + + outputs: + tag: ${{ steps.channel.outputs.tag }} + has_changesets: ${{ steps.changesets.outputs.has_changesets }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 + persist-credentials: false - uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 with: @@ -48,22 +54,30 @@ jobs: with: node-version-file: '.nvmrc' cache: pnpm - registry-url: https://registry.npmjs.org/ - - - name: Use an npm that supports trusted publishing - run: npm install -g npm@^11.5.1 - name: Determine release channel id: channel + env: + EVENT_NAME: ${{ github.event_name }} + INPUT_TAG: ${{ inputs.tag }} + REF_NAME: ${{ github.ref_name }} run: | - if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then - TAG="${{ inputs.tag }}" - elif [ "${{ github.ref_name }}" = "dev" ]; then + if [ "$EVENT_NAME" = "workflow_dispatch" ]; then + TAG="$INPUT_TAG" + elif [ "$REF_NAME" = "dev" ]; then TAG="beta" else TAG="rc" fi + case "$TAG" in + alpha|beta|rc) ;; + *) + echo "::error::Unsupported prerelease tag" + exit 1 + ;; + esac + echo "tag=$TAG" >> "$GITHUB_OUTPUT" - name: Check release intent @@ -77,8 +91,44 @@ jobs: - name: Test workspace run: pnpm test + publish: + name: Publish Prerelease Snapshot + needs: test + if: needs.test.outputs.has_changesets == 'true' + runs-on: ubuntu-latest + timeout-minutes: 20 + # Protected environment: required reviewers approve every publish, and the + # npm trusted publisher is bound to this environment name. + environment: npm-prerelease + + permissions: + contents: read + id-token: write + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + + - uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 + with: + version: 10.33.0 + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version-file: '.nvmrc' + cache: pnpm + registry-url: https://registry.npmjs.org/ + + - name: Use an npm that supports trusted publishing + run: npm install -g npm@^11.5.1 + + - name: Install dependencies + run: pnpm install --frozen-lockfile + - name: Publish snapshot packages - if: steps.changesets.outputs.has_changesets == 'true' - run: pnpm release:${{ steps.channel.outputs.tag }} env: NPM_CONFIG_PROVENANCE: true + TAG: ${{ needs.test.outputs.tag }} + run: pnpm "release:$TAG"