---
url: https://relizy.dev/guide/github-actions.md
description: >-
  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.
---

# {{ $frontmatter.title }}

{{ $frontmatter.description }}

## The Generated Workflow

`npx relizy init` writes `.github/workflows/release.yml` (see [release workflow](./../cli/init.md#release-workflow)). For a project publishing to npm, run on demand:

```yaml
# 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. `auto` passes no type flag: [`bump.type`](./../config/bump.md#type) of the config or of the profile applies, else the bump computed from the commits; the other types force it. With the push trigger, `init` writes `on: push` on the default branch, without release type: the release commit Relizy pushes with `GITHUB_TOKEN` does not start the workflow again.
* **Build**: `publish.buildCmd` builds the packages before publishing (set by `init` from your `build` script): no build step needed.
* **`fetch-depth: 0`** only saves a fetch: Relizy fetches the history of a shallow clone itself, and handles the git identity (see [What Relizy Handles in CI](./ci-cd.md#what-relizy-handles-in-ci)).

## The Relizy Action

[`relizy/action`](https://github.com/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 `.nvmrc` or `.node-version` (else `lts/*`), with the cache of pnpm and npm, and the install from the lockfile. `setup: false` skips 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](./trusted-publishing.md) (`id-token: write`).
* **AI rewrites**: the `claude` CLI, installed with `claude-code-oauth-token`.
* **Relizy**: the version of your `package.json`, else the version of the action (`relizy-version` forces one).
* **Release**: `relizy release --yes`, with the release type, the tokens and the `args` you give, and the [outputs](#outputs-and-summary) of the release.
* **Other commands**: `command` runs another command of the CLI with the same setup and tokens: `merge-preview`, `commitlint`, `bump`, `changelog`, `publish`, `provider-release`, `social`, `sync` or `pr-comment`, with its options in `args`. `release-type` applies to `release`, `bump` and `merge-preview` only, `profile` to every command, the outputs to `release` only.

| 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](./../config/profiles.md) 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](./social-media.md)                                                                                                                  |
| `twitter-api-key`, `twitter-api-key-secret`, `twitter-access-token`, `twitter-access-token-secret` |                                        | [Twitter posts](./social-media.md)                                                                                                                             |
| `claude-code-oauth-token`, `anthropic-api-key`                                                     |                                        | [AI rewrites](./ai-changelog.md)                                                                                                                               |
| `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/action@v2.3.0` 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:

```yaml
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](./trusted-publishing.md) |
| `TWITTER_API_KEY`, `TWITTER_API_KEY_SECRET`, `TWITTER_ACCESS_TOKEN`, `TWITTER_ACCESS_TOKEN_SECRET` | `twitter-api-key`... (`RELIZY_TWITTER_API_KEY`...)           | [Twitter posts](./social-media.md)                                       |
| `SLACK_TOKEN`                                                                                      | `slack-token` (`RELIZY_SLACK_TOKEN`)                         | [Slack posts](./social-media.md)                                         |
| `TEAMS_WEBHOOK_URL`                                                                                | `teams-webhook-url` (`RELIZY_TEAMS_WEBHOOK_URL`)             | [Teams cards](./social-media.md#microsoft-teams)                         |
| `CLAUDE_CODE_OAUTH_TOKEN`                                                                          | `claude-code-oauth-token` (`RELIZY_CLAUDE_CODE_OAUTH_TOKEN`) | [AI rewrites](./ai-changelog.md)                                         |

All the variables and their aliases: [Tokens](./../config/overview.md#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: write` and `issues: write`: the [PR comment](./pr-comment.md).
* `id-token: write`: publish to npm without `NPM_TOKEN`, with [trusted publishing](./trusted-publishing.md).

## 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:

```yaml
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`](./../config/commit-templates.md)):

```yaml
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).

## Outputs and Summary

The release step (the action, or `relizy release` itself) gets the outputs of the [report](./../config/release.md#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:

```yaml
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`:

```yaml
- if: failure()
  uses: actions/upload-artifact@v4
  with:
    name: relizy-log
    path: node_modules/.cache/relizy/release.log
    include-hidden-files: true
```

## Variants

### Dry Run

Add an input to preview the release from the Actions tab (`--yes` is still needed in CI):

```yaml
on:
  workflow_dispatch:
    inputs:
      dry-run:
        description: Preview only
        type: boolean
        default: false
```

```yaml
- 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`](./../cli/merge-preview.md) 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](./merge-preview.md).

```yaml
- uses: relizy/action@v2
  with:
    command: merge-preview
```

The `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`](./../commitlint/cli.md) 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`](./../commitlint/config.md#title)): `args: --title` lints it as errors whatever the merge. See [Commitlint](./../commitlint/index.md#lint-the-commits-of-a-pull-request).

```yaml
- uses: relizy/action@v2
  with:
    command: commitlint
```

### Merge 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](./branch-sync.md).

### 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](./prereleases.md#canary-releases)).

```yaml
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](./../config/profiles.md) (`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:

```yaml
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 }}
```
