Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 19 additions & 59 deletions .github/workflows/version-bump.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,22 @@
name: Version Bump
name: Auto Tag

on:
push:
branches: [main]

# Prevent concurrent version bumps
concurrency:
group: version-bump
cancel-in-progress: false

jobs:
bump:
tag:
runs-on: ubuntu-latest
# Skip if the commit was made by this action (prevent infinite loop)
if: "!startsWith(github.event.head_commit.message, 'v')"

permissions:
contents: write

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Determine bump type from commit message
id: bump
run: |
MSG="${{ github.event.head_commit.message }}"
# Extract first line of squash commit message
FIRST_LINE=$(echo "$MSG" | head -1)

if echo "$FIRST_LINE" | grep -qiE '^breaking[:(]|BREAKING CHANGE'; then
echo "type=major" >> "$GITHUB_OUTPUT"
elif echo "$FIRST_LINE" | grep -qiE '^feat[:(]'; then
echo "type=minor" >> "$GITHUB_OUTPUT"
else
echo "type=patch" >> "$GITHUB_OUTPUT"
fi

echo "Commit: $FIRST_LINE"
echo "Bump type: $(cat "$GITHUB_OUTPUT" | grep type | cut -d= -f2)"

- name: Read current version
id: current
- name: Read version from __init__.py
id: version
run: |
VERSION=$(python3 -c "
import re
Expand All @@ -52,39 +25,26 @@ jobs:
print(match.group(1))
")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Current version: $VERSION"
echo "Version: $VERSION"

- name: Calculate new version
id: new
- name: Check if tag already exists
id: check
run: |
IFS='.' read -r MAJOR MINOR PATCH <<< "${{ steps.current.outputs.version }}"
BUMP="${{ steps.bump.outputs.type }}"

if [ "$BUMP" = "major" ]; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
elif [ "$BUMP" = "minor" ]; then
MINOR=$((MINOR + 1))
PATCH=0
TAG="v${{ steps.version.outputs.version }}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Tag $TAG already exists, skipping"
else
PATCH=$((PATCH + 1))
echo "exists=false" >> "$GITHUB_OUTPUT"
echo "Tag $TAG does not exist, will create"
fi

NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
echo "New version: $NEW_VERSION ($BUMP bump)"

- name: Update version in __init__.py
run: |
sed -i "s/__version__ = \".*\"/__version__ = \"${{ steps.new.outputs.version }}\"/" shipkit/__init__.py
cat shipkit/__init__.py

- name: Commit and tag
- name: Create tag
if: steps.check.outputs.exists == 'false'
run: |
TAG="v${{ steps.version.outputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add shipkit/__init__.py
git commit -m "v${{ steps.new.outputs.version }}"
git tag "v${{ steps.new.outputs.version }}"
git push origin main --tags
git tag "$TAG"
git push origin "$TAG"
echo "Created and pushed tag $TAG"
Loading