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
90 changes: 90 additions & 0 deletions .github/workflows/version-bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Version Bump

on:
push:
branches: [main]

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

jobs:
bump:
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
run: |
VERSION=$(python3 -c "
import re
with open('shipkit/__init__.py') as f:
match = re.search(r'__version__ = \"(.+?)\"', f.read())
print(match.group(1))
")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Current version: $VERSION"

- name: Calculate new version
id: new
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
else
PATCH=$((PATCH + 1))
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
run: |
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
Loading