diff --git a/.github/workflows/spotless-check.yml b/.github/workflows/spotless-check.yml new file mode 100644 index 00000000..4b8bf666 --- /dev/null +++ b/.github/workflows/spotless-check.yml @@ -0,0 +1,44 @@ +name: Spotless Check + +on: [pull_request] + +jobs: + spotless: + runs-on: ubuntu-latest + + steps: + - name: Harden Runner + uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0 + with: + egress-policy: audit + + - name: Checkout code + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + + - name: Set up JDK 21 + uses: actions/setup-java@d62f12622c1c8c47f24e7d3b71611062a1e56a13 # v3.13.0 + with: + distribution: 'temurin' + java-version: '21' + + - name: Cache Gradle packages + uses: actions/cache@b6e12325fcdfbd3b3d3e192ae02d9bcd3c9b37c5 # v2.1.8 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Run Spotless Check + run: ./gradlew spotlessCheck + + - name: Run Spotless Apply and Check for Changes + id: check_spotless + run: | + ./gradlew spotlessApply + if ! git diff --exit-code; then + echo "Spotless found formatting issues. Please run './gradlew spotlessApply' to fix them." + exit 1 + fi