|
| 1 | +name: Release Project |
| 2 | + |
| 3 | +on: |
| 4 | + # Allows you to run this workflow manually from the Actions tab |
| 5 | + workflow_dispatch: |
| 6 | + |
| 7 | +# Sets permissions of the GITHUB_TOKEN to allow bump_version |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + pull-requests: write |
| 11 | + |
| 12 | +env: |
| 13 | + POM_PATH: ${{ github.workspace }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + # check: https://dev.to/shayki5/github-action-for-building-maven-project-with-docker-and-push-it-docker-hub-3c3k |
| 17 | + release: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 # Disable shallow clones for better analysis relevance |
| 25 | + |
| 26 | + - name: Bump jar version |
| 27 | + id: bump |
| 28 | + run: | |
| 29 | + # Commit the changes |
| 30 | + git config user.email "actions@github.com" |
| 31 | + git config user.name "GitHub Actions" |
| 32 | + |
| 33 | + OLD_VERSION=$(cd $POM_PATH && mvn help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 34 | + |
| 35 | + # Extracting major, minor, and build versions |
| 36 | + IFS='.' read -ra parts <<< "$OLD_VERSION" |
| 37 | + major="${parts[0]}" |
| 38 | + minor="${parts[1]}" |
| 39 | + build_version=$((parts[2] + 1)) |
| 40 | + |
| 41 | + NEW_VERSION="${major}.${minor}.${build_version}" |
| 42 | + echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV |
| 43 | + |
| 44 | + echo "Updating pom.xml at $POM_PATH from $OLD_VERSION to $NEW_VERSION" for the production branch |
| 45 | + git fetch |
| 46 | + git checkout production |
| 47 | + # Bump the version in the pom.xml file for the next release in production |
| 48 | + mvn -q versions:set -DnewVersion="${NEW_VERSION}" --file $POM_PATH/pom.xml |
| 49 | + git add $POM_PATH/pom.xml |
| 50 | + git commit -m "chore: bump jar version from $OLD_VERSION to $NEW_VERSION" |
| 51 | + git push origin HEAD:production |
| 52 | +
|
| 53 | + - name: Create Pull Request |
| 54 | + run: | |
| 55 | + NEW_VERSION=${{ env.NEW_VERSION }} |
| 56 | + git fetch |
| 57 | + git checkout -b bump-version-${NEW_VERSION}-SNAPSHOT |
| 58 | + mvn -q versions:set -DnewVersion="${NEW_VERSION}-SNAPSHOT" --file $POM_PATH/pom.xml |
| 59 | + git add $POM_PATH/pom.xml |
| 60 | + git commit -m "chore: bump jar version from $OLD_VERSION to $NEW_VERSION-SNAPSHOT" |
| 61 | + git push origin bump-version-${NEW_VERSION}-SNAPSHOT |
| 62 | + PR_URL=$(gh pr create --title "Bump version to $NEW_VERSION-SNAPSHOT" --body "" --base main ) |
| 63 | + gh pr review $PR_URL --approve -b "I'm **approving** this pull request because **it includes a version bump for the jar file**" |
| 64 | + gh pr merge --auto --merge "$PR_URL" |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
0 commit comments