Tag with GitVersion #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tag with GitVersion | |
on: | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
tag: | |
name: Create tag from GitVersion | |
runs-on: ubuntu-latest | |
# additional safety to ensure this runs for main branch only | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Checkout repository (full history) | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install GitVersion | |
uses: gittools/actions/gitversion/[email protected] | |
with: | |
versionSpec: '6.3.x' | |
- name: Determine Version | |
id: gitversion # step id used as reference for output values | |
uses: gittools/actions/gitversion/[email protected] | |
- name: Create and push annotated tag (minor+1, patch=0) | |
env: | |
PERSONAL_ACCESS_TOKEN: ${{ secrets.GIST_AUTH_TOKEN }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
set -euo pipefail | |
MAJOR="${{ steps.gitversion.outputs.major }}" | |
MINOR="${{ steps.gitversion.outputs.minor }}" | |
# increment minor and set patch to 0 | |
NEW_MINOR=$((MINOR + 1)) | |
TAG="v${MAJOR}.${NEW_MINOR}.0" | |
echo "Computed tag: $TAG" | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
# create annotated tag (fail if exists) | |
git tag -a "$TAG" -m "Tag created by GitHub Actions using GitVersion (incremented minor)" | |
# choose token: use PAT if provided (recommended), otherwise fallback to GITHUB_TOKEN | |
TOKEN="${PERSONAL_ACCESS_TOKEN:-${GITHUB_TOKEN}}" | |
if [ -z "$TOKEN" ]; then | |
echo "No token available to push tag" | |
exit 1 | |
fi | |
# Push the tag using the chosen token over HTTPS to ensure it triggers other workflows | |
git push "https://x-access-token:${TOKEN}@github.com/${{ github.repository }}" "$TAG" | |