Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/prerelease-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
"release-type": "node",
"include-component-in-tag": false,
"versioning": "prerelease",
"prerelease": true,
"prerelease-type": "rc",
"packages": {
".": {}
}
}
3 changes: 3 additions & 0 deletions .github/prerelease-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "6.2.2"
}
18 changes: 18 additions & 0 deletions .github/release-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
"release-type": "node",
"include-component-in-tag": false,
"versioning": "default",
"prerelease": false,
"packages": {
".": {
"extra-files": [
{
"type": "json",
"path": ".github/prerelease-manifest.json",
"jsonpath": "$[\".\"]"
}
]
}
}
}
3 changes: 3 additions & 0 deletions .github/release-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "6.2.2"
}
87 changes: 87 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: npm-publish

on:
workflow_dispatch:
inputs:
tag:
description: >-
Release tag to publish, for example v6.2.2. Leave empty to run
validation only (dry run).
type: string

permissions:
contents: read

concurrency:
# tag grouping - queues repeat publishes of the same release
# run_id - fallback for validation-only runs, which have no tag
group: npm-publish-${{ inputs.tag || github.run_id }}
cancel-in-progress: false

jobs:
validate:
name: Validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
ref: ${{ inputs.tag || github.ref }}
persist-credentials: false

- uses: actions/setup-node@v6
with:
node-version: 22.x

- name: verify release version
if: inputs.tag != ''
run: |
pkg_name=$(jq -r .name package.json)
pkg_version=$(jq -r .version package.json)
tag_version="${RELEASE_TAG#v}"
if [ "$pkg_version" != "$tag_version" ]; then
echo "package.json version ($pkg_version) does not match release tag ($tag_version)"
exit 1
fi
if npm view "${pkg_name}@${pkg_version}" version >/dev/null 2>&1; then
echo "${pkg_name}@${pkg_version} is already published"
exit 1
fi
env:
RELEASE_TAG: ${{ inputs.tag }}

- name: validate publish package contents
run: |
npm pack --dry-run 2>&1 | tee pack.log
grep -q 'lib/index.js' pack.log
! grep -qE '[[:space:]]test/' pack.log
! grep -qE '[[:space:]]tools/' pack.log

publish:
name: publish
needs: validate
if: inputs.tag != ''
runs-on: ubuntu-latest
environment: Publish
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v7
with:
ref: ${{ inputs.tag }}
persist-credentials: false

- uses: actions/setup-node@v6
with:
node-version: 26.x
registry-url: https://registry.npmjs.org

- name: npm stage publish
env:
RELEASE_TAG: ${{ inputs.tag }}
run: |
if [[ "$RELEASE_TAG" == *-rc* ]]; then
npm stage publish --provenance --tag rc
else
npm stage publish --provenance
fi
53 changes: 53 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
on:
push:
branches:
- main
permissions:
contents: write
issues: write
pull-requests: write
# Releases created with GITHUB_TOKEN cannot trigger other workflows, so
# npm-publish is dispatched explicitly below. workflow_dispatch is one of the
# few events that always creates a run, even from GITHUB_TOKEN.
actions: write

concurrency:
group: release-please-${{ github.ref_name }}
cancel-in-progress: false

name: release-please
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: googleapis/release-please-action@v5
id: prerelease
with:
token: ${{ secrets.GITHUB_TOKEN }}
config-file: .github/prerelease-config.json
manifest-file: .github/prerelease-manifest.json
target-branch: ${{ github.ref_name }}

# Once an RC PR is merged and tagged, replace it with the stable Release
# PR. The stable config also synchronizes the prerelease manifest when
# that stable PR is eventually merged.
- name: create stable Release PR
if: >-
steps.prerelease.outputs.releases_created == 'true' &&
contains(steps.prerelease.outputs.tag_name, '-rc')
uses: googleapis/release-please-action@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
config-file: .github/release-config.json
manifest-file: .github/release-manifest.json
target-branch: ${{ github.ref_name }}

# The prerelease action recognizes merges of both RC and stable Release
# PRs. It creates the corresponding tag and GitHub Release in either case.
- name: trigger npm-publish
if: steps.prerelease.outputs.releases_created == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
TAG: ${{ steps.prerelease.outputs.tag_name }}
run: gh workflow run npm-publish.yml --ref "$GITHUB_REF_NAME" -f tag="$TAG"
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package-lock=false
package-lock=false
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,26 @@ enroute.validate({
}
});
```

## Cutting a release

Releases are automated with [release-please](https://github.com/googleapis/release-please) and published to npm via GitHub Actions. We use [Conventional Commits](http://conventionalcommits.org/) to simplify the process of managing semver on this project — release-please parses commit types (`fix`, `feat`, etc.) to determine the version bump.

### Release flow

1. Merge pull requests to `main` using [Conventional Commits](http://conventionalcommits.org/).
2. `release-please` opens or updates a **Release PR** with the version bump and changelog.
3. Review and merge the Release PR when ready to ship.
4. `release-please` creates a GitHub Release and version tag (for example `v6.3.0`).
5. The same `release-please` run then dispatches `npm-publish` with that tag. It re-runs tests, validates the package contents (`npm pack --dry-run`), then pauses at the `Publish` environment for reviewer approval.
6. After approval, the package is published to npm via [Trusted Publishing](https://docs.npmjs.com/trusted-publishers) (OIDC).

Release candidates follow the same path: merging an RC PR tags an `-rc` version, `npm-publish` publishes it with `--tag rc`, and `release-please` then opens a stable Release PR.

### Dry run

To validate the publish workflow without publishing, run **Actions → npm-publish → Run workflow** and leave `tag` empty. This runs tests and `npm pack --dry-run`, and skips the publish job.

### Retrying a failed run

If `npm-publish` fails, use **Re-run jobs** on the failed run itself (Actions tab) — it replays the same tag, so there's no need to cut a new one. You can also re-run **Actions → npm-publish → Run workflow** with the same `tag`. Either is safe even if `publish` partially ran, since `validate` checks whether the version is already on npm before continuing.
Loading