|
| 1 | +name: Auto spotless |
| 2 | +on: |
| 3 | + pull_request_target: |
| 4 | + types: |
| 5 | + - opened |
| 6 | + - synchronize |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + |
| 15 | +jobs: |
| 16 | + check: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + patch-created: ${{ steps.create-patch-file.outputs.nonempty }} |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 22 | + |
| 23 | + - name: Free disk space |
| 24 | + run: .github/scripts/gha-free-disk-space.sh |
| 25 | + |
| 26 | + - name: Set up JDK for running Gradle |
| 27 | + uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1 |
| 28 | + with: |
| 29 | + distribution: temurin |
| 30 | + java-version-file: .java-version |
| 31 | + |
| 32 | + - name: Setup Gradle |
| 33 | + uses: gradle/actions/setup-gradle@06832c7b30a0129d7fb559bcc6e43d26f6374244 # v4.3.1 |
| 34 | + with: |
| 35 | + cache-read-only: true |
| 36 | + |
| 37 | + - name: Check out PR branch |
| 38 | + env: |
| 39 | + GH_TOKEN: ${{ github.token }} |
| 40 | + run: gh pr checkout ${{ github.event.pull_request.number }} |
| 41 | + |
| 42 | + - name: Spotless |
| 43 | + run: ./gradlew spotlessApply |
| 44 | + |
| 45 | + - id: create-patch-file |
| 46 | + name: Create patch file |
| 47 | + run: | |
| 48 | + git diff > patch |
| 49 | + if [ -s patch ]; then |
| 50 | + echo "nonempty=true" >> "$GITHUB_OUTPUT" |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Upload patch file |
| 54 | + if: steps.create-patch-file.outputs.nonempty == 'true' |
| 55 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 56 | + with: |
| 57 | + path: patch |
| 58 | + name: patch |
| 59 | + |
| 60 | + apply: |
| 61 | + runs-on: ubuntu-latest |
| 62 | + needs: check |
| 63 | + if: needs.check.outputs.patch-created == 'true' |
| 64 | + permissions: |
| 65 | + contents: write |
| 66 | + pull-requests: write |
| 67 | + steps: |
| 68 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 69 | + |
| 70 | + - name: Check out PR branch |
| 71 | + env: |
| 72 | + GH_TOKEN: ${{ github.token }} |
| 73 | + run: gh pr checkout ${{ github.event.pull_request.number }} |
| 74 | + |
| 75 | + - name: Download patch |
| 76 | + uses: actions/download-artifact@v4 |
| 77 | + with: |
| 78 | + name: patch |
| 79 | + |
| 80 | + - name: Use CLA approved github bot |
| 81 | + # IMPORTANT do not call the .github/scripts/use-cla-approved-bot.sh |
| 82 | + # since that script could have been compromised in the PR branch |
| 83 | + run: | |
| 84 | + git config user.name otelbot |
| 85 | + git config user.email [email protected] |
| 86 | +
|
| 87 | + - uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6 |
| 88 | + id: otelbot-token |
| 89 | + with: |
| 90 | + app-id: ${{ vars.OTELBOT_APP_ID }} |
| 91 | + private-key: ${{ secrets.OTELBOT_PRIVATE_KEY }} |
| 92 | + |
| 93 | + - name: Apply patch and push |
| 94 | + env: |
| 95 | + GH_TOKEN: ${{ steps.otelbot-token.outputs.token }} |
| 96 | + run: | |
| 97 | + git apply patch |
| 98 | + git commit -a -m "./gradlew spotlessApply" |
| 99 | + git push |
| 100 | +
|
| 101 | + - if: success() |
| 102 | + env: |
| 103 | + GH_TOKEN: ${{ steps.otelbot-token.outputs.token }} |
| 104 | + run: | |
| 105 | + gh pr comment $PR_NUM --body "🔧 The result from \`./gradlew spotlessApply\` was committed to the PR branch." |
| 106 | +
|
| 107 | + - if: failure() |
| 108 | + env: |
| 109 | + GH_TOKEN: ${{ steps.otelbot-token.outputs.token }} |
| 110 | + run: | |
| 111 | + gh pr comment $PR_NUM --body "❌ The result from \`./gradlew spotlessApply\` could not be committed to the PR branch, see logs: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID." |
0 commit comments