Repository navigation
ci: publish to npm via Trusted Publishing (OIDC) #11
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 |
|---|---|---|
|
|
@@ -22,16 +22,16 @@ jobs: | |
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: "18.15" | ||
| cache: "yarn" | ||
| cache: "npm" | ||
|
|
||
| - name: Install | ||
| run: yarn install --frozen-lockfile --non-interactive | ||
| run: npm ci | ||
|
|
||
| - name: Build | ||
| run: yarn build | ||
| run: npm run build | ||
|
|
||
| - name: Lint | ||
| run: yarn lint | ||
| run: npm run lint | ||
|
|
||
| deploy-github-pages: | ||
| runs-on: ubuntu-latest | ||
|
|
@@ -46,22 +46,22 @@ jobs: | |
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: "18.15" | ||
| cache: "yarn" | ||
| cache: "npm" | ||
|
|
||
| # Build base package, so links work | ||
| - name: Install | ||
| run: yarn install --frozen-lockfile --non-interactive | ||
| run: npm ci | ||
|
|
||
| - name: Build | ||
| run: yarn build | ||
| run: npm run build | ||
|
|
||
| # For the mobx example | ||
| - name: Install | ||
| run: yarn install --frozen-lockfile --non-interactive | ||
| run: npm ci | ||
| working-directory: ./docs/todo-mobx-example | ||
|
|
||
| - name: Build | ||
| run: yarn build | ||
| run: npm run build | ||
| working-directory: ./docs/todo-mobx-example | ||
|
|
||
| - name: Copy output | ||
|
|
@@ -78,6 +78,13 @@ jobs: | |
| if: github.event.pull_request.merged == true && (contains(github.event.pull_request.labels.*.name, 'release-major') || contains(github.event.pull_request.labels.*.name, 'release-minor') || contains(github.event.pull_request.labels.*.name, 'release-patch')) | ||
| needs: build-and-lint | ||
| runs-on: ubuntu-latest | ||
| # `id-token: write` lets GitHub mint the OIDC token that npm exchanges | ||
| # for a short-lived publish credential (npm Trusted Publishing) — no | ||
| # long-lived NPM_TOKEN secret required. `contents: write` is still | ||
| # needed for the GitHub Release created via GITHUB_TOKEN below. | ||
| permissions: | ||
| id-token: write | ||
| contents: write | ||
| steps: | ||
| - name: Determine version type from label | ||
| id: version-type | ||
|
|
@@ -116,28 +123,34 @@ jobs: | |
| git config user.email [email protected] | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@v3 | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "18.15" | ||
| cache: "yarn" | ||
| node-version: "24" | ||
| cache: "npm" | ||
| registry-url: "https://registry.npmjs.org" | ||
|
|
||
| # npm Trusted Publishing (OIDC) requires npm >= 11.5.1, which is newer | ||
| # than the npm bundled with Node 24. Upgrade explicitly so `npm publish` | ||
| # can mint provenance and exchange the OIDC token for a publish credential. | ||
| - name: Ensure npm supports Trusted Publishing | ||
| run: npm install -g npm@latest | ||
|
|
||
| - name: Install dependencies | ||
| run: yarn install --frozen-lockfile --non-interactive | ||
| run: npm ci | ||
|
|
||
| - name: Build | ||
| run: yarn build | ||
| run: npm run build | ||
|
|
||
| - name: Tag release | ||
| id: bump-version | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| VERSION_TYPE="${{ steps.version-type.outputs.type }}" | ||
| yarn version --"$VERSION_TYPE" --no-git-tag-version | ||
| npm version "$VERSION_TYPE" --no-git-tag-version | ||
| NEW_VERSION=$(node -p "require('./package.json').version") | ||
| echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | ||
| git add package.json | ||
| git add package.json package-lock.json | ||
| git commit -m "release: bump version to $NEW_VERSION" | ||
| git tag v$NEW_VERSION | ||
| git push --tags origin main | ||
|
|
@@ -152,7 +165,10 @@ jobs: | |
| draft: false | ||
| prerelease: false | ||
|
|
||
| # Publish via npm Trusted Publishing (OIDC). No NPM_TOKEN secret needed — | ||
| # the `id-token: write` permission on this job lets npm exchange a | ||
| # short-lived GitHub OIDC token for a publish credential, and provenance | ||
| # is attached automatically. Must use the npm CLI here: Yarn Classic's | ||
| # `yarn publish` does not support OIDC. | ||
| - name: Publish to NPM | ||
| run: yarn publish | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| run: npm 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
Oops, something went wrong.
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.
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.
welcomed change.