Automate releases with GitHub Actions
In this tutorial, you automate the project from Release your first package on GitHub. At the end, every change merged into main updates a release pull request, and merging that pull request publishes the release: a Git tag and a GitHub release with the changelog section as notes.
Prerequisites
Section titled “Prerequisites”- The project from Release your first package, pushed to a GitHub repository.
- Permission to change the repository settings.
Allow the workflow to open pull requests
Section titled “Allow the workflow to open pull requests”In your repository on GitHub, go to Settings > Actions > General, then under Workflow permissions, check Allow GitHub Actions to create and approve pull requests.
Add the GitHub plugin
Section titled “Add the GitHub plugin”The GitHub plugin creates a GitHub release for each published version. Install it:
npm i -D @unirelman/plugin-githubpnpm add -D @unirelman/plugin-githubyarn add -D @unirelman/plugin-githubbun add -d @unirelman/plugin-githubAdd it to your configuration:
import { defineConfig } from "@unirelman/cli";import { createChangelogPlugin } from "@unirelman/plugin-changelog";import { createChangesetsPlugin } from "@unirelman/plugin-changesets";import { createGitHubPlugin } from "@unirelman/plugin-github";import { createGitPlugin } from "@unirelman/plugin-git";import { createNpmPlugin } from "@unirelman/plugin-npm";import { createSemverPlugin } from "@unirelman/plugin-semver";
export default defineConfig({ scopes: { "my-package": "./", }, plugins: [ createChangesetsPlugin(), createChangelogPlugin(), createNpmPlugin({ publish: false }), createGitPlugin(), createGitHubPlugin(), createSemverPlugin(), ],});In GitHub Actions, the plugin reads the repository and the token from the GITHUB_REPOSITORY and GITHUB_TOKEN environment variables.
Add the release workflow
Section titled “Add the release workflow”Create .github/workflows/release.yml for your package manager:
name: Release
on: push: branches: - main
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs: release: name: Release runs-on: ubuntu-latest permissions: contents: write pull-requests: write
steps: - name: Checkout repository uses: actions/checkout@v7 with: fetch-depth: 0
- name: Setup Node.js uses: actions/setup-node@v7 with: node-version: 24 cache: npm
- name: Install dependencies run: npm ci
- name: Release uses: MrSquaare/unirelman@v0.1.0-alpha.2name: Release
on: push: branches: - main
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs: release: name: Release runs-on: ubuntu-latest permissions: contents: write pull-requests: write
steps: - name: Checkout repository uses: actions/checkout@v7 with: fetch-depth: 0
- name: Install pnpm uses: pnpm/action-setup@v6 with: version: 12
- name: Setup Node.js uses: actions/setup-node@v7 with: node-version: 24 cache: pnpm
- name: Install dependencies run: pnpm install
- name: Release uses: MrSquaare/unirelman@v0.1.0-alpha.2name: Release
on: push: branches: - main
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs: release: name: Release runs-on: ubuntu-latest permissions: contents: write pull-requests: write
steps: - name: Checkout repository uses: actions/checkout@v7 with: fetch-depth: 0
- name: Enable Corepack run: corepack enable
- name: Setup Node.js uses: actions/setup-node@v7 with: node-version: 24 cache: yarn
- name: Install dependencies run: yarn install --immutable
- name: Release uses: MrSquaare/unirelman@v0.1.0-alpha.2 with: command: yarn unirelmanname: Release
on: push: branches: - main
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs: release: name: Release runs-on: ubuntu-latest permissions: contents: write pull-requests: write
steps: - name: Checkout repository uses: actions/checkout@v7 with: fetch-depth: 0
- name: Setup Bun uses: oven-sh/setup-bun@v2
- name: Setup Node.js uses: actions/setup-node@v7 with: node-version: 24
- name: Install dependencies run: bun install --frozen-lockfile
- name: Release uses: MrSquaare/unirelman@v0.1.0-alpha.2In this workflow:
fetch-depth: 0fetches the whole history and its tags, which the Git plugin checks before tagging a version.- The install step installs the unirelman CLI of your project, which the GitHub Action runs: with
npx --no-install unirelmanby default, or with itscommandinput, as in the yarn workflow. contents: writelets the GitHub Action push tags and the release branch.pull-requests: writelets it manage the release pull request.
Trigger the first release
Section titled “Trigger the first release”-
Record a change:
Terminal window npx unirelman changesets create --scopes my-package --level minor --message "add a feature"Terminal window pnpm unirelman changesets create --scopes my-package --level minor --message "add a feature"Terminal window yarn unirelman changesets create --scopes my-package --level minor --message "add a feature"Terminal window bunx unirelman changesets create --scopes my-package --level minor --message "add a feature" -
Commit and push the workflow and the changeset together:
Terminal window git add .git commit -m "ci: automate releases"git push -
Open the Actions tab of your repository. The Release workflow runs and opens a pull request named chore(release): bump versions.
The pull request contains the release commit (
package.jsonat1.1.0, the new changelog section, the changeset deleted) and a commit named chore(release): enable publishing. This second commit enables publishing for the repository, so the GitHub Action publishes only from your first merged release pull request on: see The publish setting.The description of the pull request lists the versions it releases:
## Releases- `my-package`: 1.0.1 → 1.1.0 -
Merge the pull request.
-
The workflow runs again on
main. This time it publishes: it pushes the tag1.1.0and creates a GitHub release named1.1.0with the changelog section as notes.
Keep releasing
Section titled “Keep releasing”From now on, the cycle is:
- Merge changes with their changesets into
main. - The GitHub Action updates the release pull request with every new changeset.
- When you’re ready to release, merge the release pull request.