Skip to content

feat(publish-preview): add OIDC variant of the workflow - #311

Merged
Mrtenz merged 3 commits into
mainfrom
mrtenz/publish-preview-oidc
Nov 13, 2026
Merged

Mrtenz merged 3 commits into
mainfrom
mrtenz/publish-preview-oidc

Conversation

@Mrtenz

@Mrtenz Mrtenz commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Explanation

GitHub Actions permissions can't be set dynamically, and a reusable workflow that declares id-token: write forces every caller to grant it, even when the job is skipped. An oidc input can't make the permission optional.

This adds publish-preview-oidc.yml, which grants id-token: write and publishes without an npm token. Callers pick the file that matches their authentication mode, so publish-preview.yml stays token-only with its narrower permissions.

The is-fork-pull-request, react-to-comment, and build-preview jobs move into a shared publish-preview-build.yml workflow that both workflows call. The publish job stays duplicated because its permissions differ.


Note

Medium Risk
Touches NPM publish automation and adds an OIDC publishing path; behavior change is mostly structural, but mistakes could affect preview package publishing or permissions.

Overview
Preview build steps are extracted into a reusable prepare-preview.yml workflow (fork detection, comment reaction, PR checkout, manifest renaming, install/build ordering, and artifact upload) and both publish flows now call it via a build job, gating publish with needs.build.outputs.is-fork.

A new publish-preview-oidc.yml reusable workflow mirrors the existing token-based publisher but requests id-token: write and publishes without PUBLISH_PREVIEW_NPM_TOKEN, so consumers can pick OIDC vs secret-based auth without forcing extra permissions on token-only callers.

publish-preview.yml is slimmed down to the shared build plus its existing token-authenticated publish job (unchanged sanitization, publish, and PR comment steps).

Reviewed by Cursor Bugbot for commit 67c76e6. Bugbot is set up for automated code reviews on this repo. Configure here.

GitHub Actions `permissions` cannot be set dynamically, and a reusable workflow that declares `id-token: write` forces every caller to grant it, even when the job is skipped. Add `publish-preview-oidc.yml`, which grants `id-token: write` and publishes without an npm token. Callers pick the file that matches their authentication mode. `publish-preview.yml` stays token-only and keeps its narrower permissions.

Move the `is-fork-pull-request`, `react-to-comment`, and `build-preview` jobs into a shared `publish-preview-build.yml` workflow that both workflows call, so the build logic isn't duplicated.
secrets:
BUILD_ENV: ${{ secrets.BUILD_ENV }}

publish-preview:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could share more with publish-preview.yml here if we move this logic into a composite action. Unsure if it's worth the effort, though.

@Mrtenz
Mrtenz marked this pull request as ready for review November 11, 2026 14:51

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7146735. Configure here.

Comment thread .github/workflows/publish-preview.yml Resolved
A reusable workflow call reports success when its inner jobs are skipped. After the build moved into `publish-preview-build.yml`, fork pull requests skipped `build-preview`, but the `build` call still succeeded. `publish-preview` then ran, found no `preview-build-artifacts`, and failed.

The build workflow now exposes an `is-fork` output, and `publish-preview` only runs when it is `false`, in both `publish-preview.yml` and `publish-preview-oidc.yml`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Should we call this prepare-preview.yml or build-preview.yml? In docs and elsewhere I've been using "preview build" as an alias for "preview version", so this could be misinterpreted as the workflow that runs the publish step.

Or did you want to make sure all of the preview build files were grouped together alphabetically?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it for alphabetical grouping yes, but can rename it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's still grouped (for now) when we name it prepare-preview.yml, so I guess it's fine.

if: ${{ inputs.is-monorepo && !inputs.dry-run }}
run: yarn workspaces foreach --no-private --all exec yarn npm publish --tag preview
env:
YARN_NPM_REGISTRY_SERVER: 'https://registry.npmjs.org'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the only differences between this workflow and publish-preview.yml is that 1) we set the id-token: true permission and 2) we no longer pass YARN_NPM_AUTH_TOKEN to the publish steps. Does that sound right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's right.

We can't conditionally set permissions, so we have to copy this, unfortunately.

Comment on lines +59 to +60
build:
name: Build

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be named differently matching the composite action name?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought naming it "Build" was fine, since that's what prepare-preview does. Can rename if you prefer.


- name: Publish preview builds (monorepo)
if: ${{ inputs.is-monorepo && !inputs.dry-run }}
run: yarn workspaces foreach --no-private --all exec yarn npm publish --tag preview

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do --provenance?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We trigger this workflow from pull request comments, which runs the workflow from main, so provenance would point to the wrong branch.

It also doesn't provide much benefit for preview builds in general, I think.

@Mrtenz
Mrtenz merged commit 12b27c4 into main Nov 13, 2026
10 checks passed
@Mrtenz
Mrtenz deleted the mrtenz/publish-preview-oidc branch November 13, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants