From 29c623c23f7eb1ffb7c232088a4d86b8d48da65f Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Fri, 30 Jun 2023 22:42:47 +0100 Subject: [PATCH] Add support for updating Major/Minor git tags on release Add support for updating the SemVer Major/Minor git tags on each release to provide support for v{x} and v{x.y} references for releases when using this GitHub Action. --- .github/workflows/tag-release.yaml | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/tag-release.yaml diff --git a/.github/workflows/tag-release.yaml b/.github/workflows/tag-release.yaml new file mode 100644 index 0000000..550dc42 --- /dev/null +++ b/.github/workflows/tag-release.yaml @@ -0,0 +1,46 @@ +--- +name: Build Release + +on: + push: + tags: + - "v*" + +permissions: + contents: write + packages: read + issues: write + +defaults: + run: + # Error handling and pipefile must be explicitly set via the default shell + # https://github.com/actions/runner/issues/353#issuecomment-1067227665 + shell: bash --noprofile --norc -eo pipefail {0} + +jobs: + + update-tags: + name: Update Major/Minor Tags + runs-on: ubuntu-latest + steps: + - name: Checkout the repository + uses: actions/checkout@v3 + + - name: Fetch the tags + run: git fetch --force --tags + + - name: Force update the major tag + run: | + TAG=${GITHUB_REF/refs\/tags\//} + VERSION=${TAG#v} + MAJOR=${VERSION%%.*} + git tag v${MAJOR} ${TAG} -f + git push origin refs/tags/v${MAJOR} -f + + - name: Force update the major/minor tag + run: | + TAG=${GITHUB_REF/refs\/tags\//} + VERSION=${TAG#v} + MAJOR_MINOR=${VERSION%.*} + git tag v${MAJOR_MINOR} ${TAG} -f + git push origin refs/tags/v${MAJOR_MINOR} -f