|
20 | 20 | runs-on: ubuntu-latest |
21 | 21 | outputs: |
22 | 22 | release_created: ${{ steps.release.outputs.release_created }} |
23 | | - # Consumed by the publish job's dispatch: without this mapping the dispatch ref would |
24 | | - # be empty, and `gh workflow run --ref ""` silently falls back to the default branch |
25 | | - # instead of the released tag. |
| 23 | + # Consumed by the publish job's checkout: without this mapping the checkout ref would be |
| 24 | + # empty and the publish would build the triggering branch head instead of the released |
| 25 | + # tag's exact commit. |
26 | 26 | tag_name: ${{ steps.release.outputs.tag_name }} |
27 | 27 | steps: |
28 | 28 | - uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0 |
@@ -57,28 +57,39 @@ jobs: |
57 | 57 | git push origin scalar-next |
58 | 58 | publish: |
59 | 59 | needs: release-please |
| 60 | + # `!cancelled()` keeps publishing even when the back-sync to the integration branch |
| 61 | + # failed: a raced integration branch must not block the release from reaching its |
| 62 | + # registry. |
60 | 63 | if: ${{ !cancelled() && needs.release-please.outputs.release_created == 'true' }} |
61 | 64 | runs-on: ubuntu-latest |
| 65 | + # Job-level permissions replace the workflow's release-cutting grants with the publish |
| 66 | + # floor. OIDC trusted publishing verifies this run's claims, which name this workflow |
| 67 | + # file — register release-please.yml as the trusted publisher on the registry. |
62 | 68 | permissions: |
63 | | - actions: write |
| 69 | + contents: read |
| 70 | + id-token: write |
| 71 | + packages: write |
| 72 | + env: |
| 73 | + VERSIONING_POLICY: manual |
64 | 74 | steps: |
65 | | - - name: Publish via the release workflow at the released tag |
66 | | - env: |
67 | | - GH_TOKEN: ${{ github.token }} |
68 | | - TAG: ${{ needs.release-please.outputs.tag_name }} |
69 | | - # Dispatch, then watch the run to completion: the dispatch API does not return the run |
70 | | - # it created, so the newest workflow_dispatch run on the tag is polled into view (the |
71 | | - # tag is unique per release, so it can only be this dispatch or an identical manual |
72 | | - # re-publish) and a failed or missing run fails this job loudly. |
73 | | - run: | |
74 | | - gh workflow run sdk-release.yml --repo "${GITHUB_REPOSITORY}" --ref "${TAG}" |
75 | | - for _ in $(seq 1 12); do |
76 | | - sleep 5 |
77 | | - run_id="$(gh run list --repo "${GITHUB_REPOSITORY}" --workflow sdk-release.yml --event workflow_dispatch --branch "${TAG}" --json databaseId --jq '.[0].databaseId // empty')" |
78 | | - [ -n "${run_id}" ] && break |
79 | | - done |
80 | | - if [ -z "${run_id}" ]; then |
81 | | - echo "::error::sdk-release.yml was dispatched for ${TAG} but no run appeared." |
82 | | - exit 1 |
83 | | - fi |
84 | | - gh run watch "${run_id}" --repo "${GITHUB_REPOSITORY}" --exit-status |
| 75 | + # Publishing runs inline — a top-level job of this same run — rather than dispatching |
| 76 | + # sdk-release.yml: workflow_dispatch resolves the target workflow on the repository's |
| 77 | + # default branch only, so a dispatch would 404 whenever the release line is any other |
| 78 | + # branch, while OIDC trusted publishing accepts this job because it stays top-level |
| 79 | + # (never a reusable-workflow call). The release-please job cut the tag earlier in this |
| 80 | + # run; checking it out publishes exactly the released commit, not the branch head that |
| 81 | + # triggered the workflow. |
| 82 | + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 |
| 83 | + with: |
| 84 | + ref: ${{ needs.release-please.outputs.tag_name }} |
| 85 | + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
| 86 | + with: |
| 87 | + node-version: "22.14.0" |
| 88 | + registry-url: "https://registry.npmjs.org" |
| 89 | + - run: npm install |
| 90 | + - run: npm run build |
| 91 | + # OIDC trusted publishing needs npm >= 11.5; pinned to the major (not `latest`) so a new |
| 92 | + # npm major raising its Node engine floor cannot break publishes against the pinned Node. |
| 93 | + - run: npm install -g npm@11 |
| 94 | + - name: Publish to npm |
| 95 | + run: node scripts/publish-npm.mjs |
0 commit comments