@circleci/trusted-publishing-example
v1.0.193
Published
Just a hello world package to publish with trusted publishing via cci
Keywords
Readme
@circleci/trusted-publishing-example
A minimal example package showing how to publish to npm from CircleCI using trusted publishing, with no long-lived NPM_TOKEN.
For the full walkthrough, see Publish to npm.
Project Structure
build.sh- Sets a dynamic version (MAJOR.MINOR.<CIRCLE_BUILD_NUM>) onpackage.jsonindex.js- The package's one function:helloWorldindex.test.js- Tests, runnable withnpm test../.circleci/npm-publish.yml- CircleCI pipeline
How It Works
- CircleCI runs the publish job on push to
main. - The job mints an OIDC token (
circleci run oidc get --claims '{"aud": "npm:registry.npmjs.org"}') and exports it asNPM_ID_TOKEN. npm publishdetectsNPM_ID_TOKENand exchanges it for a short-lived publish token.
The trusted publisher is configured on npmjs.com under the package's Settings → Trusted Publishing tab and is bound to the trusted-publishing-guard CircleCI context, which has an expression restriction limiting it to main. A staging workflow on non-main branches is included to demonstrate that the lockdown rejects publishes from other branches.
