-
Notifications
You must be signed in to change notification settings - Fork 119
Add staged OIDC publish workflow #524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+93
−1
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
39b37d3
Add staged OIDC publish workflow
patocallaghan ea92a5d
Pin stage-publish to the ancestry-checked SHA (close TOCTOU window)
patocallaghan 79e3ae3
Bump actions/checkout to v7.0.0
patocallaghan 7083ed5
Fix Node-floor comment and add verify timeout
patocallaghan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # Release workflow for intercom-client. | ||
| # | ||
| # Publishing model: OIDC trusted publishing + npm staged publishing. CI authenticates to | ||
| # npm with a short-lived OIDC token (no stored npm token) and stages the release; a | ||
| # maintainer then promotes it from the npm staging area with 2FA. Replaces token-based publishing. | ||
| # | ||
| # Listed in .fernignore so it is not overwritten by code generation. | ||
| name: Publish (staged) | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] # cutting a Release creates the tag AND fires this | ||
|
|
||
| permissions: | ||
| contents: read # workflow default (least privilege); only stage-publish also needs id-token, granted on that job | ||
|
|
||
| concurrency: | ||
| group: publish-${{ github.workflow }} # serialize publishes; no dist-tag races | ||
| cancel-in-progress: false # queue, don't kill an in-flight publish | ||
|
|
||
| jobs: | ||
| verify: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 # backstop a hung step (checkout/guards only; no install/build) | ||
| outputs: | ||
| sha: ${{ steps.resolve.outputs.sha }} # ancestry-checked commit, pinned for downstream | ||
| steps: | ||
| - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | ||
| with: | ||
| persist-credentials: false | ||
| fetch-depth: 0 # full history for the ancestry check below | ||
| - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 | ||
| with: | ||
| node-version: '22' # staged publishing needs Node >= 22.14.0 (npm >= 11.15.0); repo has no .nvmrc | ||
| package-manager-cache: false # release-triggered: disable auto-cache (zizmor cache-poisoning) | ||
| - name: Assert Release tag matches package.json version | ||
| env: | ||
| RELEASE_TAG: ${{ github.event.release.tag_name }} | ||
| run: | | ||
| PKG="$(node -p "require('./package.json').version")" | ||
| [ "${RELEASE_TAG#v}" = "$PKG" ] || { echo "tag $RELEASE_TAG != package.json v$PKG"; exit 1; } | ||
| - name: Refuse releases not on the default branch | ||
| id: resolve | ||
| env: | ||
| RELEASE_TAG: ${{ github.event.release.tag_name }} | ||
| DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | ||
| run: | | ||
| git merge-base --is-ancestor "$GITHUB_SHA" "origin/$DEFAULT_BRANCH" \ | ||
| || { echo "release $RELEASE_TAG not reachable from $DEFAULT_BRANCH — refusing"; exit 1; } | ||
| echo "sha=$GITHUB_SHA" >> "$GITHUB_OUTPUT" # downstream checks out this exact SHA, not the mutable tag | ||
|
|
||
| stage-publish: | ||
| needs: verify | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 # cap a hung publish | ||
| permissions: | ||
| contents: read | ||
| id-token: write # OIDC trusted publishing: only this job mints the token | ||
|
patocallaghan marked this conversation as resolved.
|
||
| steps: | ||
| - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | ||
| with: | ||
| persist-credentials: false | ||
| ref: ${{ needs.verify.outputs.sha }} # the ancestry-checked SHA, immune to tag re-pointing (TOCTOU) | ||
| - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 | ||
| with: | ||
| node-version: '22' | ||
| registry-url: 'https://registry.npmjs.org' | ||
| package-manager-cache: false | ||
| - run: corepack enable | ||
| - run: pnpm install --frozen-lockfile | ||
| - run: pnpm run build # mandatory: dist/ is gitignored, so the published artifact is built here | ||
| - run: npm install -g npm@11.15.0 # npm CLI: staged publishing needs npm >= 11.15.0 | ||
| - name: Resolve dist-tag (a prerelease must never go to `latest`) | ||
| id: disttag | ||
| env: | ||
| ALPHA_TAG: alpha | ||
| BETA_TAG: beta | ||
| PRERELEASE_TAG: next | ||
| run: | | ||
| VERSION="$(node -p "require('./package.json').version")" | ||
| case "$VERSION" in | ||
| *-alpha.*) TAG="$ALPHA_TAG" ;; | ||
| *-beta.*) TAG="$BETA_TAG" ;; | ||
| *-*) TAG="$PRERELEASE_TAG" ;; | ||
| *) TAG="latest" ;; | ||
| esac | ||
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | ||
| - name: Stage publish | ||
| env: | ||
| DIST_TAG: ${{ steps.disttag.outputs.tag }} | ||
| run: npm stage publish --tag "$DIST_TAG" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirm on the first real release (fails closed, so safe): this ancestry gate needs
origin/$DEFAULT_BRANCHto resolve.actions/checkoutwithfetch-depth: 0does populaterefs/remotes/origin/*, so it should be fine — but if it ever isn't, every publish blocks here rather than failing open, so worth eyeballing this step in the first run's log.