11name : Auto spotless
22on :
3- pull_request_target :
3+ workflow_run :
4+ workflows :
5+ - " Auto spotless, part 1"
46 types :
5- - opened
6- - synchronize
7+ - completed
78
89concurrency :
910 group : ${{ github.workflow }}-${{ github.event.pull_request.number }}
@@ -13,45 +14,6 @@ permissions:
1314 contents : read
1415
1516jobs :
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 : Check out PR branch
33- env :
34- GH_TOKEN : ${{ github.token }}
35- run : gh pr checkout ${{ github.event.pull_request.number }}
36-
37- - name : Spotless
38- run : ./gradlew spotlessApply
39-
40- - id : create-patch-file
41- name : Create patch file
42- run : |
43- git diff > patch
44- if [ -s patch ]; then
45- echo "nonempty=true" >> "$GITHUB_OUTPUT"
46- fi
47-
48- - name : Upload patch file
49- if : steps.create-patch-file.outputs.nonempty == 'true'
50- uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
51- with :
52- path : patch
53- name : patch
54-
5517 apply :
5618 runs-on : ubuntu-latest
5719 needs : check
@@ -60,18 +22,44 @@ jobs:
6022 contents : write
6123 pull-requests : write
6224 steps :
25+ - name : Download patch
26+ 27+ with :
28+ # this script copied from
29+ # https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#using-data-from-the-triggering-workflow
30+ script : |
31+ let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
32+ owner: context.repo.owner,
33+ repo: context.repo.repo,
34+ run_id: context.payload.workflow_run.id
35+ });
36+ let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
37+ return artifact.name == "patch"
38+ })[0];
39+ let download = await github.rest.actions.downloadArtifact({
40+ owner: context.repo.owner,
41+ repo: context.repo.repo,
42+ artifact_id: matchArtifact.id,
43+ archive_format: 'zip'
44+ });
45+ const fs = require('fs');
46+ const path = require('path');
47+ const temp = '${{ runner.temp }}/artifacts';
48+ if (!fs.existsSync(temp)){
49+ fs.mkdirSync(temp);
50+ }
51+ fs.writeFileSync(path.join(temp, 'patch.zip'), Buffer.from(download.data));
52+
53+ - name : Unzip patch
54+ run : unzip patch.zip -d "${{ runner.temp }}/artifacts"
55+
6356 - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
6457
6558 - name : Check out PR branch
6659 env :
6760 GH_TOKEN : ${{ github.token }}
6861 run : gh pr checkout ${{ github.event.pull_request.number }}
6962
70- - name : Download patch
71- uses : actions/download-artifact@v4
72- with :
73- name : patch
74-
7563 - name : Use CLA approved github bot
7664 # IMPORTANT do not call the .github/scripts/use-cla-approved-bot.sh
7765 # since that script could have been compromised in the PR branch
8977 env :
9078 GH_TOKEN : ${{ steps.otelbot-token.outputs.token }}
9179 run : |
92- git apply patch
80+ git apply "${{ runner.temp }}/artifacts/ patch"
9381 git commit -a -m "./gradlew spotlessApply"
9482 git push
9583
0 commit comments