@@ -13,96 +13,81 @@ jobs:
1313  apply :
1414    runs-on : ubuntu-latest 
1515    permissions :
16+       actions : read  #  needed to download artifact from the other workflow
1617      contents : write 
1718      pull-requests : write 
1819    steps :
19-       - id : download-patch 
20-         name : Download patch 
21- 20+       - name : Download patch 
21+ 2222        with :
23-           #  this script copied from
24-           #  https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#using-data-from-the-triggering-workflow
25-           script : | 
26-             let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ 
27-                owner: context.repo.owner, 
28-                repo: context.repo.repo, 
29-                run_id: context.payload.workflow_run.id 
30-             }); 
31-             let patchArtifact = allArtifacts.data.artifacts.filter((artifact) => { 
32-               return artifact.name == "patch" 
33-             })[0]; 
34-             if (!patchArtifact) { 
35-               core.info('No patch to apply.'); 
36-               return; 
37-             } 
38-             let download = await github.rest.actions.downloadArtifact({ 
39-                owner: context.repo.owner, 
40-                repo: context.repo.repo, 
41-                artifact_id: patchArtifact.id, 
42-                archive_format: 'zip' 
43-             }); 
44-             const fs = require('fs'); 
45-             const path = require('path'); 
46-             const temp = '${{ runner.temp }}/artifacts'; 
47-             if (!fs.existsSync(temp)){ 
48-               fs.mkdirSync(temp); 
49-             } 
50-             fs.writeFileSync(path.join(temp, 'patch.zip'), Buffer.from(download.data)); 
51-             core.setOutput("exists", "true"); 
23+           run-id : ${{ github.event.workflow_run.id }} 
24+           name : patch 
25+           path : ${{ runner.temp }} 
26+           github-token : ${{ github.token }} 
27+ 
28+       - id : unzip-patch 
29+         name : Unzip patch 
30+         working-directory : ${{ runner.temp }} 
31+         run : | 
32+           if [ -f patch.zip ]; then 
33+             unzip patch.zip 
34+             echo "exists=true" >> $GITHUB_OUTPUT 
35+           fi 
5236
5337id : get-pr-number 
38+         if : steps.unzip-patch.outputs.exists == 'true' 
5439        name : Get PR number 
55- 56-         with : 
57-           script :  | 
58-             const response = await  github.request(context.payload. workflow_run.url);  
59-             core.setOutput('pr-number ', response.data.pull_requests[0].number);  
60- 
61- -  name :  Unzip patch 
62-         if :  steps.download-patch.outputs.exists == 'true' 
63-         working-directory :  ${{ runner.temp }}/artifacts 
64-         run :  unzip patch.zip 
40+         env : 
41+            PR_BRANCH :  |- 
42+             ${{  
43+               (github.event.workflow_run.head_repository.owner.login !=  github.event. workflow_run.repository.owner.login)  
44+                 && format('{0}:{1} ', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)  
45+                 || github.event.workflow_run.head_branch 
46+             }}  
47+    GH_TOKEN :  ${{ github.token }} 
48+         run :  | 
49+           gh pr view "${PR_BRANCH}" --json 'number' --jq '"pr-number=\(.number)' >> $GITHUB_OUTPUT  
6550
6651uses : actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e  #  v2.0.6
67-         if : steps.download -patch.outputs.exists == 'true' 
52+         if : steps.unzip -patch.outputs.exists == 'true' 
6853        id : otelbot-token 
6954        with :
7055          app-id : 1295839 
71-           private-key : ${{ secrets.OTELBOT_JAVA_CONTRIB_PRIVATE_KEY  }} 
56+           private-key : ${{ secrets.OTELBOT_JAVA_INSTRUMENTATION_PRIVATE_KEY  }} 
7257
7358      - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683  #  v4.2.2
74-         if : steps.download -patch.outputs.exists == 'true' 
59+         if : steps.unzip -patch.outputs.exists == 'true' 
7560        with :
7661          token : ${{ steps.otelbot-token.outputs.token }} 
7762
7863      - name : Check out PR branch 
79-         if : steps.download -patch.outputs.exists == 'true' 
64+         if : steps.unzip -patch.outputs.exists == 'true' 
8065        env :
8166          GH_TOKEN : ${{ github.token }} 
8267        run : gh pr checkout ${{ steps.get-pr-number.outputs.pr-number }} 
8368
8469      - name : Use CLA approved github bot 
85-         if : steps.download -patch.outputs.exists == 'true' 
70+         if : steps.unzip -patch.outputs.exists == 'true' 
8671        #  IMPORTANT do not call the .github/scripts/use-cla-approved-bot.sh
8772        #  since that script could have been compromised in the PR branch
8873        run : | 
8974          git config user.name otelbot 
9075          git config user.email [email protected]  9176
9277name : Apply patch and push 
93-         if : steps.download -patch.outputs.exists == 'true' 
78+         if : steps.unzip -patch.outputs.exists == 'true' 
9479        run : | 
95-           git apply "${{ runner.temp }}/artifacts/ patch" 
80+           git apply "${{ runner.temp }}/patch" 
9681          git commit -a -m "./gradlew spotlessApply" 
9782          git push 
9883
99- if : steps.download -patch.outputs.exists == 'true' && success() 
84+ if : steps.unzip -patch.outputs.exists == 'true' && success() 
10085        env :
10186          GH_TOKEN : ${{ steps.otelbot-token.outputs.token }} 
10287        run : | 
10388          gh pr comment ${{ steps.get-pr-number.outputs.pr-number }} --body "🔧 The result from spotlessApply was committed to the PR branch." 
10489
105- if : steps.download -patch.outputs.exists == 'true' && failure() 
90+ if : steps.unzip -patch.outputs.exists == 'true' && failure() 
10691        env :
10792          GH_TOKEN : ${{ steps.otelbot-token.outputs.token }} 
10893        run : | 
0 commit comments