Bump Version #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Bump Version | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| semver_part: | |
| description: 'For non-alpha versions: which semver part to bump' | |
| required: false | |
| default: 'patch' | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| jobs: | |
| bump-version: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Bump version in gradle.properties | |
| id: bump | |
| run: | | |
| CURRENT=$(grep '^mod_version=' gradle.properties | cut -d'=' -f2) | |
| echo "Current version: $CURRENT" | |
| if echo "$CURRENT" | grep -qE '\-alpha'; then | |
| # Bump the trailing revision number | |
| # e.g. 6.1.0-alpha.autoaim.1 -> 6.1.0-alpha.autoaim.2 | |
| # 6.1.0-alpha.1 -> 6.1.0-alpha.2 | |
| PREFIX=$(echo "$CURRENT" | sed 's/\.[0-9]*$//') | |
| REVISION=$(echo "$CURRENT" | grep -oE '[0-9]+$') | |
| NEW="${PREFIX}.$((REVISION + 1))" | |
| else | |
| # Bump the requested semver part | |
| SEMVER=$(echo "$CURRENT" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+') | |
| SUFFIX=$(echo "$CURRENT" | sed "s|^${SEMVER}||") | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$SEMVER" | |
| case "${{ inputs.semver_part }}" in | |
| major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;; | |
| minor) MINOR=$((MINOR + 1)); PATCH=0 ;; | |
| patch) PATCH=$((PATCH + 1)) ;; | |
| esac | |
| NEW="${MAJOR}.${MINOR}.${PATCH}${SUFFIX}" | |
| fi | |
| echo "New version: $NEW" | |
| sed -i "s/^mod_version=.*/mod_version=${NEW}/" gradle.properties | |
| echo "new_version=$NEW" >> "$GITHUB_OUTPUT" | |
| echo "old_version=$CURRENT" >> "$GITHUB_OUTPUT" | |
| - name: Commit and push | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add gradle.properties | |
| git commit -m "Bump version: ${{ steps.bump.outputs.old_version }} -> ${{ steps.bump.outputs.new_version }}" | |
| git push origin HEAD |