Sub topic 15
Versioning and Releasing for Other Repositories
This chapter covers how to publish a composite action so other repositories can depend on it without breaking when you change it. It assumes you can write an action.yml, you know how to call a local action from a workflow, and you are comfortable creating Git tags and branches.
Why versioning matters for actions
A workflow that uses ./.github/actions/greet always runs the action from the same commit as the workflow. A workflow in another repository has no such guarantee. It references your action with uses: owner/repo@ref, and ref decides which version of your code runs on every job.
The ref can be a branch, a tag, or a full commit SHA. Each choice trades convenience against safety:
| Reference | Example | Moves when you push? | Typical use |
|---|---|---|---|
| Branch | `@main` | Yes, on every push | Experiments only |
| Major tag | `@v1` | Yes, when you move the tag | Most consumers |
| Exact tag | `@v1.2.3` | No, if you never retag | Consumers who want precise control |
| Commit SHA | `@8f4b7f8...` (40 characters) | Never | Security-sensitive pipelines |
A branch reference means every push to main instantly changes what every consumer runs. A bug you commit at 10:00 breaks their builds at 10:01. Publish tags instead.
Where the action lives
Two layouts work for sharing:
- Dedicated repository. The
action.ymlsits at the repository root. Consumers writeuses: owner/repo@v1. - Subdirectory of a larger repository. The action sits at, for example,
actions/greet/action.yml. Consumers writeuses: owner/repo/actions/greet@v1. All actions in that repository share the same tags, so one tag covers every action in it.
The dedicated layout gives each action its own version history and is easier to reason about. Use the subdirectory layout when several small actions change together.
Visibility matters too. A public repository can be used by anyone. A private repository can be shared only if you allow it. In the repository settings under Actions, there is an access setting that lets workflows in other repositories of the same user or organization use the action. Without it, consumers get an error that the action could not be found.
Semantic versioning for actions
Use semantic versioning, written MAJOR.MINOR.PATCH. For an action, define "breaking" from the consumer's point of view. These changes are breaking and need a new major version:
- Renaming or removing an input or output.
- Making an optional input required.
- Changing the meaning of an existing output, for example its format.
- Raising requirements, such as needing a newer runner image or a tool the consumer did not install.
- Changing a default in a way that alters behavior.
These changes are safe for a minor or patch release:
- Adding an optional input with a default that preserves current behavior.
- Adding a new output.
- Fixing a bug so the action does what its documentation already said.
Remember that all inputs are strings. If a consumer passes run-tests: "true" and you change the check to 'yes', that is a breaking change even though the YAML looks the same.
Floating major tags
Consumers usually write @v1, not @v1.4.2. They want bug fixes without editing every workflow. The convention is to keep two kinds of tags:
- Immutable release tags:
v1.0.0,v1.0.1,v1.1.0. - A floating major tag:
v1, which you move to point at the newestv1.x.yrelease.
Create a release and move the major tag like this:
git checkout main
git pull --ff-only
git tag -a v1.1.0 -m "Add optional 'greeting-prefix' input"
git push origin v1.1.0
# Move the floating major tag to the same commit
git tag -fa v1 -m "Update v1 to v1.1.0" v1.1.0
git push origin v1 --forceThe -f flag on git tag replaces an existing local tag. The --force on the push replaces the remote tag. This is one of the few cases where force-pushing is expected, but apply it only to the floating major tag. Never move an exact tag such as v1.1.0. Consumers who pinned it expect it to stay put.
The diagram below shows how the tags relate to commits over time.
In this history, v1 pointed to the v1.0.0 commit at first, then to v1.0.1, and now points to v1.1.0. A consumer on @v1 receives each of those updates on its next run. A consumer on @v1.0.1 still runs the same code it always did.
Automating the release
Moving tags by hand invites mistakes, such as tagging the wrong commit. Automate it with a workflow that runs when you publish a release:
name: Release
on:
release:
types: [published]
permissions:
contents: write
jobs:
move-major-tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Move major tag
env:
TAG: ${{ github.event.release.tag_name }}
run: |
if [[ ! "$TAG" =~ ^v([0-9]+)\.[0-9]+\.[0-9]+$ ]]; then
echo "Tag '$TAG' is not a plain vMAJOR.MINOR.PATCH tag" >&2
exit 1
fi
MAJOR="v${BASH_REMATCH[1]}"
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"
git push origin "$MAJOR" --forceThree details deserve attention:
- The tag name goes through
env, then is read as$TAG. This follows the same injection rule as inputs: never interpolate${{ }}values directly into a script body. - The regular expression rejects pre-release tags such as
v2.0.0-beta.1, so a beta cannot movev2. - The job needs
contents: writeso the default token may push tags.
Publishing to the Marketplace
Publishing to the GitHub Marketplace is optional. It makes the action searchable. The requirements are that the repository is public, has a single action.yml at the root, and has a unique name in that file. You also add branding with an icon and color:
name: Greet
description: Build a greeting and expose it as an output
branding:
icon: message-circle
color: blue
inputs:
who-to-greet:
description: Name to greet
required: false
default: World
outputs:
greeting:
description: The greeting text
value: ${{ steps.build.outputs.greeting }}
runs:
using: composite
steps:
- id: build
shell: bash
env:
WHO: ${{ inputs.who-to-greet }}
run: echo "greeting=Hello, ${WHO}" >> "$GITHUB_OUTPUT"You then choose to publish to the Marketplace when drafting a release. Skip all of this for internal actions.
Documenting each release
Consumers decide whether to upgrade by reading your notes, so keep them useful:
- A README with every input and output, its default, and a complete
uses:example. - Release notes that name breaking changes first, then new features, then fixes.
- A migration note for each major version, for example "In v2,
nodewas renamed tonode-version."
Consuming a pinned action safely
If you consume other people's actions, the same rules apply in reverse. A tag can be moved by its owner, so a compromised account could point v1 at malicious code. Pinning to a full commit SHA prevents this, because a SHA cannot be moved. Add a comment so humans can read the version:
steps:
- uses: actions/checkout@v4
- uses: owner/greet-action@8f4b7f8c1d2e3a4b5c6d7e8f9a0b1c2d3e4f5a6b # v1.1.0
with:
who-to-greet: OctocatThe SHA above is a placeholder. Use the real 40-character SHA from the release you reviewed. A dependency update tool such as Dependabot can open pull requests that bump pinned SHAs and update the version comment.
Testing the released reference
Before announcing a release, run a workflow in a separate consumer repository that calls the published ref, not the local path. This catches problems a local test hides, such as a missing action.yml at the expected path or a script that was not committed. Add a scheduled run so you notice when a runner image update breaks your action.
name: Smoke test released action
on:
workflow_dispatch:
schedule:
- cron: "0 6 * * 1"
jobs:
smoke:
runs-on: ubuntu-latest
steps:
- id: hello
uses: owner/greet-action@v1
with:
who-to-greet: Smoke
- env:
GREETING: ${{ steps.hello.outputs.greeting }}
run: |
test "$GREETING" = "Hello, Smoke"Common mistakes
- Retagging an exact version. Consumers who pinned
v1.1.0get different code and cannot reproduce old builds. Publishv1.1.1instead. - Forgetting to move
v1. The release exists, but consumers on@v1never receive the fix. - Releasing a breaking change under the current major. Every consumer on the floating tag breaks at once. Start
v2. - Tagging a commit that lacks
action.ymlat the expected path. The consumer sees "Can't find 'action.yml'". - Relying on
main. The branch changes continuously and offers no stable contract.
Exercise
Your action is at v1.3.0, and v1 points to it. You rename the input node to node-version and remove the old name. Which tag do you create, what do you do with v1, and why?
Show answer
Create v2.0.0 and a new floating tag v2 pointing to it. Leave v1 where it is (or move it only for later non-breaking v1.x.y fixes). Removing an input is a breaking change, so consumers on @v1 must not receive it. They upgrade to @v2 when they have updated their workflows.
Exercise
Why does the release workflow pass github.event.release.tag_name through env instead of writing ${{ github.event.release.tag_name }} inside the script?
Show answer
Expressions in ${{ }} are substituted into the script text before the shell runs, so a value containing shell syntax could execute as code. Passing it through env makes the shell treat it as plain data in a variable.