Skip to content

Commit 80ec67d

Browse files
authored
auto format code (#1963)
1 parent 5036a47 commit 80ec67d

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
name: "Check Spotless Formatting"
1+
name: format code
22
on:
3-
push:
4-
branches:
5-
- main
6-
- release/**
73
pull_request:
84

95
jobs:
10-
check-formatting:
6+
format-code:
7+
name: Format Code
118
runs-on: ubuntu-latest
129
steps:
13-
- name: Checkout 🛎️
10+
- name: Checkout
1411
uses: actions/checkout@v2
12+
1513
- name: set up JDK 11
1614
uses: actions/setup-java@v2
1715
with:
@@ -28,5 +26,11 @@ jobs:
2826
restore-keys: |
2927
${{ runner.os }}-gradle-
3028
31-
- name: Check formatting with Spotless
32-
run: make checkFormat
29+
- name: Make format
30+
run: make format
31+
32+
# actions/checkout fetches only a single commit in a detached HEAD state. Therefore
33+
# we need to pass the current branch, otherwise we can't commit the changes.
34+
# GITHUB_HEAD_REF is the name of the head branch. GitHub Actions only sets this for PRs.
35+
- name: Commit Formatted Code
36+
run: ./scripts/commit-formatted-code.sh $GITHUB_HEAD_REF

build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,6 @@ spotless {
150150
}
151151
}
152152

153-
tasks.named("build") {
154-
dependsOn(":spotlessApply")
155-
}
156-
157153
gradle.projectsEvaluated {
158154
tasks.create("aggregateJavadocs", Javadoc::class.java) {
159155
setDestinationDir(file("$buildDir/docs/javadoc"))

scripts/commit-formatted-code.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
GITHUB_BRANCH="${1}"
5+
6+
if [[ $(git status) == *"nothing to commit"* ]]; then
7+
echo "Nothing to commit. All code formatted correctly."
8+
else
9+
echo "Formatted some code. Going to push the changes."
10+
git config --global user.name 'Sentry Github Bot'
11+
git config --global user.email 'bot+github-bot@sentry.io'
12+
git fetch
13+
git checkout ${GITHUB_BRANCH}
14+
git commit -am "Format code"
15+
git push --set-upstream origin ${GITHUB_BRANCH}
16+
fi

0 commit comments

Comments
 (0)