Skip to content

feat(publish-preview-oidc): publish tarballs packed in the build job - #348

Merged
Mrtenz merged 4 commits into
mainfrom
mrtenz/preview-publish-tarballs
Nov 23, 2026
Merged

Mrtenz merged 4 commits into
mainfrom
mrtenz/preview-publish-tarballs

Conversation

@Mrtenz

@Mrtenz Mrtenz commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

The publish job in publish-preview-oidc checks out the default branch, overlays the workspace from the pull request build (package.json files, yarn.lock, and packages/*/), and runs yarn install to reconcile the two. As a result, the job that holds id-token: write mixes trusted files from the default branch with untrusted files from the pull request, and it needs a sanitisation step to strip lifecycle scripts and registry overrides before publishing.

With this change, the build job packs the packages and uploads only the tarballs. The publish job no longer checks out the repository or runs Yarn.

  • prepare-preview has a new pack input, which is off by default. When it is enabled, the workflow strips pack and publish lifecycle scripts from the selected packages, runs yarn pack for each one, and uploads the tarballs as preview-build-tarballs. The token-based publish-preview workflow doesn't set the input, so its behaviour is unchanged.
  • The publish job downloads the tarballs from the current run and validates all of them before it publishes any. Each tarball must contain only plain paths under a single package/ directory and exactly one package/package.json. The manifest must have a name in the preview scope, a -preview-<sha> version, and a publishConfig that sets only access and the NPM registry. Because NPM strips the top-level directory before it reads the manifest, a crafted tarball could otherwise make NPM use a different manifest from the one that was validated.
  • Tarballs are published with npm publish <file>, using the NPM bundled with the runner.

Note

Medium Risk
Changes the trusted path for npm publishing and OIDC credentials; validation is stricter but any gap in tarball checks could still be security-sensitive.

Overview
Preview publishing for publish-preview-oidc no longer ships the whole workspace into the job that has id-token: write. The reusable prepare-preview workflow gains a pack input (default false); when enabled it strips pack/publish lifecycle scripts, runs yarn pack for the selected packages, and uploads preview-build-tarballs instead of preview-build-artifacts.

The OIDC publish job now downloads those tarballs only—no checkout, Yarn, or manifest sanitization on a mixed trusted/untrusted tree. It validates each .tgz (layout under package/, preview scope name, -preview-<sha> version, allowed publishConfig) then publishes with npm publish (--ignore-scripts, fixed registry). Monorepo/polyrepo PR comment generation is split so polyrepo reads the version from the tarball.

Shell fixes in package selection avoid empty mapfile issues when jq returns nothing.

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

The publish job used to overlay workspace files from the pull request
build on top of a checkout of the default branch, then run
`yarn install` to reconcile the two. That mixed trusted and untrusted
files in the job that holds `id-token: write`.

Now the build job packs the packages and uploads only the tarballs. The
publish job no longer checks out the repository or runs Yarn. It
validates each tarball (single `package/` directory, exactly one
manifest, name in the preview scope, preview version, restricted
`publishConfig`) and publishes it with `npm publish --ignore-scripts`.

`prepare-preview.yml` gains a `pack` input, off by default, so the
token-based `publish-preview.yml` workflow keeps working as before.
The tarball validation compared `publishConfig.registry` against
`https://registry.npmjs.org/` exactly, so a manifest using
`https://registry.npmjs.org` failed the job even though both point to
the same registry. Accept both forms and nothing else, so lookalike
hosts are still rejected.
run: echo "Dry run — skipping publish"

- name: Generate preview build message
- name: Generate preview build message (monorepo)

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.

Split this into a separate step for monorepos and polyrepos, so it's a bit more readable.

if: ${{ inputs.pull-request }}
run: gh pr comment "${PR_NUMBER}" --body-file preview-build-message.txt
env:
GH_REPO: ${{ github.repository }}

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.

Without a checkout, the gh CLI needs this specified explicitly.

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.

Recommended to review this without whitespace.


for location in "${locations[@]}"; do
manifest="$location/package.json"
jq 'if .scripts then .scripts |= with_entries(select(.key | test("^(pre|post)?(pack|publish|prepare)$") | not)) else . end' "$manifest" > temp.json

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 previously did this in the publish workflow, but since we're now packing here, we need to do this here.

@Mrtenz
Mrtenz marked this pull request as ready for review November 23, 2026 09:43
environment: ${{ inputs.environment }}
runs-on: ubuntu-latest
steps:
- name: Checkout and setup environment

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.

AI pointed this:

This job doesn't set up Node any more, so npm publish uses the runner's npm. OIDC publishing needs npm 11.5.1 or newer.

With an older npm, the publish fails at the token exchange with an auth error. Can we add actions/setup-node with node-version: 24 before the publish steps? so we don't rely on the runner's node version

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 initially added actions/setup-node here for that reason, but removed it later because I noticed GitHub includes NPM 11.19.1 by default in the latest image.

If we add something like node-version: '24', it's another place where we need to maintain a Node.js version. We already have some actions in this repository still using Node.js 18 etc. 😅 And we can't reference an .nvmrc without doing a checkout, which I tried to avoid.

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.

I guess we can rely on github keeping everything in sync then 👍

Comment thread .github/workflows/prepare-preview.yml Resolved
The steps that select and pack packages filled arrays with `mapfile`
from a process substitution. GitHub runs steps with `bash -e` but
without `pipefail`, so a failing `yarn workspaces list` or `jq` left the
array empty and the step passed. Capture the output in a variable first,
so a failure stops the step. Call `mapfile` only when there is output,
because it turns empty input into an array with one empty element.
@Mrtenz
Mrtenz requested a review from GuillaumeRx November 23, 2026 11:19
@Mrtenz
Mrtenz merged commit 29dc21a into main Nov 23, 2026
12 checks passed
@Mrtenz
Mrtenz deleted the mrtenz/preview-publish-tarballs branch November 23, 2026 11:22
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.

2 participants