name: Tag Release
on:
push:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
tag-release:
name: Tag release and bump dev version
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
if: "startsWith(github.event.head_commit.message, 'release: v')"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_TOKEN }}
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Extract version
id: version
run: |
VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Detected version: $VERSION"
- name: Check if 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
echo "Tag v${{ steps.version.outputs.version }} already exists"
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Create and push 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 }}"
echo "Created and pushed tag v${{ steps.version.outputs.version }}"
- name: Bump to next dev version
if: steps.check_tag.outputs.exists == 'false'
env:
GH_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
# Calculate next dev version (patch bump + alpha.0)
VERSION="${{ steps.version.outputs.version }}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
NEXT_DEV="${MAJOR}.${MINOR}.$((PATCH + 1))-alpha.0"
echo "Bumping to next dev version: $NEXT_DEV"
# Create branch, update version, and open PR
BRANCH="chore/bump-${NEXT_DEV}"
git checkout -b "$BRANCH"
sed -i "0,/^version = \"${VERSION}\"/s//version = \"${NEXT_DEV}\"/" Cargo.toml
git add Cargo.toml
git commit -m "chore: bump to ${NEXT_DEV} for next development iteration"
git push origin "$BRANCH"
gh pr create \
--title "chore: bump to ${NEXT_DEV} for next development iteration" \
--body "Automated version bump after v${VERSION} release." \
--head "$BRANCH" \
--base main
- name: Summary
run: |
echo "## Release Tagged" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.check_tag.outputs.exists }}" == "true" ]; then
echo "Tag v${{ steps.version.outputs.version }} already existed, skipped." >> $GITHUB_STEP_SUMMARY
else
echo "- Created tag: v${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- Bumped to next dev version" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The release workflow will now build and publish artifacts." >> $GITHUB_STEP_SUMMARY
fi