Skip to content

Commit 1ed1eaa

Browse files
committed
Add auto-format CI step
1 parent 22cb85f commit 1ed1eaa

2 files changed

Lines changed: 68 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,72 @@ on:
99
permissions:
1010
pull-requests: write
1111

12+
concurrency:
13+
group: ci-${{ github.event.pull_request.number || github.ref }}
14+
cancel-in-progress: true
15+
1216
jobs:
17+
format:
18+
runs-on: ubuntu-latest
19+
name: Auto-format
20+
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
21+
steps:
22+
- uses: actions/checkout@v6
23+
with:
24+
ref: ${{ github.head_ref }}
25+
token: ${{ secrets.PR_TOKEN }}
26+
27+
- name: Check if last commit is from bot
28+
id: check-bot
29+
run: |
30+
LAST_AUTHOR=$(git log -1 --format='%an')
31+
if [ "$LAST_AUTHOR" = "github-actions[bot]" ]; then
32+
echo "skip=true" >> "$GITHUB_OUTPUT"
33+
else
34+
echo "skip=false" >> "$GITHUB_OUTPUT"
35+
fi
36+
37+
- name: Set up JDK 21
38+
if: steps.check-bot.outputs.skip != 'true'
39+
uses: actions/setup-java@v5
40+
with:
41+
java-version: 21
42+
distribution: 'corretto'
43+
44+
- name: Cache compiled buildscripts
45+
if: steps.check-bot.outputs.skip != 'true'
46+
uses: actions/cache@v5
47+
with:
48+
key: ${{ runner.os }}-gradle-${{ hashFiles('buildSrc/**/*.kts') }}
49+
path: |
50+
./buildSrc/build
51+
52+
- name: Setup Gradle
53+
if: steps.check-bot.outputs.skip != 'true'
54+
uses: gradle/actions/setup-gradle@v6
55+
with:
56+
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
57+
gradle-home-cache-includes: |
58+
caches
59+
60+
- name: Run spotlessApply
61+
if: steps.check-bot.outputs.skip != 'true'
62+
run: ./gradlew spotlessApply
63+
64+
- name: Commit formatting changes
65+
if: steps.check-bot.outputs.skip != 'true'
66+
run: |
67+
if [ -n "$(git status --porcelain)" ]; then
68+
git config user.name "github-actions[bot]"
69+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
70+
git add -A
71+
git commit -m "Auto-format: apply spotless formatting"
72+
git push
73+
fi
74+
1375
build:
76+
needs: [format]
77+
if: always() && !cancelled()
1478
runs-on: ${{ matrix.os }}
1579
name: Java ${{ matrix.java }} ${{ matrix.os }}
1680
strategy:

core/src/main/java/software/amazon/smithy/java/core/Version.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public final class Version {
2626

2727
static String getVersion() {
2828
try (InputStream is = Objects.requireNonNull(Version.class.getResourceAsStream(VERSION_RESOURCE_FILE))) {
29-
var properties = new Properties();
30-
properties.load(is);
31-
return properties.get(VERSION_PROPERTY).toString();
29+
var properties = new Properties();
30+
properties.load(is);
31+
return properties.get(VERSION_PROPERTY).toString();
3232
} catch (IOException e) {
33-
throw new UncheckedIOException(e);
33+
throw new UncheckedIOException(e);
3434
}
3535
}
3636

0 commit comments

Comments
 (0)