Bump gradle/gradle-build-action from 2.11.0 to 3.5.0 #94
Workflow file for this run
This file contains 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: Java CI with Maven | |
on: | |
push: | |
branches: [ master ] | |
paths-ignore: | |
- "hello-world-gradle/**" | |
- "hello-world-war/**" | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
branches: [ master ] | |
paths-ignore: | |
- "hello-world-gradle/**" | |
- "hello-world-war/**" | |
workflow_dispatch: | |
jobs: | |
build: | |
name: Build Maven Project | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: "17" | |
distribution: "temurin" | |
cache: "maven" | |
- name: Cache the Maven packages to speed up build | |
uses: actions/cache@v4 | |
with: | |
path: ~/.m2/repository | |
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
restore-keys: | | |
${{ runner.os }}-maven- | |
- name: Build and test project with Maven | |
run: | | |
cd hello-world-maven/ | |
mvn -B package --file pom.xml | |
release-jar: | |
if: github.event_name == 'push' && github.event.ref == 'refs/heads/master' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.ACCESS_TOKEN }} | |
- run: git fetch --prune --unshallow | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: "17" | |
distribution: "temurin" | |
cache: "maven" | |
- name: Set up Git | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git config advice.addIgnoredFile false | |
- name: Get the last tag | |
id: last_tag | |
run: | | |
cd hello-world-maven/ | |
LAST_TAG=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | |
echo "${LAST_TAG}" | |
echo "last_tag=${LAST_TAG}" >> $GITHUB_OUTPUT | |
- name: Determine bump type | |
id: bump_type | |
run: | | |
COMMIT_MSG=$(git log -1 --pretty=format:%s) | |
BRANCH_NAME=${GITHUB_REF#refs/heads/} | |
if [[ "$COMMIT_MSG" == *"[major]"* ]]; then | |
echo "bump_type=major" >> $GITHUB_OUTPUT | |
elif [[ "$COMMIT_MSG" == *"[minor]"* ]]; then | |
echo "bump_type=minor" >> $GITHUB_OUTPUT | |
elif [[ "$COMMIT_MSG" == *"[patch]"* ]]; then | |
echo "bump_type=patch" >> $GITHUB_OUTPUT | |
elif [[ "$COMMIT_MSG" == *"[hotfix]"* ]] || [[ "$COMMIT_MSG" == *"[bugfix]"* ]]; then | |
echo "bump_type=patch" >> $GITHUB_OUTPUT | |
elif [[ "$BRANCH_NAME" == "feature/"* ]]; then | |
echo "bump_type=minor" >> $GITHUB_OUTPUT | |
elif [[ "$BRANCH_NAME" == "bugfix/"* ]] || [[ "$BRANCH_NAME" == "hotfix/"* ]]; then | |
echo "bump_type=patch" >> $GITHUB_OUTPUT | |
else | |
echo "bump_type=build" >> $GITHUB_OUTPUT | |
fi | |
- name: Calculate new version | |
id: new_version | |
run: | | |
LAST_TAG=${{ steps.last_tag.outputs.last_tag }} | |
echo "${LAST_TAG}" | |
IFS='.' read -ra PARTS <<< "$LAST_TAG" | |
MAJOR=${PARTS[0]} | |
MINOR=${PARTS[1]} | |
PATCH=${PARTS[2]} | |
BUILD=${PARTS[3]} | |
BUMP_TYPE=${{ steps.bump_type.outputs.bump_type }} | |
if [ "$BUMP_TYPE" == "major" ]; then | |
MAJOR=$((MAJOR + 1)) | |
MINOR=0 | |
PATCH=0 | |
BUILD=0 | |
elif [ "$BUMP_TYPE" == "minor" ]; then | |
MINOR=$((MINOR + 1)) | |
PATCH=0 | |
BUILD=0 | |
elif [ "$BUMP_TYPE" == "patch" ]; then | |
PATCH=$((PATCH + 1)) | |
BUILD=0 | |
else | |
BUILD=$((BUILD + 1)) | |
fi | |
NEW_VERSION="$MAJOR.$MINOR.$PATCH.$BUILD" | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT | |
- name: Update Version in Pom file | |
run: | | |
cd hello-world-maven/ | |
mvn -B versions:set -DnewVersion="${NEW_VERSION}" -DgenerateBackupPoms=false | |
- name: Build and test project with Maven | |
run: | | |
cd hello-world-maven/ | |
mvn -B package --file pom.xml | |
- name: List Pom Files | |
run: | | |
find . -maxdepth 3 -type f -name "pom.xml" > pom_files.txt | |
cat pom_files.txt | |
- name: Add and Commit Pom Files | |
run: | | |
while IFS= read -r file; do | |
git add "$file" | |
done < pom_files.txt | |
git commit -m "Update version in pom.xml files [skip ci]" | |
- name: Push Changes | |
run: | | |
# Use the PAT secret to authenticate the push | |
# git remote set-url origin "https://${{ secrets.ACCESS_TOKEN }}@github.com/${{ github.repository }}.git" | |
git push origin master # Replace with the name of your protected branch | |
- name: Tag and Create Release | |
run: | | |
NEW_VERSION=${{ steps.new_version.outputs.new_version }} | |
git tag -a "$NEW_VERSION" -m "Release v$NEW_VERSION" | |
git push origin $NEW_VERSION | |
- name: Merge changes from master to develop | |
run: | | |
# Authenticate using a GitHub token | |
#gh auth login --with-token ${{ secrets.ACCESS_TOKEN }} | |
# Ensure you're on the 'develop' branch | |
git checkout develop | |
# Fetch and merge the latest changes from the source branch | |
git pull origin master -X ours | |
# Push the merged changes to 'develop' | |
git push origin develop |