diff --git a/.github/workflows/formatter.yml b/.github/workflows/formatter.yml new file mode 100644 index 0000000..955d0b6 --- /dev/null +++ b/.github/workflows/formatter.yml @@ -0,0 +1,46 @@ +name: Apply Spotless Formatting + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + format: + runs-on: ubuntu-latest + concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }} + cancel-in-progress: true + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref || github.ref_name }} + fetch-depth: 0 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + + - name: Apply Spotless formatting + run: mvn spotless:apply + + - name: Commit changes if any + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git add . + if ! git diff --quiet --staged; then + git commit -m "Apply Spotless formatting" + git pull --rebase origin ${{ github.head_ref || github.ref_name }} + git push origin HEAD:${{ github.head_ref || github.ref_name }} + else + echo "No formatting changes to commit." + fi