Skip to content

use release action and commit changes #10

use release action and commit changes

use release action and commit changes #10

Workflow file for this run

name: Semantic Versioning and Build
env:
WORKING_DIR: ./jvm-spring-web
on:
push:
branches:
- main
- feat/auto-release
- 'release/*'
pull_request:
branches:
- main
jobs:
versioning:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
working-directory: ${{ env.WORKING_DIR }}
- name: Configure Git
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
working-directory: ${{ env.WORKING_DIR }}
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
working-directory: ${{ env.WORKING_DIR }}
- name: Determine Next Version
id: determine_version
run: |
# Extracting version type (major/minor/patch) from commit message or PR title
VERSION_TYPE="patch"
if [[ "$GITHUB_REF" == refs/heads/release/* ]]; then
VERSION_TYPE="minor"
fi
# Determine if a major version bump is needed (using a ceiling of 100 for minor version)
CURRENT_VERSION=$(./gradlew -q printVersion)
MINOR_VERSION=$(echo $CURRENT_VERSION | awk -F. '{print $2}')
if [[ "$MINOR_VERSION" -ge 100 ]]; then
VERSION_TYPE="major"
fi
# Bumping version accordingly using a custom script or Gradle task
NEW_VERSION=$(./gradlew -q printVersion)
./gradlew bumpVersion -Ptype=$VERSION_TYPE
echo "::set-output name=new_version::$NEW_VERSION"
working-directory: ${{ env.WORKING_DIR }}
- name: Generate and Commit Summary of Changes
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/feat/auto-release'}}
run: |
SUMMARY_FILE="change_summary.md"
git log -1 --pretty=format:"%h - %s (%an)" >> $SUMMARY_FILE
echo "Summary of changes updated in $SUMMARY_FILE"
cat $SUMMARY_FILE
git add $SUMMARY_FILE
git commit -m "Update change summary for version ${{ steps.determine_version.outputs.new_version }}"
git push origin HEAD
working-directory: ${{ env.WORKING_DIR }}
- name: Commit Version Changes for Feature Branches
if: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/release/*' }}
run: |
git add version.txt
git commit -m "Bump version to ${{ steps.determine_version.outputs.new_version }}"
git push origin HEAD
working-directory: ${{ env.WORKING_DIR }}
- name: Create GitHub Release for Major Version
if: ${{ github.ref == 'refs/heads/release/*'}}
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.determine_version.outputs.new_version }}
name: Release ${{ steps.determine_version.outputs.new_version }}
body: |
$(cat change_summary.md)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}