Release-via-PR Pipeline for a Protected Default Branch
If the main branch of your repository has branch protection rules enabled (direct git push is forbidden, and merging requires PR approval and passing status checks), you can combine the following three built-in capabilities of @neosjs/release to set up a complete closed loop:
--pr(Release-via-PR): on your local machine (or triggered manually in CI), cut arelease/v<version>branch, bump the version, updateCHANGELOG.md, and automatically create/update the PR.--no-increment: after the PR is merged back intomain, GitHub Actions tags the new version, pushes the tag, and publishes to npm.--sync-releases: reads theCHANGELOG.mdsection for the version that was reviewed and merged in the PR and automatically creates the GitHub Release.
Step 1: Project Configuration (release.config.ts)
ts
import { type ConfigOptions, defineConfig } from '@neosjs/release'
export default defineConfig({
changelog: {
generate: true,
infile: 'CHANGELOG.md'
},
git: {
commitMessage: 'chore: release v${version}',
tagName: 'v${version}',
requireBranch: 'main',
requireCommits: true,
requireCommitsFail: false
},
pr: {
branch: 'release/v${version}',
base: 'main',
title: 'chore: release v${version}',
forcePush: true
},
npm: {
publish: false
},
github: {
release: true
}
}) satisfies ConfigOptionsStep 2: Open the Release PR
The maintainer runs the following on a clean local main branch that is in sync with upstream:
bash
pnpm release --prThe tool then automatically:
- Recommends and confirms the target version (for example
1.4.0); - Updates
package.jsonandCHANGELOG.md; - Cuts the
release/v1.4.0branch, commits, and pushes it to the remote, then switches back tomain; - Creates the Pull Request from
release/v1.4.0tomainautomatically throughGITHUB_TOKEN(or a logged-inghCLI, or the browser).
If additional commits land during review or you want to adjust the version number, simply run pnpm release --pr again; the tool updates the release branch with --force-with-lease and updates the existing PR in place.
Step 3: After the PR Is Merged, GitHub Actions Tags and Publishes Automatically
Add .github/workflows/publish-on-release-pr.yml:
yaml
name: Publish Release
on:
push:
branches:
- main
permissions:
contents: write
id-token: write
jobs:
publish:
# Trigger only when the release commit is merged into main (avoids being triggered by ordinary commits)
if: startsWith(github.event.head_commit.message, 'chore: release v')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
registry-url: https://registry.npmjs.org
- name: Install & Build
run: |
pnpm install --frozen-lockfile
pnpm build
- name: Read version & check existing tag
id: meta
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
if git rev-parse "v${VERSION}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Tag, Push & Publish to npm
if: steps.meta.outputs.exists == 'false'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
pnpm release --no-increment --no-pr --ci --no-git.commit --no-git.requireCommits --npm.publish --no-github.release
- name: Create GitHub Release from CHANGELOG.md
if: steps.meta.outputs.exists == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pnpm release --sync-releases="v${{ steps.meta.outputs.version }}" --github.release --ciWhy Run It in Two Steps?
- The first step uses
--no-increment --no-git.commit --npm.publish --no-github.release: it leaves thepackage.jsonversion and theCHANGELOG.mdcontent that came in with the merged PR untouched, and only runsnpm publish, creates the annotated tagv<version>, and pushes the tag. - The second step uses
--sync-releases="v<version>" --github.release: it parses theCHANGELOG.mdsection for that version, which has already been reviewed manually in the PR, and creates the GitHub Release precisely from it, keeping it fully consistent withCHANGELOG.md.