Sub topic 14
Tagging and releasing an action
This chapter covers how to publish versions of a custom action so that workflows can depend on it without breaking when you change it. It assumes you have a working JavaScript or Docker action with an action.yml, that you know how to call it with uses:, and that you are comfortable with git tag and git push. For JavaScript actions, it also assumes you already commit your bundled dist/ folder.
How workflows pick a version
A workflow selects your action with a reference after the @ sign:
steps:
- uses: your-org/hello-action@v1The part after @ can be a branch, a tag, or a full commit SHA. The runner fetches that ref and runs whatever action.yml and code it finds there. There is no package registry. Your Git history is the release system.
This leads to the main design decision, which is how much stability each consumer gets.
| Reference | Example | Changes under the user? | Typical use |
|---|---|---|---|
| Branch | `@main` | Every push | Testing only |
| Major tag | `@v1` | Each compatible release | Most workflows |
| Exact tag | `@v1.2.3` | Only if the tag is moved | Reproducible builds |
| Commit SHA | `@8f4b7f8...` | Never | Security-sensitive pipelines |
Branch references are risky for consumers because a bad push breaks every workflow at once. Publish tags and tell people to use them.
Semantic versioning for actions
Use [semantic versioning](https://semver.org): MAJOR.MINOR.PATCH. For an action, the public interface is everything a workflow author can observe. Decide the bump from that interface.
- Patch (
v1.2.3tov1.2.4): bug fixes and dependency updates with no interface change. - Minor (
v1.2.4tov1.3.0): new optional inputs, new outputs, new behavior that is off by default. - Major (
v1.3.0tov2.0.0): anything that can break an existing workflow.
These changes require a major bump:
- Removing or renaming an input or output.
- Making an optional input
required: true. - Changing the default value of an input.
- Changing the output format, for example from a comma-separated list to JSON.
- Raising the runtime, such as moving from
node20to a newer Node version. Users on older self-hosted runners may fail. - Changing which environment variables or files the action reads or writes.
The moving major tag
If users must write @v1.2.3 and update it by hand, they will fall behind on fixes. The convention is to keep a major version tag such as v1 that always points at the newest v1.x.y release. Users who write @v1 get compatible fixes automatically. Users who need an exact build write @v1.2.3.
This means v1 is the one tag you deliberately move. The full tags, v1.2.3 and so on, should stay fixed once published.
Prepare the commit before you tag
A tag points at one commit, and consumers run exactly what is in that commit. For JavaScript actions, that must include the bundled dist/ output. A frequent release error is tagging a commit where dist/ is stale, so the published action runs old code or fails with Cannot find module.
Check this before tagging. The script below assumes your package.json defines a build script that writes to dist/:
#!/bin/sh
set -eu
npm ci
npm run build
# Fail if the build changed anything that is not committed.
if ! git diff --quiet -- dist/; then
echo "dist/ is out of date. Commit the rebuilt files first." >&2
exit 1
fi
# Fail if the working tree has any other uncommitted changes.
if [ -n "$(git status --porcelain)" ]; then
echo "Working tree is not clean." >&2
exit 1
fi
echo "Ready to tag."Docker actions need a similar check. If action.yml uses image: 'Dockerfile', the runner builds the image on every run, so a release is just the committed files. If you instead reference a prebuilt image such as docker://ghcr.io/your-org/hello:1.2.3, push that image tag first. Otherwise the action tag will point at an image that does not exist yet.
Create a release by hand
With a clean, built commit on main, create an annotated tag for the exact version, then move the major tag:
git checkout main
git pull --ff-only
git tag -a v1.2.3 -m "Release v1.2.3"
git push origin v1.2.3
# Move the major tag to the same commit.
git tag -fa v1 -m "Update v1 to v1.2.3" v1.2.3^{commit}
git push origin v1 --forceThe -f flag on git tag replaces the local v1. The --force on git push replaces the remote one. The ^{commit} suffix makes v1 point at the commit and not at the v1.2.3 tag object. Force-pushing a tag is normally something to avoid, but it is the accepted way to update a moving major tag. Never do it to a full version tag.
After pushing the tag, create a GitHub release from it. A release adds release notes, which is where users look to learn what changed and whether the upgrade is safe. You can do this in the web UI or with the GitHub CLI:
gh release create v1.2.3 --title "v1.2.3" --generate-notesAutomate the major tag
Hand-moving v1 is easy to forget. This workflow, kept in the action's own repository, moves the major tag whenever a release is published:
name: Update major tag
on:
release:
types: [published]
permissions:
contents: write
jobs:
move-major-tag:
if: ${{ !github.event.release.prerelease }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Move the major tag
env:
TAG: ${{ github.event.release.tag_name }}
run: |
case "$TAG" in
v[0-9]*.[0-9]*.[0-9]*) ;;
*) echo "Tag $TAG is not vMAJOR.MINOR.PATCH" >&2; exit 1 ;;
esac
major="${TAG%%.*}"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -fa "$major" -m "Update $major to $TAG" "$TAG^{commit}"
git push origin "$major" --forceThree details in this workflow matter:
- The tag name goes through an
env:variable and not directly into therun:script. Tag names are user-controlled text, so interpolating${{ ... }}straight into a shell script is a script-injection risk. - The
if:condition skips prereleases. Without it, publishingv2.0.0-beta.1would movev2to a beta build. permissions: contents: writeis required because the default token may be read-only. Grant it only to this workflow.
Publishing to the Marketplace
Releases do not require the GitHub Marketplace. Anyone who can read your repository can use it, and a public repository works with uses: without any listing. Listing is optional and makes the action searchable.
To list an action, the repository must be public. It must have a single action.yml at the root and no workflow files other than ones for the action's own testing. It also needs a unique name in action.yml that does not collide with an existing Marketplace action or a GitHub user, organization, or product name. When you create a release in the web UI, you can tick the option to publish to the Marketplace. Optional branding in action.yml sets the icon and color:
name: 'Hello World'
description: 'Greet someone and record the time'
branding:
icon: 'message-circle'
color: 'blue'Common errors
- Tagging before building.
dist/is stale, so the action fails or runs old logic. Run the check script first and tag only afterward. - Moving a full version tag. Users who pinned
@v1.2.3get changed behavior with no warning. Ifv1.2.3is broken, shipv1.2.4. - Breaking change in a minor release. Users on
@v1break on the next workflow run. When unsure, bump the major version. - Forgetting to push the moved tag.
git tag -fonly changes the local copy. The remotev1stays on the old commit until you push with--force. - Creating
v1as a branch. Git then has ambiguous refs namedv1, and resolution can pick the wrong one. Keep release names as tags only. - Treating tags as secure. Anyone with write access to your repository can move a tag. Consumers who need immutability should pin to a commit SHA, as the security chapter explains. GitHub also offers immutable releases as a repository setting, which locks a release's tag once it is published. If you enable it, you can no longer force-move a tag that belongs to a release, so check how it interacts with a moving major tag before turning it on.
Exercise
Your action is at v1.4.2 and the major tag v1 points at it. You add a new optional input timeout that defaults to the old behavior. What version do you release, and which tags exist and point at the new commit afterward?
Show answer
Release v1.5.0, because a new optional input with a backward-compatible default is a minor change. Afterward v1.5.0 is a new tag on the new commit, and v1 is force-moved to that same commit. The tag v1.4.2 stays where it was, so users pinned to it are unaffected.
Exercise
A release workflow runs git tag -fa "$major" ... using ${TAG%%.*} and the maintainer publishes a prerelease named v2.0.0-rc.1. What goes wrong without a prerelease check, and how do you prevent it?
Show answer
The major part resolves to v2, so the workflow moves v2 to the release-candidate commit. Anyone using @v2 would then run unfinished code. Prevent it by skipping prereleases with if: ${{ !github.event.release.prerelease }} and by validating that the tag matches vMAJOR.MINOR.PATCH before moving anything.