Skip to content

Manual Build

Manual Build #5

Workflow file for this run

name: Build Jar Manually
on:
workflow_dispatch: # Allows manual trigger from the GitHub UI
jobs:
build:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code
- name: Checkout repository
uses: actions/checkout@v3
# Step 2: Set up Java 17 (or your target version)
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin' # or 'zulu', 'adopt', etc.
# Step 3: Get the current version from the pom.xml
- name: Get current version from pom.xml
id: get_version
run: |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "Current version is: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
# Step 4: Increment the version (patch version bump)
- name: Increment version
id: increment_version
run: |
# Increment the patch version
VERSION=$(echo ${{ env.VERSION }} | awk -F. '{$NF+=1; OFS="."; print}')
echo "New version is: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
# Update the version in the pom.xml
mvn versions:set -DnewVersion=${{ env.VERSION }} -DgenerateBackupPoms=false
# Step 5: Verify if the version change has been applied to pom.xml
- name: Check for version change in pom.xml
run: |
git status
git diff
# Step 6: Build the .jar file
- name: Build jar file
run: mvn clean package
# Step 7: Upload the built .jar file as an artifact
- name: Upload .jar artifact
uses: actions/upload-artifact@v3
with:
name: built-jar
path: target/*.jar
# Step 8: Commit the updated pom.xml with the new version (only if there are changes)
- name: Commit new version
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add pom.xml
git commit -m "Bump version to ${{ env.VERSION }}" || echo "No changes to commit"
# Step 9: Push the commit and the new version tag to the repository
- name: Create Git Tag and push
run: |
TAG_NAME="v${{ env.VERSION }}"
git tag -a "$TAG_NAME" -m "Release $TAG_NAME"
git push origin master
git push origin "$TAG_NAME"