Skip to content

Commit cba5af0

Browse files
authored
Format GitHub action (#1488)
* Add Spotless Maven plugin * Add Format workflow
1 parent ac69394 commit cba5af0

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

.github/workflows/format.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Java Code Format
2+
3+
on:
4+
push:
5+
branches:
6+
- 'sdk-automation/models'
7+
8+
jobs:
9+
format:
10+
if: ${{ github.event.commits != null && !startsWith(github.event.head_commit.message, 'style(fmt)') }}
11+
permissions:
12+
contents: write
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
token: ${{ secrets.ADYEN_AUTOMATION_BOT_ACCESS_TOKEN }}
19+
20+
- name: Set up JDK
21+
uses: actions/setup-java@v4
22+
with:
23+
java-version: '20'
24+
distribution: 'adopt'
25+
26+
- name: Cache Maven packages
27+
uses: actions/cache@v3
28+
with:
29+
path: ~/.m2
30+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
31+
restore-keys: |
32+
${{ runner.os }}-m2-
33+
34+
- name: Run Spotless Apply
35+
run: mvn spotless:apply
36+
37+
- name: Commit and Push Changes
38+
run: |
39+
git config user.name AdyenAutomationBot
40+
git config user.email "${{ secrets.ADYEN_AUTOMATION_BOT_EMAIL }}"
41+
git add .
42+
if git diff --cached --quiet; then
43+
echo "No changes to commit."
44+
else
45+
git commit -m "style(fmt): code formatted"
46+
git push
47+
fi

checkstyle.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@
133133
<module name="ParenPad"/>
134134
<module name="TypecastParenPad"/>
135135
<module name="WhitespaceAfter"/>
136+
<!-- disable rule to align with Spotless formatting
136137
<module name="WhitespaceAround"/>
138+
-->
137139

138140
<!-- Modifier Checks -->
139141
<!-- See http://checkstyle.sf.net/config_modifiers.html -->

pom.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,37 @@
191191
</instructions>
192192
</configuration>
193193
</plugin>
194+
<!-- Format code -->
195+
<plugin>
196+
<groupId>com.diffplug.spotless</groupId>
197+
<artifactId>spotless-maven-plugin</artifactId>
198+
<version>2.44.4</version>
199+
<executions>
200+
<execution>
201+
<goals>
202+
<goal>apply</goal>
203+
</goals>
204+
</execution>
205+
</executions>
206+
<configuration>
207+
<java>
208+
<includes>
209+
<include>src/main/java/**/*.java</include>
210+
<include>src/test/java/**/*.java</include>
211+
</includes>
212+
<googleJavaFormat>
213+
<version>1.19.2</version>
214+
<style>GOOGLE</style>
215+
<formatJavadoc>true</formatJavadoc>
216+
</googleJavaFormat>
217+
<importOrder /> <!-- standard import order -->
218+
<removeUnusedImports>
219+
<engine>google-java-format</engine>
220+
</removeUnusedImports>
221+
</java>
222+
</configuration>
223+
</plugin>
224+
194225
</plugins>
195226
</build>
196227
<dependencies>

0 commit comments

Comments
 (0)