Skip to content

Updating Github actions to simplify JDK setup #3

Updating Github actions to simplify JDK setup

Updating Github actions to simplify JDK setup #3

name: License Year Update
on:
push:
branches: [ master ]
paths:
- '.github/workflows/license_update.yml'
schedule:
# Run at 00:30 on the first of January every year
- cron: '30 0 1 1 *'
jobs:
update-license:
name: License Year 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: Cache local .m2
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up maven
uses: s4u/[email protected]
with:
checkout-fetch-depth: 0
java-distribution: 'temurin'
java-version: '23'
maven-version: '3.9.9'
- name: Update license year
run: |
# Get the current and previous year dynamically
CURRENT_YEAR=$(date +%Y)
PREVIOUS_YEAR=$((CURRENT_YEAR - 1))
# Find and replace '<free text> 2021-<previous_year>' with '<free text> 2021-<current_year>'
find . -type f -not -path './.git/*' -exec sed -i "s/\(2021-\)\(${PREVIOUS_YEAR}\)/\1${CURRENT_YEAR}/g" {} +
if [ -z "$(git status --porcelain)" ]; 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 -T 2C
- name: Commit changes
id: change_commit
if: env.has_changes == 'true'
run: |
git config user.name github-actions
git config user.email "[email protected]"
git add .
git commit -m 'Updating licence year'
- name: Push changes
if: env.has_changes == 'true'
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: master