feat(workflows): add major version tagging for releases

- Introduce a workflow to automate major version tag creation
- Derives major version from release tag and re-creates the tag
- Supports easier version management for published releases
This commit is contained in:
2025-06-27 22:16:34 +02:00
parent 2ea1395252
commit 62e259f9f0

View File

@@ -0,0 +1,61 @@
name: Create Major Version Tag
on:
release:
types: [published]
jobs:
update-major-tag:
runs-on: ubuntu-latest
permissions:
contents: write # required to delete/create tags
steps:
# ▸ 1. Check out the repository at the release tag
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch all tags
ref: ${{ github.event.release.tag_name }}
# ▸ 2. Extract the major version from the release tag
- name: Derive major version
id: derive
shell: bash
run: |
TAG="${{ github.event.release.tag_name }}" # e.g., v2.3.4
echo "Release tag: $TAG"
TAG_NOPREFIX="${TAG#v}" # remove leading v/V
MAJOR="${TAG_NOPREFIX%%.*}" # take part before the first dot
MAJOR_TAG="v${MAJOR}" # e.g., v2
echo "Major tag: $MAJOR_TAG"
echo "major_tag=$MAJOR_TAG" >>"$GITHUB_OUTPUT"
# ▸ 3. Delete the old major tag (if it exists) and create a new one
- name: Re-create major tag
env:
MAJOR_TAG: ${{ steps.derive.outputs.major_tag }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
shell: bash
run: |
set -euo pipefail
git config user.name "$CI_COMMIT_AUTHOR_NAME"
git config user.email "$CI_COMMIT_AUTHOR_EMAIL"
# Determine the specific commit of the release tag
COMMIT_SHA="$(git rev-list -n 1 "$RELEASE_TAG")"
echo "Commit of the release tag: $COMMIT_SHA"
# (a) Locally and remotely remove the old major tag (if it exists)
git tag -d "$MAJOR_TAG" 2>/dev/null || true
git push --delete origin "$MAJOR_TAG" 2>/dev/null || true
# (b) Create and push a new annotated tag
git tag -a "$MAJOR_TAG" "$COMMIT_SHA" \
-m "Update $MAJOR_TAG → $RELEASE_TAG"
git push origin "$MAJOR_TAG"
echo "✅ $MAJOR_TAG now points to $RELEASE_TAG ($COMMIT_SHA)"