Skip to content

ci: publish to npm via OIDC trusted publishing - #161

Merged
ThallesP merged 2 commits into
masterfrom
ci/npm-oidc-trusted-publishing
Jul 4, 2026
Merged

ci: publish to npm via OIDC trusted publishing#161
ThallesP merged 2 commits into
masterfrom
ci/npm-oidc-trusted-publishing

Conversation

@ThallesP

@ThallesP ThallesP commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Migrates the release workflow from an NPM_TOKEN secret to npm trusted publishing (OIDC).

Why the previous attempts failed

The git history from January (02787dc3c22150) hit three known traps, each of which independently breaks OIDC publishing:

  1. bun publish doesn't support trusted publishing — the OIDC token exchange is implemented in the npm CLI only (oven-sh/bun#22423, #24855). Bun still handles install/build/lint/test; only the publish step uses npm.
  2. setup-node with registry-url breaks OIDC — it writes an .npmrc with _authToken=${NODE_AUTH_TOKEN}, and the mere presence of that auth config makes npm skip OIDC and fail with a misleading ENEEDAUTH/E404 (npm/cli#9088). That explains the whole NODE_AUTH_TOKEN unset/empty-string dance in the old commits — the fix is to not set registry-url at all and have no token env var anywhere.
  3. repository.url case mismatch — the old attempt used github.com/thallesp/… but the OIDC token's repository claim is ThallesP/nestjs-better-auth, and provenance validation compares them case-sensitively. This PR adds the repository field with the exact casing (it was removed entirely in the revert).

Also required: npm ≥ 11.5.1, so the workflow updates npm rather than trusting the runner's bundled version, and id-token: write permission.

⚠️ Manual setup required before merging

On npmjs.com → package @thallesp/nestjs-better-auth → Settings → Trusted Publisher, add a GitHub Actions publisher with these exact, case-sensitive values:

Field Value
Organization or user ThallesP
Repository nestjs-better-auth
Workflow filename release.yaml (with the .yaml extension, not .yml)
Environment (leave empty — the workflow doesn't use one)

After the first successful OIDC publish, the NPM_TOKEN repo secret can be deleted, and optionally set the package to "Require two-factor authentication or automation" → disallow tokens.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Enabled trusted publishing for the package, improving the security of release publishing via OIDC.
  • Chores
    • Updated the release workflow to publish with npm publish using provenance and public access (replacing the previous Bun-based publish approach).
    • Set up a newer Node.js/npm toolchain for publishing reliability.
    • Added repository metadata to the package configuration.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The release workflow now uses npm trusted publishing with OIDC, including Node 24 and npm upgrade steps, and package.json adds repository metadata.

Changes

Release Workflow and Package Metadata

Layer / File(s) Summary
Workflow trigger and permissions setup
.github/workflows/release.yaml
Workflow permissions add id-token: write while keeping contents: read for OIDC publishing.
Node/npm toolchain setup
.github/workflows/release.yaml
Workflow installs Node 24 and upgrades npm to the latest version before publishing.
Publish step replacement
.github/workflows/release.yaml
Workflow replaces bun publish and token-based auth with npm publish using --provenance and public access.
Package repository metadata
package.json
package.json adds a repository field with git type and the project GitHub URL.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
    participant GitHub Actions
    participant Node Setup
    participant npm Registry
    GitHub Actions->>Node Setup: actions/setup-node@v5 (Node 24)
    Node Setup->>GitHub Actions: npm install -g npm@latest
    GitHub Actions->>npm Registry: npm publish --provenance --access public
    npm Registry-->>GitHub Actions: publish result
Loading

Poem

A rabbit hops through YAML fields so neat,
Trading bun for npm, oh what a feat!
OIDC shines with a provenance glow,
And repository roots help the burrow grow. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: switching release publishing to npm OIDC trusted publishing.
Description check ✅ Passed The description explains what changed, why, and the manual npm setup, but it does not follow the exact template headings or include a checklist.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci/npm-oidc-trusted-publishing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/ThallesP/nestjs-better-auth/@thallesp/nestjs-better-auth@161

commit: 6972b81

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
.github/workflows/release.yaml (1)

35-36: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Pin npm to a tested npm release

npm install -g npm@latest makes the release toolchain non-reproducible. Pin a known-good version instead (for example npm@11.5.1 or newer) so trusted publishing keeps behaving consistently.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/release.yaml around lines 35 - 36, The release workflow
currently installs npm using a floating latest tag, which makes the toolchain
non-reproducible. Update the “Update npm” step in the release workflow to pin
npm to a known-good tested version instead of npm@latest, keeping the existing
npm --version check so the workflow still verifies the installed release.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/release.yaml:
- Around line 60-62: The Release to NPM step in the release workflow will
publish on manual dispatch whenever dry_run is false, which can push a real
package version unexpectedly. Tighten the guard on the workflow job/step that
runs npm publish in the release.yaml workflow (the Release to NPM block), or add
explicit documentation and checks that the package.json version already exists
on npm before allowing workflow_dispatch to publish. Ensure the condition
clearly distinguishes OIDC-only runs from real release publishes.

---

Nitpick comments:
In @.github/workflows/release.yaml:
- Around line 35-36: The release workflow currently installs npm using a
floating latest tag, which makes the toolchain non-reproducible. Update the
“Update npm” step in the release workflow to pin npm to a known-good tested
version instead of npm@latest, keeping the existing npm --version check so the
workflow still verifies the installed release.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c79d2c8a-4a7e-40fc-ba2a-f147d39706cc

📥 Commits

Reviewing files that changed from the base of the PR and between 0cdedcf and 6c2b30b.

📒 Files selected for processing (2)
  • .github/workflows/release.yaml
  • package.json

Comment on lines 60 to +62
- name: Release to NPM
run: bun publish --access public
env:
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && !inputs.dry_run)
run: npm publish --provenance --access public

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

sed -n '1,180p' .github/workflows/release.yaml

Repository: ThallesP/nestjs-better-auth

Length of output: 2032


🏁 Script executed:

cat -n package.json | sed -n '1,80p'

Repository: ThallesP/nestjs-better-auth

Length of output: 2920


🏁 Script executed:

rg -n "OIDC|dry_run|dry run|trusted publishing|publish --dry-run|without releasing|without releasing a new version" .

Repository: ThallesP/nestjs-better-auth

Length of output: 165


Manual dispatch with dry_run: false still publishes to npm

If this path is only meant to exercise OIDC, gate it more tightly or document that package.json’s version must already exist on npm; otherwise a non-dry-run dispatch will publish that version for real.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/release.yaml around lines 60 - 62, The Release to NPM step
in the release workflow will publish on manual dispatch whenever dry_run is
false, which can push a real package version unexpectedly. Tighten the guard on
the workflow job/step that runs npm publish in the release.yaml workflow (the
Release to NPM block), or add explicit documentation and checks that the
package.json version already exists on npm before allowing workflow_dispatch to
publish. Ensure the condition clearly distinguishes OIDC-only runs from real
release publishes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ThallesP
ThallesP merged commit ae3a83d into master Jul 4, 2026
7 checks passed
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.

1 participant