-
Notifications
You must be signed in to change notification settings - Fork 35
release: adopt npm trusted publishing #270
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,100 @@ | ||
| # Automated release via Changesets. | ||
| # | ||
| # On push to main: | ||
| # - If there are unreleased changesets, opens/updates a "Version Packages" | ||
| # - If there are unreleased changesets, opens/updates a release version | ||
| # PR that bumps versions and updates changelogs. | ||
| # - If that PR is merged (no remaining changesets), builds and publishes | ||
| # to npm. | ||
| # - If there are no unreleased changesets, builds, tests, and publishes | ||
| # to npm from a separate least-privilege job. | ||
| # | ||
| # Requires an NPM_TOKEN secret with publish access to the @tko scope. | ||
| # Requires npm trusted publisher configuration for the @tko packages. | ||
| # Publish auth comes from GitHub Actions OIDC, not a long-lived npm token. | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: ${{ github.workflow }}-${{ github.ref }} | ||
|
|
||
| jobs: | ||
| release: | ||
| prepare-release: | ||
| name: Prepare Release | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| outputs: | ||
| has_changesets: ${{ steps.changesets.outputs.hasChangesets }} | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| # actions/checkout v6.0.2 | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd | ||
|
|
||
| - name: Setup Node.js | ||
| # actions/setup-node v6.3.0 | ||
| uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f | ||
| with: | ||
| # npm trusted publishing requires npm CLI 11.5.1+, which is available | ||
| # on the current Node 24 line. | ||
| node-version: 24.x | ||
| cache: 'npm' | ||
| registry-url: 'https://registry.npmjs.org' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Create or update version PR | ||
| id: changesets | ||
| # changesets/action v1.5.3 | ||
| uses: changesets/action@e0145edc7d9d8679003495b11f87bd8ef63c0cba | ||
| with: | ||
| version: npx changeset version | ||
| title: 'chore: version packages' | ||
| commit: 'chore: version packages' | ||
|
brianmhunt marked this conversation as resolved.
|
||
| # Signed GitHub API commits are preferable to git-cli pushes for the | ||
| # automated version PR branch. | ||
| commitMode: github-api | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| publish: | ||
| name: Publish to npm | ||
| needs: prepare-release | ||
| if: needs.prepare-release.outputs.has_changesets == 'false' | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v6 | ||
| # actions/checkout v6.0.2 | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| # actions/setup-node v6.3.0 | ||
| uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f | ||
| with: | ||
| node-version: 22.x | ||
| # npm trusted publishing requires npm CLI 11.5.1+, which is available | ||
| # on the current Node 24 line. | ||
| node-version: 24.x | ||
| cache: 'npm' | ||
| registry-url: 'https://registry.npmjs.org' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install | ||
| run: npm ci | ||
|
|
||
| - name: Build all packages | ||
| run: make | ||
|
|
||
| - name: Run tests | ||
| run: make test-headless | ||
|
|
||
| - name: Create release PR or publish | ||
| uses: changesets/action@v1 | ||
| with: | ||
| version: npx changeset version | ||
| publish: npx changeset publish --provenance | ||
| title: 'chore: version packages' | ||
| commit: 'chore: version packages' | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| - name: Publish packages | ||
| # npm generates provenance attestations automatically during trusted | ||
| # publishing from GitHub Actions. | ||
| run: npx changeset publish | ||
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
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,75 @@ | ||
| # Plan: Trusted Publishing for npm Releases | ||
|
|
||
| **Goal**: Move TKO npm publishing from long-lived `NPM_TOKEN` authentication to | ||
| npm trusted publishing via GitHub Actions OIDC. | ||
|
|
||
| --- | ||
|
|
||
| ## Current State | ||
|
|
||
| - `.github/workflows/release.yml` already grants `id-token: write` | ||
| - Releases still document and use `NPM_TOKEN` | ||
| - Workflow publishes through `changesets/action` | ||
| - Current workflow uses Node 22, but npm trusted publishing now requires | ||
| npm CLI `11.5.1+` | ||
|
|
||
| ## Desired State | ||
|
|
||
| - Release publishing works from GitHub-hosted runners without a write token | ||
| - The workflow uses a Node/npm combination compatible with npm trusted publishing | ||
| - Release docs no longer tell maintainers to configure `NPM_TOKEN` | ||
| - The migration path notes the remaining manual npm-side setup: | ||
| trusted publisher registration and token revocation after verification | ||
|
|
||
| ## Implementation | ||
|
|
||
| ### 1. Workflow | ||
|
|
||
| - Update the release workflow to use a trusted-publisher-compatible Node version | ||
| - Split version-PR automation from npm publishing so the publish job can run | ||
| with read-only repository permissions plus OIDC | ||
| - Switch CI dependency installation to `npm ci` for lockfile-enforced releases | ||
| - Pin third-party GitHub Actions by commit SHA | ||
| - Remove publish-time `NPM_TOKEN` / `NODE_AUTH_TOKEN` env wiring | ||
| - Keep `id-token: write` | ||
| - Keep Changesets for release PR creation | ||
| - Drop explicit `--provenance` because npm generates provenance automatically | ||
| during trusted publishing | ||
|
|
||
| ### Why split prepare vs publish | ||
|
|
||
| Many Changesets-based repositories keep release-PR creation and npm publishing | ||
| in one job. That is simpler, but it forces the publish path to carry both | ||
| repository write access and package-publish credentials at the same time. | ||
|
|
||
| For TKO, the split is intentional: | ||
|
|
||
| - `prepare-release` needs repository write permissions to open/update the | ||
| version PR branch | ||
| - `publish` only needs `contents: read` plus `id-token: write` for npm OIDC | ||
| - this keeps the npm publish path on least privilege while preserving the | ||
| standard Changesets PR flow on `main` | ||
|
|
||
| This is a better fit for trusted publishing than the default single-job | ||
| Changesets pattern. | ||
|
|
||
| ### 2. Repository docs | ||
|
|
||
| - Update the build/release plan to describe trusted publishing instead of | ||
| token-based publishing | ||
| - Update the README release guidance so maintainers do not follow the old | ||
| `lerna publish` path | ||
|
|
||
| ### 3. Follow-up outside the repo | ||
|
|
||
| - Configure trusted publishers for the public `@tko/*` packages on npm | ||
| - Verify one publish from GitHub Actions | ||
| - After verification, disable token-based publishing for those packages and | ||
| revoke unneeded automation tokens | ||
|
|
||
| ## Verification | ||
|
|
||
| - Review `.github/workflows/release.yml` for OIDC-only publish auth | ||
| - Confirm no remaining repo docs require `NPM_TOKEN` for publishing | ||
| - Confirm the workflow now targets a Node/npm version that meets npm trusted | ||
| publishing requirements |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.