Skip to content
Visual explainer 3h to learn 4 steps

Release automation & GitHub Packages

Tag, build changelogs and publish packages or images on release.

By Invicly Tech, , in Git, GitHub & GitHub Actions. About 10 minutes to read.

Topic 16 of 18

In short

Release automation turns a version tag into a changelog, a GitHub Release and published packages or images. Semantic versions tell users whether an upgrade is safe.

Explained simply

A release is a named, frozen version of your software that people can rely on. Instead of "whatever is on main today", users get v1.4.0, with a list of what changed and files or images they can download. Automating releases makes them boring, which is exactly what you want.

Version numbers carry a promise. In semantic versioning, MAJOR.MINOR.PATCH, a patch (1.4.1) only fixes bugs, a minor (1.5.0) adds features without breaking anything, and a major (2.0.0) may break existing users. Users decide whether to upgrade based on that number.

A changelog tells people what changed. Writing it by hand is easy to forget, so tools build it from commit messages or merged pull requests. That only works if commit messages follow a simple pattern, like feat: for features and fix: for fixes.

Publishing is the last step: push a package to a registry or a container image to GitHub Container Registry (GHCR), and create the GitHub Release page. A workflow does it the same way every time, triggered by a tag or by merging a release pull request.

Press Play on a diagram to walk through it one step at a time.

FlowTag to published release
  1. 1
    Merge to main

    Conventional commit messages like feat: and fix:.

  2. 2
    Push tag v1.4.0

    Major.minor.patch based on the changes.

  3. 3
    Workflow triggers

    on: push: tags: ['v*']

  4. 4
    Generate notes

    Changelog built from merged PRs and commits.

  5. 5
    Publish

    Package to GitHub Packages, image to GHCR.

  6. 6
    GitHub Release

    Notes plus attached build files.

MapOne tag, many release outputs
tag v1.4.0
  • GitHub Release
    • Generated notes
    • Attached binaries and checksums
  • Container image
    • ghcr.io/acme/api:1.4.0
    • :1.4 and :latest
  • Package
    • @acme/api-client 1.4.0 on npm.pkg.github.com
  • Changelog
    • CHANGELOG.md section for 1.4.0

In depth

Semantic versioning details

Below 1.0.0, anything may change at any time, so 0.x versions make no stability promise. Pre-releases add a hyphen: 2.0.0-rc.1 comes before 2.0.0, and package managers do not install pre-releases unless asked. Build metadata after a plus, like 1.4.0+build.42, is ignored when comparing versions.

Git tags carry the version. Use annotated tags (git tag -a v1.4.0 -m "v1.4.0") because they record who tagged and when, and can be signed with -s. The v prefix is a convention, not part of semver. Once a version is published, never move or reuse its tag: people and caches have already pulled it, and a different artifact under the same version causes confusing bugs.

  • Breaking change: bump MAJOR, reset MINOR and PATCH to 0
  • New feature: bump MINOR, reset PATCH
  • Bug fix: bump PATCH
  • git describe --tags shows the latest tag reachable from HEAD

From commits to a changelog

Conventional Commits is a message format: type, optional scope, colon, summary. feat(api): add export means a minor bump, fix: means a patch, and either feat!: or a BREAKING CHANGE: footer means a major bump. Other types like docs, chore, refactor and test usually do not trigger a release. With squash merging, the PR title becomes the commit, so check PR titles in CI.

release-please keeps an open release PR that updates the version file and CHANGELOG.md as commits land; merging that PR creates the tag and the GitHub Release. semantic-release releases on every qualifying push to main without a PR. If you prefer labels to commit formats, GitHub's generated release notes group merged PRs into sections configured in .github/release.yml.

FlowThe release-please loop
  1. 1
    Merge feat: and fix: PRs

    Conventional PR titles on main

  2. 2
    Release PR updated

    Next version and changelog proposed

  3. 3
    Merge the release PR

    A human decides when to ship

  4. 4
    Tag and Release

    v1.5.0 with generated notes

  5. 5
    Publish job

    Runs because release_created is true

GitHub Packages and GHCR

GitHub Packages hosts npm, Maven, Gradle, NuGet and RubyGems registries plus the container registry at ghcr.io. A workflow in the same repo can publish with GITHUB_TOKEN if the job has packages: write. For npm, the package name must be scoped to the owner, like @acme/utils, and setup-node with registry-url: https://npm.pkg.github.com plus NODE_AUTH_TOKEN does the login. Installing from GitHub's npm registry needs a token even for public packages.

For images, use docker/login-action, docker/metadata-action and docker/build-push-action. metadata-action turns the tag v1.4.0 into image tags 1.4.0, 1.4 and latest, and adds an org.opencontainers.image.source label that links the image to the repo. Image names must be lowercase, so github.repository with capitals breaks a hand-written docker tag. A new container package starts private; change its visibility in the package settings.

The GITHUB_TOKEN trigger trap

To prevent endless loops, events caused by GITHUB_TOKEN do not start new workflow runs, except workflow_dispatch and repository_dispatch. So if release-please (running with GITHUB_TOKEN) creates a tag and a release, a separate workflow with on: release or on: push: tags never fires. Many teams lose an afternoon to this.

There are two clean fixes. One: publish in the same workflow, in a job that runs only when the release step reports release_created. Two: create the release with a GitHub App installation token (actions/create-github-app-token), whose events do trigger workflows. Avoid personal access tokens for this; they are tied to one person and usually have far more access than needed.

