diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2d108f14..877f1eb3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,8 +4,6 @@ on: pull_request: types: [closed] branches: [main] - # Temporary first-release retry: PR #345 is already merged and verified. - workflow_dispatch: permissions: contents: read @@ -23,10 +21,6 @@ jobs: release: needs: checks - if: >- - ${{ !cancelled() && github.repository == 'TanStack/oracles' && - (needs.checks.result == 'success' || - (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main')) }} # Skipped PR closures never enter this queue. Retain eligible pending jobs. concurrency: group: release-main @@ -37,27 +31,11 @@ jobs: contents: write id-token: write steps: - - name: Verify merged version PR - id: release-pr - run: | - set -euo pipefail - merge_sha=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$RELEASE_PR" | jq -er \ - --arg repo "$GITHUB_REPOSITORY" --arg merge "$EXPECTED_MERGE_SHA" ' - select(.merged == true and .base.ref == "main" and - .head.ref == "changeset-release/main" and - .head.repo.full_name == $repo and .merge_commit_sha == $merge) | - .merge_commit_sha - ') - printf 'merge_sha=%s\n' "$merge_sha" >> "$GITHUB_OUTPUT" - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - RELEASE_PR: ${{ github.event.pull_request.number || '345' }} - EXPECTED_MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha || 'a1323afacd8c663ff10b624ac424b3d9443d654b' }} - name: Checkout uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: fetch-depth: 0 - ref: ${{ steps.release-pr.outputs.merge_sha }} + ref: ${{ github.event.pull_request.merge_commit_sha }} persist-credentials: true # Changesets pushes release tags. - name: Setup Tools uses: tanstack/config/.github/setup@e4b48f16568324f76f467aa4c2aac2f05db632c3 diff --git a/RELEASING.md b/RELEASING.md index c9b2e697..26718cdf 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -76,3 +76,15 @@ release. `pnpm changeset status` shows the pending release plan. For a manual publish from a built version commit, run `pnpm run changeset:publish`. + +## Recovering a tag push after npm publication + +If npm publication succeeds but GitHub rejects the package tags because the +token lacks `workflows` permission, the packages are already published. +This can happen when the release uses an older merge commit whose workflows +differ from the current workflow. A maintainer with Contents and Workflows +write access can push the package tags at that exact merge commit, then rerun +the failed release job to finish the GitHub releases. Do not publish a new +package version for this metadata failure. The built-in `GITHUB_TOKEN` cannot +be granted Workflows write access through workflow YAML; unattended recovery +requires a GitHub App token or fine-grained PAT with that permission. diff --git a/scripts/release-workflows.test.mjs b/scripts/release-workflows.test.mjs index aad254c6..924c5f00 100644 --- a/scripts/release-workflows.test.mjs +++ b/scripts/release-workflows.test.mjs @@ -32,38 +32,9 @@ test('only guarded publication jobs enter the release queue', () => { queue: 'max', }) assert.equal(release.jobs.release.needs, 'checks') - const eligible = new Function( - 'github', - 'needs', - 'cancelled', - `return (${release.jobs.release.if.replace(/^\$\{\{\s*|\s*\}\}$/g, '')})`, - ) - const context = { - repository: 'TanStack/oracles', - event_name: 'pull_request', - ref: 'refs/heads/main', - } - assert.equal( - eligible(context, { checks: { result: 'success' } }, () => false), - true, - ) - assert.equal( - eligible(context, { checks: { result: 'failure' } }, () => false), - false, - ) - context.event_name = 'workflow_dispatch' - assert.equal( - eligible(context, { checks: { result: 'skipped' } }, () => false), - true, - ) - context.ref = 'refs/heads/feature' - assert.equal( - eligible(context, { checks: { result: 'skipped' } }, () => false), - false, - ) + assert.equal(release.jobs.release.if, undefined) assert.deepEqual(release.on, { pull_request: { types: ['closed'], branches: ['main'] }, - workflow_dispatch: null, }) const allowed = new Function('github', `return (${release.jobs.checks.if})`) const event = { @@ -118,73 +89,10 @@ test('main pushes only maintain the version PR and releases use the merge commit const checkout = release.jobs.release.steps.find((step) => step.uses?.startsWith('actions/checkout@'), ) - assert.equal(checkout.with.ref, '${{ steps.release-pr.outputs.merge_sha }}') -}) - -test('manual release resolves only the verified merged version PR', (t) => { - const resolver = release.jobs.release.steps.find( - (step) => step.id === 'release-pr', + assert.equal( + checkout.with.ref, + '${{ github.event.pull_request.merge_commit_sha }}', ) - assert.ok(resolver, 'release metadata must be verified before checkout') - const temporary = mkdtempSync(join(tmpdir(), 'release-pr-metadata-')) - t.after(() => rmSync(temporary, { recursive: true, force: true })) - const bin = join(temporary, 'bin') - mkdirSync(bin) - const gh = join(bin, 'gh') - writeFileSync(gh, '#!/bin/sh\ncat "$RELEASE_METADATA_FIXTURE"\n') - chmodSync(gh, 0o755) - const merge = 'a1323afacd8c663ff10b624ac424b3d9443d654b' - const valid = { - merged: true, - merge_commit_sha: merge, - base: { ref: 'main' }, - head: { - ref: 'changeset-release/main', - repo: { full_name: 'TanStack/oracles' }, - }, - } - const fixture = join(temporary, 'pr.json') - const output = join(temporary, 'output') - const execute = () => - execFileSync('bash', ['-euo', 'pipefail', '-c', resolver.run], { - env: { - ...process.env, - PATH: `${bin}:${process.env.PATH}`, - RELEASE_METADATA_FIXTURE: fixture, - RELEASE_PR: '345', - GITHUB_REPOSITORY: 'TanStack/oracles', - EXPECTED_MERGE_SHA: merge, - GITHUB_OUTPUT: output, - }, - stdio: 'pipe', - }) - writeFileSync(fixture, JSON.stringify(valid)) - execute() - assert.equal(readFileSync(output, 'utf8'), `merge_sha=${merge}\n`) - for (const change of [ - (pr) => { - pr.merged = false - }, - (pr) => { - pr.base.ref = 'feature' - }, - (pr) => { - pr.head.ref = 'feature' - }, - (pr) => { - pr.head.repo.full_name = 'fork/oracles' - }, - (pr) => { - pr.merge_commit_sha = 'b'.repeat(40) - }, - ]) { - const invalid = structuredClone(valid) - change(invalid) - writeFileSync(fixture, JSON.stringify(invalid)) - writeFileSync(output, '') - assert.throws(execute) - assert.equal(readFileSync(output, 'utf8'), '') - } }) const fakeCommands = `#!/usr/bin/env node