Skip to content

Commit 896fc78

Browse files
Merge pull request #89 from nihaltp/feature/stylingBot
Add GitHub Actions workflow for Spotless formatting
2 parents 0f5fb4f + 568cafb commit 896fc78

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

.github/workflows/formatter.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
16+
cancel-in-progress: true
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
ref: ${{ github.head_ref || github.ref_name }}
23+
fetch-depth: 0
24+
25+
- name: Set up JDK 17
26+
uses: actions/setup-java@v4
27+
with:
28+
java-version: '17'
29+
distribution: 'temurin'
30+
cache: maven
31+
32+
- name: Apply Spotless formatting
33+
run: mvn spotless:apply
34+
35+
- name: Commit changes if any
36+
run: |
37+
git config --global user.name "github-actions[bot]"
38+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
39+
git add .
40+
if ! git diff --quiet --staged; then
41+
git commit -m "Apply Spotless formatting"
42+
git pull --rebase origin ${{ github.head_ref || github.ref_name }}
43+
git push origin HEAD:${{ github.head_ref || github.ref_name }}
44+
else
45+
echo "No formatting changes to commit."
46+
fi

0 commit comments

Comments
 (0)