Skip to content

Commit

Permalink
Merge pull request #44 from mtrogman/test-minor-versioning
Browse files Browse the repository at this point in the history
Test minor versioning
  • Loading branch information
mtrogman authored Oct 12, 2023
2 parents 5a1919b + 70c6bca commit 849740e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 54 deletions.
86 changes: 33 additions & 53 deletions .github/workflows/minor-version-bump.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update Minor Version
name: Update Minor Version on PR

on:
pull_request:
Expand All @@ -17,62 +17,42 @@ jobs:
run: |
git config --global user.email "$GH_EMAIL"
git config --global user.name "$GH_USER"
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Check if Minor Version Needs Bump
id: check_minor_bump
run: |
PR_NUMBER="${{ github.event.pull_request.number }}"
MINOR_BUMP_REQUIRED=$(curl -s -X GET "https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" | jq -r 'map(select(.body | contains("@minor-version-bump"))) | length')
if [ "$MINOR_BUMP_REQUIRED" -gt 0 ]; then
echo "::set-output name=minor_bump_requested::true"
else
echo "::set-output name=minor_bump_requested::false"
fi
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
MINOR_BUMP_FLAG="bump_minor_${BRANCH_NAME}"
- name: Bump Minor Version
if: steps.check_minor_bump.outputs.minor_bump_requested == 'true'
id: bump_version
run: |
# Parse the current version
CURRENT_VERSION=$(cat VERSION)
MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
PATCH=$(echo $CURRENT_VERSION | cut -d. -f3)
# Calculate the new version
NEW_MINOR=$((MINOR + 1))
NEW_VERSION="$MAJOR.$NEW_MINOR.0"
if [ -z "$(git show-ref --heads "$MINOR_BUMP_FLAG")" ]; then
git checkout -b $BRANCH_NAME
git pull --rebase origin $BRANCH_NAME
# Parse the current version
CURRENT_VERSION=$(cat VERSION)
MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
PATCH=$(echo $CURRENT_VERSION | cut -d. -f3)
# Calculate the new version
NEW_MINOR=$((MINOR + 1))
NEW_VERSION="$MAJOR.$NEW_MINOR.0"
# Update the version file
echo "$NEW_VERSION" > VERSION
echo "Bumped version to $NEW_VERSION"
# Commit and push the changes
git commit -am "Bump version to $NEW_VERSION"
git push origin $BRANCH_NAME
# Update the version file
echo "$NEW_VERSION" > VERSION
echo "Bumped version to $NEW_VERSION"
# Set the new version as an output
echo "::set-output name=new_version::$NEW_VERSION"
- name: Commit and Push Version Bump
if: steps.check_minor_bump.outputs.minor_bump_requested == 'true'
run: |
git add VERSION
git commit -m "Bump version to ${{ steps.bump_version.outputs.new_version }}"
git push
- name: Create Git Tag
if: steps.check_minor_bump.outputs.minor_bump_requested == 'true'
run: |
git tag v${{ steps.bump_version.outputs.new_version }}
git push origin v${{ steps.bump_version.outputs.new_version }}
- name: Create Release
if: steps.check_minor_bump.outputs.minor_bump_requested == 'true'
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.bump_version.outputs.new_version }}
release_name: ${{ steps.bump_version.outputs.new_version }}
draft: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Set the new version as an output
echo "::set-output name=new_version::$NEW_VERSION"
else
echo "We already bumped minor for this branch"
fi
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.17
0.3.0

0 comments on commit 849740e

Please sign in to comment.