forked from open-telemetry/opentelemetry-java-contrib
-
Notifications
You must be signed in to change notification settings - Fork 1
84 lines (75 loc) · 3.17 KB
/
auto-spotless-apply.yml
File metadata and controls
84 lines (75 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Auto spotless apply
on:
workflow_run:
workflows:
- "Auto spotless check"
types:
- completed
permissions:
contents: read
jobs:
apply:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Download patch
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
run-id: ${{ github.event.workflow_run.id }}
path: ${{ runner.temp }}
merge-multiple: true
github-token: ${{ github.token }}
- id: unzip-patch
name: Unzip patch
working-directory: ${{ runner.temp }}
run: |
if [ -f patch ]; then
echo "exists=true" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
if: steps.unzip-patch.outputs.exists == 'true'
with:
repository: "${{ github.event.workflow_run.head_repository.full_name }}"
ref: "${{ github.event.workflow_run.head_branch }}"
token: ${{ github.token }}
- name: Use CLA approved github bot
if: steps.unzip-patch.outputs.exists == 'true'
# IMPORTANT do not call the .github/scripts/use-cla-approved-bot.sh
# since that script could have been compromised in the PR branch
run: |
git config user.name otelbot
git config user.email 197425009+otelbot@users.noreply.github.com
- name: Apply patch and push
if: steps.unzip-patch.outputs.exists == 'true'
run: |
git apply "${{ runner.temp }}/patch"
git commit -a -m "./gradlew spotlessApply"
# explicitly pushing to repo and branch handles edge case where the PR branch name is "<user>/main"
# due to the "main" branch already existing when "gh pr checkout" was run
git push
- id: get-pr
if: steps.unzip-patch.outputs.exists == 'true'
name: Get PR
env:
PR_BRANCH: |-
${{
(github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login)
&& format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)
|| github.event.workflow_run.head_branch
}}
GH_TOKEN: ${{ github.token }}
run: |
number=$(gh pr view --repo "${{ github.event.workflow_run.repository.full_name }}" "${PR_BRANCH}" --json number --jq .number)
echo "number=$number" >> $GITHUB_OUTPUT
- if: steps.unzip-patch.outputs.exists == 'true' && success()
env:
GH_TOKEN: ${{ github.token }}
run: |
gh pr comment ${{ steps.get-pr.outputs.number }} --body "🔧 The result from spotlessApply was committed to the PR branch."
- if: steps.unzip-patch.outputs.exists == 'true' && failure()
env:
GH_TOKEN: ${{ github.token }}
run: |
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."