Skip to content
jshacks.dev
Packages

Publish a canary release on every merge

Publish a unique 0.0.0-canary version under a canary dist-tag from CI on each merge to main, so testers get the latest code without touching latest.

1 min read
Summarize in AI

Teams that want to test the newest code without cutting a real release can publish a canary from each merge. The version carries the commit hash, so each one is unique, and the canary tag keeps it away from latest.

.github/workflows/canary.ymlYAML
name: Canary
on:
  push:
    branches: [main]
permissions:
  contents: read
  id-token: write
jobs:
  canary:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 24
          registry-url: https://registry.npmjs.org
      - run: npm ci
      - run: npm version "0.0.0-canary.${GITHUB_SHA::7}" --no-git-tag-version
      - run: npm publish --tag canary

Afterward, the tags look like this:

Text
canary: 0.0.0-canary.3f2a1bc
latest: 1.4.2

The hash will be your commit. Users install it with npm install my-lib@canary. The --no-git-tag-version flag stops npm version from creating a commit and tag in the CI checkout.

Each canary stays on the registry forever, so clean-up is manual. Using a prerelease version also keeps it out of any caret range, as covered in the semver docs.

Share

More snippets

Packages

Initialize a package with npm init

Initialize a package.json with npm init, skip the questions with the yes flag, and set your own defaults for author and license in npm config.

1 min read
Packages

Generate a changelog from commits

Turn conventional commit messages into a CHANGELOG.md section with conventional-changelog, grouped by feature and fix. Works with any Git history.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.