@@ -16,93 +16,80 @@ jobs:
1616      contents : write 
1717      pull-requests : write 
1818    steps :
19-       - id : download-patch 
20-         name : Download patch 
21- 19+       - name : Download patch 
20+ 2221        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"); 
22+           run-id : ${{ github.event.workflow_run.id }} 
23+           name : patch 
24+           path : ${{ runner.temp }} 
25+           github-token : ${{ github.token }} 
26+ 
27+       - id : unzip-patch 
28+         name : Unzip patch 
29+         working-directory : ${{ runner.temp }} 
30+         run : | 
31+           echo ================= 
32+           ls 
33+           echo ================= 
34+           if [ -f patch.zip ]; then 
35+             unzip patch.zip 
36+             echo "exists=true" >> $GITHUB_OUTPUT 
37+           fi 
5238
5339id : get-pr-number 
40+         if : steps.unzip-patch.outputs.exists == 'true' 
5441        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 
42+         env : 
43+            PR_BRANCH :  |- 
44+             ${{  
45+               (github.event.workflow_run.head_repository.owner.login !=  github.event. workflow_run.repository.owner.login)  
46+                 && format('{0}:{1} ', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)  
47+                 || github.event.workflow_run.head_branch 
48+             }}  
49+    GH_TOKEN :  ${{ github.token }} 
50+         run :  | 
51+           gh pr view "${PR_BRANCH}" --json 'number' --jq '"pr-number=\(.number)' >> $GITHUB_OUTPUT  
6552
6653uses : actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e  #  v2.0.6
67-         if : steps.download -patch.outputs.exists == 'true' 
54+         if : steps.unzip -patch.outputs.exists == 'true' 
6855        id : otelbot-token 
6956        with :
7057          app-id : 1295839 
71-           private-key : ${{ secrets.OTELBOT_JAVA_CONTRIB_PRIVATE_KEY  }} 
58+           private-key : ${{ secrets.OTELBOT_JAVA_INSTRUMENTATION_PRIVATE_KEY  }} 
7259
7360      - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683  #  v4.2.2
74-         if : steps.download -patch.outputs.exists == 'true' 
61+         if : steps.unzip -patch.outputs.exists == 'true' 
7562        with :
7663          token : ${{ steps.otelbot-token.outputs.token }} 
7764
7865      - name : Check out PR branch 
79-         if : steps.download -patch.outputs.exists == 'true' 
66+         if : steps.unzip -patch.outputs.exists == 'true' 
8067        env :
8168          GH_TOKEN : ${{ github.token }} 
8269        run : gh pr checkout ${{ steps.get-pr-number.outputs.pr-number }} 
8370
8471      - name : Use CLA approved github bot 
85-         if : steps.download -patch.outputs.exists == 'true' 
72+         if : steps.unzip -patch.outputs.exists == 'true' 
8673        #  IMPORTANT do not call the .github/scripts/use-cla-approved-bot.sh
8774        #  since that script could have been compromised in the PR branch
8875        run : | 
8976          git config user.name otelbot 
9077          git config user.email [email protected]  9178
9279name : Apply patch and push 
93-         if : steps.download -patch.outputs.exists == 'true' 
80+         if : steps.unzip -patch.outputs.exists == 'true' 
9481        run : | 
95-           git apply "${{ runner.temp }}/artifacts/ patch" 
82+           git apply "${{ runner.temp }}/patch" 
9683          git commit -a -m "./gradlew spotlessApply" 
9784          git push 
9885
99- if : steps.download -patch.outputs.exists == 'true' && success() 
86+ if : steps.unzip -patch.outputs.exists == 'true' && success() 
10087        env :
10188          GH_TOKEN : ${{ steps.otelbot-token.outputs.token }} 
10289        run : | 
10390          gh pr comment ${{ steps.get-pr-number.outputs.pr-number }} --body "🔧 The result from spotlessApply was committed to the PR branch." 
10491
105- if : steps.download -patch.outputs.exists == 'true' && failure() 
92+ if : steps.unzip -patch.outputs.exists == 'true' && failure() 
10693        env :
10794          GH_TOKEN : ${{ steps.otelbot-token.outputs.token }} 
10895        run : | 
0 commit comments