Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
name: "Check Spotless Formatting"
name: format code
on:
push:
branches:
- main
- release/**
pull_request:

jobs:
check-formatting:
format-code:
name: Format Code
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
- name: Checkout
uses: actions/checkout@v2

- name: set up JDK 11
uses: actions/setup-java@v2
with:
Expand All @@ -28,5 +26,11 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-

- name: Check formatting with Spotless
run: make checkFormat
- name: Make format
run: make format

# actions/checkout fetches only a single commit in a detached HEAD state. Therefore
# we need to pass the current branch, otherwise we can't commit the changes.
# GITHUB_HEAD_REF is the name of the head branch. GitHub Actions only sets this for PRs.
- name: Commit Formatted Code
run: ./scripts/commit-formatted-code.sh $GITHUB_HEAD_REF
4 changes: 0 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ spotless {
}
}

tasks.named("build") {
dependsOn(":spotlessApply")
}

gradle.projectsEvaluated {
tasks.create("aggregateJavadocs", Javadoc::class.java) {
setDestinationDir(file("$buildDir/docs/javadoc"))
Expand Down
16 changes: 16 additions & 0 deletions scripts/commit-formatted-code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -euo pipefail

GITHUB_BRANCH="${1}"

if [[ $(git status) == *"nothing to commit"* ]]; then
echo "Nothing to commit. All code formatted correctly."
else
echo "Formatted some code. Going to push the changes."
git config --global user.name 'Sentry Github Bot'
git config --global user.email 'bot+github-bot@sentry.io'
git fetch
git checkout ${GITHUB_BRANCH}
git commit -am "Format code"
git push --set-upstream origin ${GITHUB_BRANCH}
fi