Repository navigation
ci: publish releases from CI with npm trusted publishing #57
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
3 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 |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| name: Release | ||
|
|
||
| # Publishing is driven by a version tag, not by a commit pushed from CI. The | ||
| # version bump and the CHANGELOG.md section land through a normal pull request, | ||
| # and pushing the matching tag afterwards triggers the publish. See RELEASING.md. | ||
| on: | ||
| push: | ||
| tags: | ||
| - 'v[0-9]+.[0-9]+.[0-9]+' | ||
| - 'v[0-9]+.[0-9]+.[0-9]+-*' | ||
| # Rehearsal against the current branch. Always a dry run: it validates the | ||
| # version and the full gate without tagging or publishing anything. | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: release-${{ github.ref }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| # Every CI job, including the iOS and Android builds and native unit tests, | ||
| # must pass on the tagged commit before anything is published. | ||
| ci: | ||
| permissions: | ||
| contents: read | ||
| uses: ./.github/workflows/ci.yml | ||
|
|
||
| release: | ||
| needs: [ci] | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| # Create the GitHub Release for the pushed tag. | ||
| contents: write | ||
| # Mint the OIDC token npm exchanges for a short-lived publish token, and | ||
| # sign the provenance attestation. | ||
| id-token: write | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
|
|
||
| - name: Setup Bun | ||
| uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 | ||
| with: | ||
| bun-version: 1.3.14 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 | ||
| with: | ||
| # Node 24 ships npm >= 11.5.1, required for npm trusted publishing. | ||
| # `registry-url` is deliberately omitted: it writes an `_authToken` | ||
| # entry into .npmrc, which makes npm assume classic token auth and skip | ||
| # the OIDC flow. The registry is already pinned by publishConfig. | ||
| node-version: 24 | ||
|
|
||
| - name: Verify npm supports trusted publishing | ||
| run: | | ||
| npm_version="$(npm --version)" | ||
| required=11.5.1 | ||
| echo "npm $npm_version (need >= $required)" | ||
| if [ "$(printf '%s\n%s\n' "$required" "$npm_version" | sort -V | head -n1)" != "$required" ]; then | ||
| echo "::error::npm $npm_version is too old for trusted publishing (need >= $required)." | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Install dependencies | ||
| run: bun install --frozen-lockfile | ||
|
|
||
| - name: Resolve version | ||
| id: version | ||
| run: | | ||
| version="$(node -p "require('./package/package.json').version")" | ||
| echo "package.json version: $version" | ||
| echo "version=$version" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Verify tag matches package.json | ||
| if: github.event_name == 'push' | ||
| env: | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| TAG: ${{ github.ref_name }} | ||
| run: | | ||
| if [ "$TAG" != "v$VERSION" ]; then | ||
| echo "::error::Tag $TAG does not match package.json version $VERSION. Bump the version on main first." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # A tag trigger matches the tag's name, whatever branch holds its commit. | ||
| # Publish only commits that reached main through the release pull request. | ||
| # The full-history checkout above fetched origin/main. | ||
| - name: Verify the tagged commit is on main | ||
| if: github.event_name == 'push' | ||
| env: | ||
| TAG: ${{ github.ref_name }} | ||
| run: | | ||
| if ! git merge-base --is-ancestor HEAD origin/main; then | ||
| echo "::error::Tag $TAG points at $(git rev-parse HEAD), which is not on main. Merge the release pull request, then tag main." | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Verify version is not already published | ||
| env: | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| run: | | ||
| if npm view "@gmisoftware/react-native-pay@$VERSION" version >/dev/null 2>&1; then | ||
| echo "::error::@gmisoftware/react-native-pay@$VERSION is already on npm." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # The section becomes the GitHub Release body. Checking it here stops a | ||
| # release whose pull request forgot the changelog before npm has it, and | ||
| # prints the body, which release-it skips in a rehearsal. | ||
| - name: Verify CHANGELOG.md has a section for the version | ||
| working-directory: package | ||
| env: | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| run: node scripts/changelog-section.js "$VERSION" | ||
|
|
||
| - name: Copy README into the package | ||
| # npm reads the README shown on the registry page from the package | ||
| # directory while it builds the manifest, before any pack script runs. | ||
| # The `prepack` copy therefore never reaches the registry; the file must | ||
| # exist here first. | ||
| run: cp README.md package/README.md | ||
|
|
||
| - name: Publish | ||
| working-directory: package | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| # --no-increment: the version already lives in package.json, reviewed | ||
| # and merged through a pull request. | ||
| # --no-git: the tag is pushed by the maintainer; CI never writes to git. | ||
| args=(--ci --no-increment --no-git) | ||
| if [ "${{ github.event_name }}" != 'push' ]; then | ||
| args+=(--dry-run) | ||
| echo 'Rehearsal run — nothing will be tagged or published.' | ||
| fi | ||
| bunx release-it "${args[@]}" | ||
|
|
||
| - name: Summary | ||
| if: always() | ||
| env: | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| run: | | ||
| { | ||
| echo "### Release v$VERSION" | ||
| echo | ||
| if [ "${{ github.event_name }}" != 'push' ]; then | ||
| echo "Rehearsal only — nothing was published." | ||
| else | ||
| echo "- [npm](https://www.npmjs.com/package/@gmisoftware/react-native-pay/v/$VERSION)" | ||
| echo "- [GitHub Release](${{ github.server_url }}/${{ github.repository }}/releases/tag/v$VERSION)" | ||
| fi | ||
| } >> "$GITHUB_STEP_SUMMARY" | ||
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,123 @@ | ||
| # Releasing | ||
|
|
||
| Releases are published to npm from CI with | ||
| [provenance](https://docs.npmjs.com/generating-provenance-statements) by the | ||
| [Release workflow](.github/workflows/release.yml). Nothing is published from a | ||
| developer machine, and no long-lived npm token exists anywhere. | ||
|
|
||
| Publishing is triggered by pushing a version tag. CI never writes to git: the | ||
| version bump and the changelog go through a normal pull request instead. | ||
|
|
||
| ## Cutting a release | ||
|
|
||
| **1. Open a release pull request.** Bump the version: | ||
|
|
||
| ```bash | ||
| cd package | ||
| npm version 0.1.0 --no-git-tag-version --no-workspaces-update | ||
| ``` | ||
|
|
||
| `--no-workspaces-update` stops npm from reifying the workspace, which this | ||
| Bun-managed repository does not support. `bun install` does not rewrite | ||
| `bun.lock` for a version-only change, so also set the `version` of the | ||
| `package` workspace near the top of `bun.lock`, then check that | ||
| `bun install --frozen-lockfile` still passes. | ||
|
|
||
| In [CHANGELOG.md](CHANGELOG.md), rename `## Unreleased` to the version and the | ||
| date, for example `## 0.1.0 — 2026-10-27`. That section becomes the GitHub | ||
| Release body, and the workflow refuses to publish a version without one. | ||
|
|
||
| Open a pull request titled `chore(release): prepare 0.1.0` with these changes, | ||
| then review and merge it as usual. | ||
|
|
||
| **2. Rehearse (optional).** Run the **Release** workflow manually from the | ||
| Actions tab. A manual run is always a dry run: it runs the full gate, prints the | ||
| release notes in the changelog step, and runs `npm publish --dry-run`. | ||
|
|
||
| **3. Push the tag.** | ||
|
|
||
| ```bash | ||
| git checkout main && git pull | ||
| git tag -a v0.1.0 -m 'v0.1.0' | ||
| git push origin v0.1.0 | ||
| ``` | ||
|
|
||
| The workflow then runs every [CI](.github/workflows/ci.yml) job on the tagged | ||
| commit (lint, typecheck, tests, the Nitro codegen check, the package contents | ||
| check, and the iOS and Android builds with their unit tests); verifies the tag | ||
| matches `package/package.json` and points at a commit on `main`, that the | ||
| version is not already on npm and that `CHANGELOG.md` has a section for it; | ||
| publishes to npm with provenance; and | ||
| creates the GitHub Release with that section as its body. | ||
|
|
||
| The iOS podspec reads its version from `package.json`, so there is no second | ||
| version to keep in sync. | ||
|
|
||
| ## Versioning | ||
|
|
||
| The package is below 1.0.0, so a caret range such as `^0.1.0` accepts patch | ||
| releases only. Bump the minor version (`0.1.0` → `0.2.0`) for a release that | ||
| breaks the public API or changes runtime behavior apps rely on, and the patch | ||
| version for anything else. List breaking changes under **Changed** or | ||
| **Removed** in the changelog with what apps need to do. | ||
|
|
||
| Tags are `v`-prefixed from `v0.1.0`. Versions up to 0.0.17 were published by | ||
| hand from `package/`, carry no provenance, and are tagged without the prefix. | ||
|
|
||
| ## Pre-releases | ||
|
|
||
| A version with a pre-release identifier works without extra configuration. | ||
| Tagging `v0.2.0-rc.1` publishes under the `rc` dist-tag rather than `latest`, so | ||
| `npm install @gmisoftware/react-native-pay` is unaffected, and the GitHub | ||
| Release is marked as a pre-release. release-it derives both from the version | ||
| itself. The changelog section is `## 0.2.0-rc.1 — <date>`. | ||
|
|
||
| Consumers opt in explicitly: | ||
|
|
||
| ```bash | ||
| npm install @gmisoftware/react-native-pay@rc | ||
| ``` | ||
|
|
||
| ## One-time setup: npm trusted publishing | ||
|
|
||
| Publishing uses OIDC, so it only works once npm knows which workflow may publish | ||
| this package. On npmjs.com, open the `@gmisoftware/react-native-pay` package | ||
| settings → **Trusted publishing** and add a **GitHub Actions** trusted publisher | ||
| pointing at: | ||
|
|
||
| - repository: `gmi-software/react-native-pay` | ||
| - workflow: `release.yml` | ||
|
|
||
| A new trusted publisher configuration expires unless a real (not dry-run) | ||
| publish uses it within 2 days, so add it when the next release is about to be | ||
| tagged, not earlier. Until it is configured the publish step fails with an | ||
| authentication error. | ||
|
|
||
| Provenance also requires the repository to be public. | ||
|
|
||
| ## Notes on the configuration | ||
|
|
||
| A few settings exist for non-obvious reasons: | ||
|
|
||
| - `npm.skipChecks: true` in `package/.release-it.json`: release-it otherwise | ||
| runs `npm whoami` at startup, which fails under trusted publishing because the | ||
| token is only minted at publish time. | ||
| - The workflow does **not** set `registry-url` on `actions/setup-node`: doing so | ||
| writes an `_authToken` entry into `.npmrc`, which makes npm assume classic | ||
| token auth and skip the OIDC flow. The registry is pinned by `publishConfig`. | ||
| - `release-it` runs with `--no-increment --no-git`: the version is already | ||
| committed and the tag already pushed, so CI only publishes and creates the | ||
| release. | ||
| - The workflow copies `README.md` into `package/` before publishing. npm reads | ||
| the README shown on the registry page before any pack script runs, so the | ||
| `prepack` copy alone never reaches npmjs.com. | ||
|
|
||
| ## Inspecting a release locally | ||
|
|
||
| A local publish would produce a package without provenance, so it is not | ||
| supported. To see what a release would do: | ||
|
|
||
| ```bash | ||
| cd package | ||
| GITHUB_TOKEN="$(gh auth token)" bunx release-it --no-increment --no-git --dry-run | ||
| ``` |
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.
Uh oh!
There was an error while loading. Please reload this page.