GitHub Actions
Release with GitHub Actions - the workflow generated by relizy init, the relizy action, its secrets and permissions, protected branches, canary releases on pull requests, and the outputs of the release.
The Generated Workflow
npx relizy init writes .github/workflows/release.yml (see release workflow). For a project publishing to npm, run on demand:
# Generated by relizy init: https://relizy.dev/guide/github-actions
name: Release
on:
workflow_dispatch:
inputs:
release:
description: Release type (auto follows the commits)
type: choice
default: auto
options: [auto, patch, minor, major]
# One release at a time
concurrency: release
jobs:
release:
runs-on: ubuntu-latest
permissions:
# The release commit, the tags and the GitHub release
contents: write
# The comment of the pull request of the release
pull-requests: write
issues: write
# npm trusted publishing (OIDC): publishes without NPM_TOKEN once set up on npmjs.com
id-token: write
steps:
- uses: actions/checkout@v7
with:
# The changelogs need the history since the last release
fetch-depth: 0
# Sets up Node.js and the package manager, installs the dependencies and runs relizy release
- id: release
uses: relizy/action@v2
with:
release-type: ${{ inputs.release }}
npm-token: ${{ secrets.NPM_TOKEN }}
# The outputs of the release, for the next steps
- if: steps.release.outputs.released == 'true'
run: echo "Released ${{ steps.release.outputs.version }} (${{ steps.release.outputs.tags }})"- Trigger: run it from the Actions tab.
autopasses no type flag:bump.typeof the config or of the profile applies, else the bump computed from the commits; the other types force it. With the push trigger,initwriteson: pushon the default branch, without release type: the release commit Relizy pushes withGITHUB_TOKENdoes not start the workflow again. - Build:
publish.buildCmdbuilds the packages before publishing (set byinitfrom yourbuildscript): no build step needed. fetch-depth: 0only saves a fetch: Relizy fetches the history of a shallow clone itself, and handles the git identity (see What Relizy Handles in CI).
The Relizy Action
relizy/action does what a release job needs after the checkout:
- Setup: your package manager (from the lockfile: pnpm, Yarn, Bun or npm), the Node version of
.nvmrcor.node-version(elselts/*), with the cache of pnpm and npm, and the install from the lockfile.setup: falseskips it, when the job already set up the project. - npm: updated to 11.5.1 or later when the job can publish with trusted publishing (
id-token: write). - AI rewrites: the
claudeCLI, installed withclaude-code-oauth-token. - Relizy: the version of your
package.json, else the version of the action (relizy-versionforces one). - Release:
relizy release --yes, with the release type, the tokens and theargsyou give, and the outputs of the release. - Other commands:
commandruns another command of the CLI with the same setup and tokens:merge-preview,commitlint,bump,changelog,publish,provider-release,social,syncorpr-comment, with its options inargs.release-typeapplies torelease,bumpandmerge-previewonly,profileto every command, the outputs toreleaseonly.
| Input | Default | Description |
|---|---|---|
command | release | The relizy command: release, merge-preview, commitlint, or another command of the CLI |
release-type | auto | auto (no type flag: bump.type of the config or the profile, else the commits), patch, minor, major, prerelease, prepatch, preminor, premajor |
profile | A release profile of the config (beta, canary...): profile: beta is --profile beta (relizy 2.3.0 or later) | |
args | More arguments for the command: --tag beta --preid beta, --config standalone, --dry-run for relizy release, --title for relizy commitlint | |
github-token | ${{ github.token }} | GitHub releases, push and PR comment |
npm-token | npm publishing, not needed with trusted publishing | |
slack-token, teams-webhook-url | Slack posts, Teams cards | |
twitter-api-key, twitter-api-key-secret, twitter-access-token, twitter-access-token-secret | Twitter posts | |
claude-code-oauth-token, anthropic-api-key | AI rewrites | |
setup | true | Set up Node.js and the package manager, install the dependencies |
package-manager | from the lockfile | npm, pnpm, yarn or bun |
node-version | .nvmrc, else lts/* | Node version |
relizy-version | the one of the project | Version of relizy, else the one of the action |
working-directory | . | Directory of the project |
relizy/action@v2 follows the latest relizy 2, relizy/[email protected] stays on a version. The other variables of the step (env:) reach relizy too: RELIZY_GITHUB_TOKEN, RELIZY_SLACK_WEBHOOK_URL...
Without the action, the same job sets up the project and runs relizy itself. relizy init writes it when you choose the relizy CLI (How does the CI run relizy?), the merge preview workflow too:
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: pnpm/action-setup@v6
- uses: actions/setup-node@v7
with:
node-version-file: .nvmrc
cache: pnpm
- run: pnpm install --frozen-lockfile
# npm trusted publishing (OIDC) needs npm 11.5.1 or later: https://relizy.dev/guide/trusted-publishing
- run: npm install -g npm@latest
- id: release
run: pnpm exec relizy release --yes ${{ inputs.release != 'auto' && format('--{0}', inputs.release) || '' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELIZY_NPM_TOKEN: ${{ secrets.NPM_TOKEN }}Secrets and Permissions
Create the secrets in Settings > Secrets and variables > Actions. GitHub gives GITHUB_TOKEN to each run.
| Secret | Input of the action (variable without it) | When |
|---|---|---|
| (none) | github-token, by default (GITHUB_TOKEN) | Always |
NPM_TOKEN | npm-token (RELIZY_NPM_TOKEN) | Publishing to npm, without trusted publishing |
TWITTER_API_KEY, TWITTER_API_KEY_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET | twitter-api-key... (RELIZY_TWITTER_API_KEY...) | Twitter posts |
SLACK_TOKEN | slack-token (RELIZY_SLACK_TOKEN) | Slack posts |
TEAMS_WEBHOOK_URL | teams-webhook-url (RELIZY_TEAMS_WEBHOOK_URL) | Teams cards |
CLAUDE_CODE_OAUTH_TOKEN | claude-code-oauth-token (RELIZY_CLAUDE_CODE_OAUTH_TOKEN) | AI rewrites |
All the variables and their aliases: Tokens. Relizy writes the npm token to a temporary .npmrc itself: no registry-url nor NODE_AUTH_TOKEN needed.
The permissions of the job:
contents: write: push the release commit and the tags, create the GitHub release. Without it, the release stops before publishing, with the fix.pull-requests: writeandissues: write: the PR comment.id-token: write: publish to npm withoutNPM_TOKEN, with trusted publishing.
Protected Branches and Rulesets
GITHUB_TOKEN cannot bypass a branch protection or a ruleset requiring pull requests or status checks: the push of the release commit is rejected, after the publish. Check out the repository with a token allowed to bypass the rule, a GitHub App (in the bypass list of the ruleset) or a fine-grained personal access token of a user allowed to bypass it, with the Contents: write permission:
steps:
- uses: actions/create-github-app-token@v2
id: app-token
with:
app-id: ${{ vars.RELEASE_APP_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
- uses: actions/checkout@v7
with:
fetch-depth: 0
# The release commit and the tags are pushed with this token
token: ${{ steps.app-token.outputs.token }}Unlike GITHUB_TOKEN, a push with this token starts the workflows: with the push trigger, skip the release commit (chore(release): by default, see templates.commitMessage):
jobs:
release:
if: "!startsWith(github.event.head_commit.message, 'chore(release): ')"A Push with GITHUB_TOKEN Starts No Workflow
The commit, the tags and the GitHub release created with GITHUB_TOKEN trigger no other workflow: a workflow on: push: tags or on: release does not run after a release. Run what follows in the same workflow, from the outputs.
Outputs and Summary
The release step (the action, or relizy release itself) gets the outputs of the report (released, status, version, tags, packages, urls, install..., plus report as JSON and summary as markdown), and the summary of the release is written to the summary of the run, without option.
Give them to the next jobs through the outputs of the job:
jobs:
release:
# ...
outputs:
released: ${{ steps.release.outputs.released }}
version: ${{ steps.release.outputs.version }}
deploy-docs:
needs: release
if: needs.release.outputs.released == 'true'
runs-on: ubuntu-latest
steps:
- run: echo "Deploying the docs of ${{ needs.release.outputs.version }}"When the release fails, the log of the run is in node_modules/.cache/relizy/release.log:
- if: failure()
uses: actions/upload-artifact@v4
with:
name: relizy-log
path: node_modules/.cache/relizy/release.log
include-hidden-files: trueVariants
Dry Run
Add an input to preview the release from the Actions tab (--yes is still needed in CI):
on:
workflow_dispatch:
inputs:
dry-run:
description: Preview only
type: boolean
default: false- id: release
uses: relizy/action@v2
with:
args: ${{ inputs.dry-run && '--dry-run' || '' }}Preview the Release on Pull Requests
A second workflow, on the pull requests, runs the action with command: merge-preview (relizy merge-preview instead of relizy release): a comment tells what the merge releases, and the job fails when the release of the merge would fail. Nothing is written nor published. relizy init offers it, relizy merge-preview init adds it to a project already set up; see Merge Preview.
- uses: relizy/action@v2
with:
command: merge-previewThe merge-preview: true input of relizy 2.3 and before still works, with a deprecation warning.
Lint the Commits of Pull Requests
command: commitlint runs relizy commitlint on the commits of the pull request, with your config: the job fails on a commit the release would misread, and each problem is an annotation on the pull request. The title is linted too, from the merge method (see commitlint.title): args: --title lints it as errors whatever the merge. See Commitlint.
- uses: relizy/action@v2
with:
command: commitlintMerge the Release into develop
With a git flow, add the rule sync: { rules: [{ from: 'main', to: ['develop'] }] }: the release job of main merges it into develop once pushed (contents: write), or opens a pull request with mode: 'pull-request' (pull-requests: write). See Branch Sync.
Canary Release on Pull Requests
Publish a test version of each pull request (1.3.0-0.canary-a3f4b2c on the canary dist-tag), and comment it on the pull request. Nothing is committed nor pushed (see Canary Releases).
name: Canary
on:
pull_request:
jobs:
canary:
# The pull requests of forks get neither the secrets nor a token able to comment
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
issues: write
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
# Relizy finds the pull request of the branch; the number also covers the pull requests of forks
- uses: relizy/action@v2
with:
args: --canary --pr-number ${{ github.event.pull_request.number }}
npm-token: ${{ secrets.NPM_TOKEN }}With a canary profile (release: { canary: true }), the same step is profile: canary.
Release When a Pull Request Is Merged
After the merge, the PR comment goes to the pull request of the merge commit, found by its commit. --pr-number makes it explicit. Same job as the generated workflow, with:
on:
pull_request:
types: [closed]
branches: [main]
jobs:
release:
# Merged, and not from a fork (no secrets, read-only token)
if: github.event.pull_request.merged == true && github.event.pull_request.head.repo.full_name == github.repository
steps:
- uses: actions/checkout@v7
with:
# The branch the pull request was merged into
ref: ${{ github.event.pull_request.base.ref }}
fetch-depth: 0
- id: release
uses: relizy/action@v2
with:
args: --pr-number ${{ github.event.pull_request.number }}