Skip to content

Version Bump

Version Bump #8

Workflow file for this run

name: Version Bump
on:
workflow_run:
workflows: ["Tests"]
types:
- completed
jobs:
version-bump:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.bump_version.outputs.new_version }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Check for changes
id: check_changes
run: |
git fetch origin main
changes=$(git diff --name-only origin/main...HEAD | grep -v "uaf/version.py" || true)
if [ -n "$changes" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
- name: Check if last commit is version bump
id: check_last_commit
run: |
last_commit_message=$(git log -1 --pretty=%B)
if [[ $last_commit_message == "chore(release): bump version"* ]]; then
echo "is_version_bump=true" >> $GITHUB_OUTPUT
else
echo "is_version_bump=false" >> $GITHUB_OUTPUT
fi
- name: Get latest version
id: get_version
if: steps.check_changes.outputs.has_changes == 'true' && steps.check_last_commit.outputs.is_version_bump == 'false'
run: echo "version=$(grep -oP '(?<=__version__ = ")[^"]*' uaf/version.py)" >> $GITHUB_OUTPUT
- name: Determine version bump type
id: bump_type
if: steps.check_changes.outputs.has_changes == 'true' && steps.check_last_commit.outputs.is_version_bump == 'false'
run: |
commits=$(git log --pretty=format:"%s" $(git describe --tags --abbrev=0)..HEAD)
if echo "$commits" | grep -qiE "BREAKING CHANGE"; then
echo "type=major" >> $GITHUB_OUTPUT
elif echo "$commits" | grep -qiE "^feat(\(.+\))?:"; then
echo "type=minor" >> $GITHUB_OUTPUT
elif echo "$commits" | grep -qiE "^fix(\(.+\))?:"; then
echo "type=patch" >> $GITHUB_OUTPUT
else
echo "type=none" >> $GITHUB_OUTPUT
fi
- name: Bump version
id: bump_version
if: steps.check_changes.outputs.has_changes == 'true' && steps.check_last_commit.outputs.is_version_bump == 'false' && steps.bump_type.outputs.type != 'none'
run: |
current_version=${{ steps.get_version.outputs.version }}
IFS='.' read -ra version_parts <<< "$current_version"
major=${version_parts[0]}
minor=${version_parts[1]}
patch=${version_parts[2]}
case ${{ steps.bump_type.outputs.type }} in
major)
major=$((major + 1))
minor=0
patch=0
;;
minor)
minor=$((minor + 1))
patch=0
;;
patch)
patch=$((patch + 1))
;;
esac
new_version="$major.$minor.$patch"
echo "new_version=$new_version" >> $GITHUB_OUTPUT
sed -i "s/__version__ = \".*\"/__version__ = \"$new_version\"/" uaf/version.py
- name: Generate changelog
id: changelog
if: steps.check_changes.outputs.has_changes == 'true' && steps.check_last_commit.outputs.is_version_bump == 'false'
run: |
changelog=$(git log --pretty=format:"- %s" $(git describe --tags --abbrev=0)..HEAD)
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$changelog" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
if: steps.check_changes.outputs.has_changes == 'true' && steps.check_last_commit.outputs.is_version_bump == 'false' && steps.bump_type.outputs.type != 'none'
with:
commit-message: "chore(release): bump version to ${{ steps.bump_version.outputs.new_version }}"
title: "Bump version to ${{ steps.bump_version.outputs.new_version }}"
body: |
This PR bumps the version to ${{ steps.bump_version.outputs.new_version }}.
Changes:
${{ steps.changelog.outputs.changelog }}
branch: "version-bump-${{ steps.bump_version.outputs.new_version }}"
delete-branch: true
base: main
- name: No Version Bump Needed
if: steps.bump_type.outputs.type == 'none'
run: |
echo "No version bump needed. Only non-version-changing commits detected."