| 
 | 1 | +name: Auto spotless apply  | 
 | 2 | +on:  | 
 | 3 | +  workflow_run:  | 
 | 4 | +    workflows:  | 
 | 5 | +      - "Auto spotless check"  | 
 | 6 | +    types:  | 
 | 7 | +      - completed  | 
 | 8 | + | 
 | 9 | +permissions:  | 
 | 10 | +  contents: read  | 
 | 11 | + | 
 | 12 | +jobs:  | 
 | 13 | +  apply:  | 
 | 14 | +    runs-on: ubuntu-latest  | 
 | 15 | +    permissions:  | 
 | 16 | +      contents: write  | 
 | 17 | +      pull-requests: write  | 
 | 18 | +    steps:  | 
 | 19 | +      - name: Download patch  | 
 | 20 | + | 
 | 21 | +        with:  | 
 | 22 | +          run-id: ${{ github.event.workflow_run.id }}  | 
 | 23 | +          path: ${{ runner.temp }}  | 
 | 24 | +          merge-multiple: true  | 
 | 25 | +          github-token: ${{ github.token }}  | 
 | 26 | + | 
 | 27 | +      - id: unzip-patch  | 
 | 28 | +        name: Unzip patch  | 
 | 29 | +        working-directory: ${{ runner.temp }}  | 
 | 30 | +        run: |  | 
 | 31 | +          if [ -f patch ]; then  | 
 | 32 | +            echo "exists=true" >> $GITHUB_OUTPUT  | 
 | 33 | +          fi  | 
 | 34 | +
  | 
 | 35 | +      - uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6  | 
 | 36 | +        if: steps.unzip-patch.outputs.exists == 'true'  | 
 | 37 | +        id: otelbot-token  | 
 | 38 | +        with:  | 
 | 39 | +          app-id: 1296620  | 
 | 40 | +          private-key: ${{ secrets.OTELBOT_JAVA_CONTRIB_PRIVATE_KEY }}  | 
 | 41 | + | 
 | 42 | +      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2  | 
 | 43 | +        if: steps.unzip-patch.outputs.exists == 'true'  | 
 | 44 | +        with:  | 
 | 45 | +          token: ${{ steps.otelbot-token.outputs.token }}  | 
 | 46 | + | 
 | 47 | +      - id: get-pr  | 
 | 48 | +        if: steps.unzip-patch.outputs.exists == 'true'  | 
 | 49 | +        name: Get PR  | 
 | 50 | +        env:  | 
 | 51 | +          PR_BRANCH: |-  | 
 | 52 | +            ${{  | 
 | 53 | +              (github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login)  | 
 | 54 | +                && format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)  | 
 | 55 | +                || github.event.workflow_run.head_branch  | 
 | 56 | +            }}  | 
 | 57 | +          GH_TOKEN: ${{ github.token }}  | 
 | 58 | +        run: |  | 
 | 59 | +          echo gh pr view "${PR_BRANCH}" --json number --jq .number  | 
 | 60 | +          number=$(gh pr view "${PR_BRANCH}" --json number --jq .number)  | 
 | 61 | +          echo $number  | 
 | 62 | +          echo "number=$number" >> $GITHUB_OUTPUT  | 
 | 63 | +
  | 
 | 64 | +      - name: Check out PR branch  | 
 | 65 | +        if: steps.unzip-patch.outputs.exists == 'true'  | 
 | 66 | +        env:  | 
 | 67 | +          GH_TOKEN: ${{ github.token }}  | 
 | 68 | +        run: gh pr checkout ${{ steps.get-pr.outputs.number }}  | 
 | 69 | + | 
 | 70 | +      - name: Use CLA approved github bot  | 
 | 71 | +        if: steps.unzip-patch.outputs.exists == 'true'  | 
 | 72 | +        # IMPORTANT do not call the .github/scripts/use-cla-approved-bot.sh  | 
 | 73 | +        # since that script could have been compromised in the PR branch  | 
 | 74 | +        run: |  | 
 | 75 | +          git config user.name otelbot  | 
 | 76 | +          git config user.email [email protected]  | 
 | 77 | +
  | 
 | 78 | +      - name: Apply patch and push  | 
 | 79 | +        if: steps.unzip-patch.outputs.exists == 'true'  | 
 | 80 | +        run: |  | 
 | 81 | +          git apply "${{ runner.temp }}/patch"  | 
 | 82 | +          git commit -a -m "./gradlew spotlessApply"  | 
 | 83 | +          git push  | 
 | 84 | +
  | 
 | 85 | +      - if: steps.unzip-patch.outputs.exists == 'true' && success()  | 
 | 86 | +        env:  | 
 | 87 | +          GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}  | 
 | 88 | +        run: |  | 
 | 89 | +          gh pr comment ${{ steps.get-pr.outputs.number }} --body "🔧 The result from spotlessApply was committed to the PR branch."  | 
 | 90 | +
  | 
 | 91 | +      - if: steps.unzip-patch.outputs.exists == 'true' && failure()  | 
 | 92 | +        env:  | 
 | 93 | +          GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}  | 
 | 94 | +        run: |  | 
 | 95 | +          gh pr comment ${{ steps.get-pr.outputs.number }} --body "❌ The result from spotlessApply could not be committed to the PR branch, see logs: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID."  | 
0 commit comments