Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cicirello/ade1d559a89104140557389365154bc1 to your computer and use it in GitHub Desktop.
Save cicirello/ade1d559a89104140557389365154bc1 to your computer and use it in GitHub Desktop.
Workflow to automate maintaining major release tag for GitHub Actions (e.g., from v3.1.2 to v3)

Automated Update of Major Release Tag

Purpose

GitHub's documentation for developers of GitHub Actions recommend that in addition to specific tagged releases with SemVer release numbers that a major release tag is maintained and moved to point to the most recent specific version. For example, let's say that you just release v3.1.2 (with corresponding tag). The recommendation is to then move a v3 tag to point to that new version. This gives users of the action the option to use specific release version, such as v3.1.2, or to just use the major release number, v3, which enables them to automatically gain the benefit of any bug fixes without updating their workflows.

What This Workflow Does

When you create a release, this workflow runs. It assumes that the release tag is of the form, vX.Y.Z (where X, Y, and Z are the major, minor, and patch numbers of a SemVer version). From this, it extracts the major version forming a string of the form vX. It then adds (if it doesn't exist) or moves (if it does exist) the tag with major version only to the new released version. For example, if the new release has a tag of v3.1.2, it will move the v3 tag to also point to the v3.1.2 release. Or for example, let's say you just released a new major version, with tag v4.0.0, this workflow will add a new tag v4 that also points to v4.0.0.

Usage

To use this workflow, drop the workflow file into the .github/workflows directory. And then edit your name and username where indicated.

# Copyright (c) 2021 Vincent A. Cicirello
# MIT License
name: Update Major Release Tag
on:
release:
types: [created]
jobs:
movetag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get major version num and update tag
run: |
VERSION=${GITHUB_REF#refs/tags/}
MAJOR=${VERSION%%.*}
git config --global user.name 'YOUR NAME HERE'
git config --global user.email 'USERNAME@users.noreply.github.com'
git tag -fa ${MAJOR} -m "Update major version tag"
git push origin ${MAJOR} --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment