Skip to content

Manage Release Tags #12

Manage Release Tags

Manage Release Tags #12

name: Manage Release Tags
on:
create:
schedule:
- cron: '0 8 * * 2' # Every Tuesday at 8 AM UTC
workflow_dispatch:
permissions:
contents: write
actions: write
jobs:
create-tags:
name: Create Release Tags
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Handle initial release tag
if: github.event_name == 'create' && github.event.ref_type == 'branch'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH_NAME="${{ github.event.ref }}"
# Check if this is a release branch
if [[ ! "$BRANCH_NAME" =~ ^release-[0-9]+\.[0-9]+$ ]]; then
echo "Not a release branch, skipping"
exit 0
fi
# Extract version from branch name
VERSION=${BRANCH_NAME#release-}
TAG="v${VERSION}.0"
# Check if tag already exists
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists, skipping"
exit 0
fi
echo "Creating initial release tag $TAG for branch $BRANCH_NAME"
git tag "$TAG"
git push origin "$TAG"
echo "Triggering release workflow for $TAG"
gh workflow run release.yml -f tag="$TAG"
- name: Handle patch release tags
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Find all release branches
RELEASE_BRANCHES=$(git branch -r | grep -E 'origin/release-[0-9]+\.[0-9]+$' | sed 's|origin/||' | sed 's/^[[:space:]]*//')
if [ -z "$RELEASE_BRANCHES" ]; then
echo "No release branches found"
exit 0
fi
echo "Found release branches:"
echo "$RELEASE_BRANCHES"
for BRANCH in $RELEASE_BRANCHES; do
echo "Processing branch: $BRANCH"
# Extract major.minor version from branch name
if [[ ! "$BRANCH" =~ ^release-([0-9]+\.[0-9]+)$ ]]; then
echo "Invalid branch name format: $BRANCH, skipping"
continue
fi
VERSION_PREFIX="${BASH_REMATCH[1]}"
# Find latest tag for this release branch
LATEST_TAG=$(git tag -l "v${VERSION_PREFIX}.*" | sort -V | tail -n1)
if [ -z "$LATEST_TAG" ]; then
# No tags exist for this branch, create v.X.Y.0
NEW_TAG="v${VERSION_PREFIX}.0"
echo "No existing tags for $BRANCH, creating initial tag $NEW_TAG"
else
# Check if there are commits since the last tag
git checkout "origin/$BRANCH" --quiet
COMMITS_SINCE_TAG=$(git rev-list "$LATEST_TAG..origin/$BRANCH" --count)
if [ "$COMMITS_SINCE_TAG" -eq 0 ]; then
echo "No new commits on $BRANCH since $LATEST_TAG, skipping"
continue
fi
echo "Found $COMMITS_SINCE_TAG commits since $LATEST_TAG"
# Extract and increment patch version
PATCH_VERSION=$(echo "$LATEST_TAG" | sed "s/v${VERSION_PREFIX}\.//" )
NEW_PATCH=$((PATCH_VERSION + 1))
NEW_TAG="v${VERSION_PREFIX}.${NEW_PATCH}"
echo "Creating new patch tag $NEW_TAG for $BRANCH"
fi
# Check if tag already exists
if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then
echo "Tag $NEW_TAG already exists, skipping"
continue
fi
# Create and push the tag
git checkout "origin/$BRANCH" --quiet
git tag "$NEW_TAG"
git push origin "$NEW_TAG"
echo "Successfully created and pushed tag $NEW_TAG"
# Trigger release workflow
echo "Triggering release workflow for $NEW_TAG"
gh workflow run release.yml -f tag="$NEW_TAG"
done