-
Notifications
You must be signed in to change notification settings - Fork 0
ci: migrate to OIDC trusted publishing #10
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
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,64 +1,41 @@ | ||
| name: ci | ||
| on: [push, pull_request] | ||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| permissions: | ||
| contents: read | ||
| concurrency: ci-${{ github.ref }} | ||
|
|
||
| jobs: | ||
| typecheck: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| node: [20.x, 22.x] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: pnpm/action-setup@v4 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: ${{ matrix.node }} | ||
| cache: pnpm | ||
| - run: pnpm install | ||
| - run: pnpm -s typecheck | ||
|
|
||
| format: | ||
| ci: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: pnpm/action-setup@v4 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| cache: pnpm | ||
| - run: pnpm install | ||
| - run: pnpm run format | ||
| cache: 'pnpm' | ||
|
|
||
| test-build: | ||
| runs-on: ubuntu-latest | ||
| needs: [typecheck, format] | ||
| strategy: | ||
| matrix: | ||
| node: [20.x, 22.x] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: pnpm/action-setup@v4 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: ${{ matrix.node }} | ||
| cache: pnpm | ||
| - run: pnpm install | ||
| - run: pnpm test | ||
| - run: pnpm build | ||
| - name: Verify packed artifacts | ||
| - name: Validate PR title (Conventional Commits) | ||
| if: github.event_name == 'pull_request' | ||
| env: | ||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
| run: | | ||
| set -euo pipefail | ||
| PACK_OUTPUT=$(npm pack --silent) | ||
| echo "$PACK_OUTPUT" | ||
| TARBALL=$(printf '%s\n' "$PACK_OUTPUT" | tail -n 1 | tr -d '[:space:]') | ||
| echo "Packed tarball: $TARBALL" | ||
| LISTING=$(tar -tf "$TARBALL") | ||
| echo "Listing contents:" | ||
| printf '%s\n' "$LISTING" | sed -n '1,200p' | ||
| printf '%s\n' "$LISTING" | grep -q '^package/dist/index.mjs$' | ||
| printf '%s\n' "$LISTING" | grep -q '^package/dist/index.cjs$' | ||
| printf '%s\n' "$LISTING" | grep -q '^package/dist/index.d.ts$' | ||
| rm -f "$TARBALL" | ||
| node - <<'NODE' | ||
| const title = process.env.PR_TITLE || ""; | ||
| const ok = | ||
| /^(feat|fix|chore|docs|test|refactor|ci|build|perf|style|revert)(\(.+\))?(!)?: .+/.test( | ||
| title, | ||
| ); | ||
| if (!ok) { | ||
| console.error(`Invalid PR title (Conventional Commits required): ${title}`); | ||
| process.exit(1); | ||
| } | ||
| NODE | ||
|
|
||
| - run: pnpm install | ||
| - run: pnpm -s test | ||
| - run: pnpm -s typecheck | ||
| - run: pnpm -s build | ||
| - run: pnpm -s format |
This file was deleted.
Oops, something went wrong.
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,52 +1,51 @@ | ||
| name: publish | ||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| tags: | ||
| - 'v*' | ||
| permissions: | ||
| contents: write | ||
| id-token: write | ||
| packages: write | ||
| contents: write | ||
| jobs: | ||
| publish: | ||
| if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' | ||
| runs-on: ubuntu-latest | ||
| environment: release | ||
| concurrency: publish-${{ github.ref }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| registry-url: 'https://registry.npmjs.org' | ||
| - uses: pnpm/action-setup@v4 | ||
| - run: pnpm install | ||
| - run: pnpm test | ||
| - run: pnpm typecheck | ||
| - run: pnpm build | ||
| - name: npm publish with provenance | ||
| run: npm publish --access public --provenance | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| - name: Read version from package.json | ||
| id: ver | ||
| - name: Ensure npm CLI supports trusted publishing | ||
| run: | | ||
| npm i -g npm@11.5.1 | ||
| npm --version | ||
|
|
||
| - name: Detect already-published version | ||
| id: npmcheck | ||
| run: | | ||
| set -euo pipefail | ||
| NAME=$(node -p "require('./package.json').name") | ||
| VERSION=$(node -p "require('./package.json').version") | ||
| echo "name=$NAME" >> "$GITHUB_OUTPUT" | ||
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | ||
| - name: Create vX.Y.Z tag if missing | ||
| run: | | ||
| TAG="v${{ steps.ver.outputs.version }}" | ||
| if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then | ||
| echo "Tag $TAG already exists. Skipping." | ||
| exit 0 | ||
| if npm view "$NAME@$VERSION" version >/dev/null 2>&1; then | ||
| echo "published=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "published=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| git tag -a "$TAG" -m "$TAG" | ||
| git push origin "$TAG" | ||
|
|
||
| - name: npm publish (OIDC trusted publishing) | ||
| if: steps.npmcheck.outputs.published != 'true' | ||
| run: npm publish --access public | ||
|
|
||
| - name: Sync GitHub Release notes via changelogen | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: pnpm dlx changelogen gh release v${{ steps.ver.outputs.version }} --token "${GITHUB_TOKEN}" | ||
| run: pnpm exec changelogen gh release ${{ github.ref_name }} --token "${GITHUB_TOKEN}" | ||
This file was deleted.
Oops, something went wrong.
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
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.
The new publish workflow removes
NODE_AUTH_TOKENbut the publish step now callsnpm publish --access publicwithout enabling provenance (--provenance/NPM_CONFIG_PROVENANCE) or any other authentication. npm only uses GitHub’s OIDC flow when provenance is requested; otherwise it expects an auth token and exits withEAUTH/ENEEDAUTH. On any tag push this step will fail before releasing the package, blocking trusted publishing entirely.Useful? React with 👍 / 👎.