Skip to content

Commit 75c9d8d

Browse files
committed
Fix auto spotless
1 parent f704bf6 commit 75c9d8d

File tree

1 file changed

+30
-49
lines changed

1 file changed

+30
-49
lines changed

.github/workflows/auto-spotless-apply.yml

Lines changed: 30 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,93 +16,74 @@ jobs:
1616
contents: write
1717
pull-requests: write
1818
steps:
19-
- id: download-patch
20-
name: Download patch
21-
uses: actions/[email protected]
19+
- name: Download patch
20+
uses: actions/[email protected]
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+
path: ${{ runner.temp }}/artifacts
24+
25+
- id: unzip-patch
26+
name: Unzip patch
27+
working-directory: ${{ runner.temp }}/artifacts
28+
run: |
29+
if [ -f patch.zip ]; then
30+
unzip patch.zip
31+
echo "exists=true" >> $GITHUB_OUTPUT
32+
fi
5233
5334
- id: get-pr-number
35+
if: steps.unzip-patch.outputs.exists == 'true'
5436
name: Get PR number
55-
uses: actions/[email protected]
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
37+
env:
38+
PR_BRANCH: |-
39+
${{
40+
(github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login)
41+
&& format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)
42+
|| github.event.workflow_run.head_branch
43+
}}
44+
run: |
45+
gh pr view "${PR_BRANCH}" --json 'number' --jq '"pr-number=\(.number)' >> $GITHUB_OUTPUT
6546
6647
- uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
67-
if: steps.download-patch.outputs.exists == 'true'
48+
if: steps.unzip-patch.outputs.exists == 'true'
6849
id: otelbot-token
6950
with:
7051
app-id: 1295839
7152
private-key: ${{ secrets.OTELBOT_JAVA_INSTRUMENTATION_PRIVATE_KEY }}
7253

7354
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
74-
if: steps.download-patch.outputs.exists == 'true'
55+
if: steps.unzip-patch.outputs.exists == 'true'
7556
with:
7657
token: ${{ steps.otelbot-token.outputs.token }}
7758

7859
- name: Check out PR branch
79-
if: steps.download-patch.outputs.exists == 'true'
60+
if: steps.unzip-patch.outputs.exists == 'true'
8061
env:
8162
GH_TOKEN: ${{ github.token }}
8263
run: gh pr checkout ${{ steps.get-pr-number.outputs.pr-number }}
8364

8465
- name: Use CLA approved github bot
85-
if: steps.download-patch.outputs.exists == 'true'
66+
if: steps.unzip-patch.outputs.exists == 'true'
8667
# IMPORTANT do not call the .github/scripts/use-cla-approved-bot.sh
8768
# since that script could have been compromised in the PR branch
8869
run: |
8970
git config user.name otelbot
9071
git config user.email [email protected]
9172
9273
- name: Apply patch and push
93-
if: steps.download-patch.outputs.exists == 'true'
74+
if: steps.unzip-patch.outputs.exists == 'true'
9475
run: |
9576
git apply "${{ runner.temp }}/artifacts/patch"
9677
git commit -a -m "./gradlew spotlessApply"
9778
git push
9879
99-
- if: steps.download-patch.outputs.exists == 'true' && success()
80+
- if: steps.unzip-patch.outputs.exists == 'true' && success()
10081
env:
10182
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
10283
run: |
10384
gh pr comment ${{ steps.get-pr-number.outputs.pr-number }} --body "🔧 The result from spotlessApply was committed to the PR branch."
10485
105-
- if: steps.download-patch.outputs.exists == 'true' && failure()
86+
- if: steps.unzip-patch.outputs.exists == 'true' && failure()
10687
env:
10788
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
10889
run: |

0 commit comments

Comments
 (0)