SequenceWhy the publish workflow did not start
release workflow
GitHub
publish workflow
  1. 1Create tag v1.5.0 with GITHUB_TOKEN
    release workflow to GitHub: Create tag v1.5.0 with GITHUB_TOKEN
  2. 2Event made by GITHUB_TOKEN: no new runs
    GitHub to GitHub: Event made by GITHUB_TOKEN: no new runs
  3. 3on: push tags is NOT triggered
    GitHub to publish workflow: on: push tags is NOT triggered
  4. 4Fix: publish job in the same run
    release workflow to release workflow: Fix: publish job in the same run
  5. 5Or create the tag with an App token
    release workflow to GitHub: Or create the tag with an App token

Learn it in 4 short steps

About 45m each. Track them with a timer in your plan.

  1. 1
    Tag releases with semantic versions~45m
  2. 2
    Generate changelogs automatically~45m
  3. 3
    Publish packages to GitHub Packages~45m
  4. 4
    Push images to GHCR on release~45m

Key points

  • Bump major for breaking changes, minor for features, patch for fixes.
  • Tools like release-please or semantic-release derive versions from commit messages.
  • GITHUB_TOKEN with packages: write can push to GHCR without a personal token.
  • Build once per tag so the release, package and image all match.

Key terms

Tap a card to flip it. 0/4 known

Examples

yaml
on: { push: { tags: ["v*"] } }
permissions: { contents: write, packages: write }
jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
      - run: docker build -t ghcr.io/${{ github.repository }}:${{ github.ref_name }} .
      - run: docker push ghcr.io/${{ github.repository }}:${{ github.ref_name }}
      - run: gh release create ${{ github.ref_name }} --generate-notes
        env: { GH_TOKEN: "${{ github.token }}" }

A tag push builds, pushes to GHCR and creates the release.

release-please with publishing in the same run

You want a release PR and automatic publishing, without the GITHUB_TOKEN trap. Step 1: run release-please on every push to main. Step 2: expose release_created and tag_name as job outputs. Step 3: a publish job calls your reusable publish workflow only when a release was actually created. Step 4: grant packages: write at the top, because a called workflow cannot raise permissions.

yaml
on: { push: { branches: [main] } }
permissions: { contents: write, pull-requests: write, packages: write }
jobs:
  release:
    runs-on: ubuntu-latest
    outputs:
      created: ${{ steps.rp.outputs.release_created }}
      tag: ${{ steps.rp.outputs.tag_name }}
    steps:
      - id: rp
        uses: googleapis/release-please-action@v4
        with: { release-type: node }
  publish:
    needs: release
    if: needs.release.outputs.created == 'true'
    uses: ./.github/workflows/publish.yml
    with: { tag: "${{ needs.release.outputs.tag }}" }

Push a correctly tagged image to GHCR on a version tag

This workflow runs on push of tags matching v*.*.*. Step 1: log in to ghcr.io with GITHUB_TOKEN (packages: write). Step 2: metadata-action computes lowercase image names and semver tags, so v1.4.0 becomes 1.4.0, 1.4 and latest, plus OCI labels. Step 3: build-push-action builds and pushes with those tags and labels. The labels link the package to the repo on GitHub.

yaml
permissions: { contents: read, packages: write }
jobs:
  image:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: docker/login-action@v3
        with: { registry: ghcr.io, username: "${{ github.actor }}", password: "${{ secrets.GITHUB_TOKEN }}" }
      - id: meta
        uses: docker/metadata-action@v5
        with:
          images: ghcr.io/${{ github.repository }}
          tags: "type=semver,pattern={{version}}\ntype=semver,pattern={{major}}.{{minor}}"
      - uses: docker/build-push-action@v6
        with: { context: ., push: true, tags: "${{ steps.meta.outputs.tags }}", labels: "${{ steps.meta.outputs.labels }}" }

Quick reference

  • feat: is a minor bump, fix: a patch, feat!: or a BREAKING CHANGE: footer a major
  • git tag -a v1.4.0 -m "v1.4.0" && git push origin v1.4.0 creates an annotated release tag
  • gh release create v1.4.0 --generate-notes builds notes from merged PRs
  • .github/release.yml groups generated release notes by PR labels
  • packages: write lets GITHUB_TOKEN push to ghcr.io and GitHub Packages
  • Image names must be lowercase; docker/metadata-action handles that
  • Tags and releases made with GITHUB_TOKEN do not trigger other workflows
  • Never re-tag a published version; release a new patch instead

Common mistakes

  • Re-tagging a published version with different code, confusing every user.
  • Messy commit messages that make generated changelogs useless.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Which version comes first when sorted by semver precedence?

Question 2

2A commit message says fix(auth)!: drop legacy tokens. What release does it trigger?

Question 3

3release-please creates a release with GITHUB_TOKEN, but your on: release workflow never runs. Why?

Question 4

4docker push ghcr.io/Acme/API:1.0.0 fails. What is the likely cause?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Create an annotated tag v0.1.0 for the current commit, push it, and create a GitHub Release with generated notes.

  2. Exercise 2medium

    Configure generated release notes with sections for features, fixes and everything else, and exclude PRs labelled skip-changelog.

  3. Exercise 3hard

    Publish an npm package @acme/utils to GitHub Packages when a GitHub Release is published.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Should I use release-please or semantic-release?
release-please gives you a release PR to review and merge when you are ready. semantic-release ships automatically on every qualifying push. Both read Conventional Commits.
Is GitHub Container Registry free?
Public container images are free to store and pull. Private packages use your plan's included storage and data transfer, then are billed.
What is the difference between a tag and a release?
A tag is a Git pointer to a commit. A GitHub Release is built on a tag and adds notes, downloadable assets and a page users can follow.
How do I link a GHCR image to my repository?
Add the label org.opencontainers.image.source with the repo URL, which docker/metadata-action does automatically, or connect it in the package settings.
ShareXLinkedInWhatsApp