Skip to content

Create Version Tag

Create Version Tag #2

name: Create Version Tag
on:
workflow_run:
workflows: ["Build"]
types: [completed]
branches: [main]
permissions:
contents: write
jobs:
create-tag:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Extract version
id: version
run: |
VERSION=$(sed -n 's/.*"version": "\([^"]*\)".*/\1/p' sources.json | head -1)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "major=${VERSION%%.*}" >> "$GITHUB_OUTPUT"
- name: Check if version tag exists
id: check-tag
run: |
if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create version tag
if: steps.check-tag.outputs.exists == 'false'
run: |
git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}"
git push origin "v${{ steps.version.outputs.version }}"
- name: Update moving tags
run: |
VERSION="${{ steps.version.outputs.version }}"
MAJOR="${{ steps.version.outputs.major }}"
git push origin :refs/tags/latest 2>/dev/null || true
git push origin ":refs/tags/v$MAJOR" 2>/dev/null || true
git tag -d latest 2>/dev/null || true
git tag -d "v$MAJOR" 2>/dev/null || true
git tag -a latest -m "Latest release: v$VERSION"
git tag -a "v$MAJOR" -m "Latest v$MAJOR release: v$VERSION"
git push origin latest "v$MAJOR"
- name: Summary
run: |
echo "## Tag Summary" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "| Tag | Points To |" >> "$GITHUB_STEP_SUMMARY"
echo "| --- | --- |" >> "$GITHUB_STEP_SUMMARY"
echo "| v${{ steps.version.outputs.version }} | $(git rev-parse --short HEAD) |" >> "$GITHUB_STEP_SUMMARY"
echo "| v${{ steps.version.outputs.major }} | v${{ steps.version.outputs.version }} |" >> "$GITHUB_STEP_SUMMARY"
echo "| latest | v${{ steps.version.outputs.version }} |" >> "$GITHUB_STEP_SUMMARY"