Merge pull request #52 from SelahattinSert/task/deploy-application-to… #11
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: Post-Merge Version Update | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
update-version: | |
runs-on: ubuntu-latest | |
if: github.actor != 'github-actions[bot]' | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set Up Java | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
cache: 'maven' | |
- name: Set new version | |
run: | | |
export REVISION_ID=$(git rev-parse --short HEAD) | |
export NEW_VERSION=$(date +%Y%m%d)-$REVISION_ID | |
echo "Setting version to $NEW_VERSION" | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
mvn versions:set -DnewVersion=$NEW_VERSION -DgenerateBackupPoms=false | |
mvn versions:commit | |
- name: Debug Git Changes | |
run: | | |
git status | |
git diff pom.xml | |
- name: Create new branch and commit changes | |
run: | | |
git config user.name "GitHub Actions Bot" | |
git config user.email "[email protected]" | |
git checkout -b update-version-${{ env.NEW_VERSION }} | |
git add pom.xml | |
if git status --porcelain | grep .; then | |
git commit -m "Update project version to ${{ env.NEW_VERSION }}" | |
else | |
echo "No changes to commit. Exiting." | |
exit 0 | |
fi | |
- name: Push changes to new branch | |
run: | | |
git push origin update-version-${{ env.NEW_VERSION }} | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
title: "Update project version to ${{ env.NEW_VERSION }}" | |
body: "Automated version update by GitHub Actions." | |
branch: update-version-${{ env.NEW_VERSION }} | |
base: main | |
- name: Enable Pull Request Automerge | |
if: steps.cpr.outputs.pull-request-number != '' | |
uses: peter-evans/enable-pull-request-automerge@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }} | |
merge-method: merge |