Fixing version updates Github action to not fail if there are no changes #13
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: Versions Update | |
on: | |
push: | |
branches: [ master ] | |
paths: | |
- '.github/workflows/version_update.yml' | |
schedule: | |
# Run once on the first of the month | |
- cron: '45 0 1 * *' | |
jobs: | |
update: | |
name: Versions Update | |
runs-on: ubuntu-latest | |
permissions: | |
actions: write | |
contents: write | |
security-events: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Checkout submodules | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
path: advent-of-code-inputs | |
repository: zodac/advent-of-code-inputs | |
token: ${{ secrets.SUBMODULE_ACCESS }} | |
- name: Set up JDK | |
uses: actions/setup-java@v4.2.1 | |
with: | |
distribution: 'temurin' | |
java-version: '23' | |
- name: Cache local .m2 | |
uses: actions/cache@v4.0.2 | |
with: | |
path: ~/.m2 | |
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
restore-keys: | | |
${{ runner.os }}-maven- | |
- name: Set up maven | |
uses: s4u/setup-maven-action@v1.14.0 | |
with: | |
java-distribution: 'temurin' | |
java-version: '23' | |
maven-version: '3.9.9' | |
- name: Update Maven project versions | |
run: | | |
mvn versions:update-properties | |
if git diff-index --quiet HEAD; then | |
echo "No changes to commit" | |
echo "has_changes=false" >> $GITHUB_ENV | |
else | |
echo "has_changes=true" >> $GITHUB_ENV | |
fi | |
- name: Run linters and unit/integration tests | |
id: application_tests | |
if: env.has_changes == 'true' | |
run: mvn clean install -Dall | |
- name: Commit changes | |
id: change_commit | |
if: env.has_changes == 'true' | |
run: | | |
git config user.name github-actions | |
git config user.email "actions@github.com" | |
git add . | |
git commit -m 'Updating versions' | |
- name: Push changes | |
if: env.has_changes == 'true' | |
uses: ad-m/github-push-action@v0.8.0 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: master |