Skip to content

Commit e0fb155

Browse files
committed
Add GitHub Actions workflow for Spotless formatting
this will automatically apply formatting using `mvn spotless:apply`
1 parent 0f5fb4f commit e0fb155

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

.github/workflows/formatter.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Apply Spotless Formatting
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
format:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
ref: ${{ github.head_ref || github.ref_name }}
20+
fetch-depth: 0
21+
22+
- name: Set up JDK 17
23+
uses: actions/setup-java@v4
24+
with:
25+
java-version: '17'
26+
distribution: 'temurin'
27+
cache: maven
28+
29+
- name: Apply Spotless formatting
30+
run: mvn spotless:apply
31+
32+
- name: Commit changes if any
33+
run: |
34+
git config --global user.name "github-actions[bot]"
35+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
36+
git add .
37+
if ! git diff --quiet --staged; then
38+
git commit -m "Apply Spotless formatting"
39+
git pull --rebase origin ${{ github.head_ref }}
40+
git push origin HEAD:${{ github.head_ref }}
41+
else
42+
echo "No formatting changes to commit."
43+
fi

0 commit comments

Comments
 (0)