-
Notifications
You must be signed in to change notification settings - Fork 11
200 lines (182 loc) · 7.97 KB
/
pr_comment.yml
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: PR comment
on:
workflow_run:
workflows: [CI]
types:
- completed
#permissions:
# pull-requests: write
jobs:
create_test_summary_report:
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure'}}
# if: github.repository == 'hablapps/doric'
runs-on: ubuntu-latest
name: Create testing summary comment
steps:
# - name: <DEBUG> Dump GitHub context
# env:
# GITHUB_CONTEXT: ${{ toJson(github) }}
# run: echo "$GITHUB_CONTEXT"
- name: Download PR context
uses: dawidd6/[email protected] # marcofaggian/[email protected]
with:
name: pr_context.json
workflow_conclusion: ""
github_token: ${{secrets.GITHUB_TOKEN}}
workflow: ${{ github.event.workflow.id }}
commit: ${{ github.event.workflow_run.head_commit.id }}
repo: ${{github.repository}}
if_no_artifact_found: fail
- name: Output PR context
id: output_pr_context
shell: bash
run: |
content="$(cat pr_context.json)"
echo "${content}"
# the following lines are only required for multi line json
content="${content//'%'/'%25'}"
content="${content//$'\n'/'%0A'}"
content="${content//$'\r'/'%0D'}"
echo "::set-output name=pr_context::$(echo "${content}")"
- name: Find Comment
# if: github.event_name == 'pull_request'
# if: ${{ github.event.workflow_run.conclusion == 'success/failure' }}
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ fromJson(steps.output_pr_context.outputs.pr_context).pr_number }}
body-includes: "This is an auto-generated comment"
# - uses: actions/checkout@v3
#
# - name: Render template
# id: template
# uses: chuhlomin/[email protected]
# with:
# template: .github/templates/pr_comment.md
# vars: |
# workflow: ${{ github.workflow }}
# run_url: [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
# attempt: ${{ github.event.workflow_run.run_attempt }}
# job_name: ${{ github.job }}
- name: Get current date
id: getDate
run: echo "::set-output name=current_date::$(date +'%Y-%m-%d %H:%M:%S %z (%Z)')"
- name: Create summary comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ fromJson(steps.output_pr_context.outputs.pr_context).pr_number }}
token: "${{ secrets.GITHUB_TOKEN }}"
edit-mode: replace
# body: ${{ steps.template.outputs.result }}
body: |
:octocat: This is an auto-generated comment created by:
- Date : ${{ steps.getDate.outputs.current_date }}
- Workflow : ${{ github.workflow }}
- Job name : ${{ github.job }}
- Run : [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
- Commit : ${{ github.event.workflow_run.head_commit.id }} <!-- ${{ github.event.workflow_run.head_sha }} --> ${{ github.event.workflow_run.head_commit.message }}
<table>
<tr>
<th>Actor</th>
<th>Triggering actor</th>
<th>Sender</th>
</tr>
<td style="text-align:center">
<a href="${{ github.event.workflow_run.actor.html_url }}">
<img src="${{ github.event.workflow_run.actor.avatar_url }}" alt="${{ github.event.workflow_run.actor.login }}" style="width:30px;height:30px;">
<br>
${{ github.event.workflow_run.actor.login }}
</a>
</td>
<td style="text-align:center">
<a href="${{ github.event.workflow_run.triggering_actor.html_url }}">
<img src="${{ github.event.workflow_run.triggering_actor.avatar_url }}" alt="${{ github.event.workflow_run.triggering_actor.login }}" style="width:30px;height:30px;">
<br>
${{ github.event.workflow_run.triggering_actor.login }}
</a>
</td>
<td style="text-align:center">
<a href="${{ github.event.sender.html_url }}">
<img src="${{ github.event.sender.avatar_url }}" alt="${{ github.event.sender.login }}" style="width:30px;height:30px;">
<br>
${{ github.event.sender.login }}
</a>
</td>
<tr><td colspan="3">
Triggered by:
- Workflow name: "${{ github.event.workflow_run.name }}" at ${{ github.event.workflow_run.path }}
- URL: [${{ github.event.workflow_run.html_url }}](${{ github.event.workflow_run.html_url }})
- on ${{ github.event_name }}:${{ github.event.action }} <!-- ${{ github.event.workflow_run.status }} -->
</td></tr>
</table>
Test summary report 📊
| Spark version | testing |
|:-------------:|:-------------:|
update_test_summary_report:
needs: ["create_test_summary_report"]
runs-on: ubuntu-latest
name: Update comment
steps:
- name: Download artifact
id: download_artifacts
uses: dawidd6/[email protected] # marcofaggian/[email protected]
with:
# names: test-summary-*.md
workflow_conclusion: ""
github_token: ${{secrets.GITHUB_TOKEN}}
workflow: ${{ github.event.workflow.id }}
commit: ${{ github.event.workflow_run.head_commit.id }}
repo: ${{github.repository}}
if_no_artifact_found: fail
- name: Get summary
if: steps.download_artifacts.conclusion == 'success'
id: summary
# The content must be escaped to preserve newlines. --> https://github.com/orgs/community/discussions/26288
run: |
body="$(cat test-summary-*.md/*)"
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "::set-output name=summary::$(echo "${body}")"
shell: bash
- name: Output PR context
id: output_pr_context
shell: bash
run: |
content="$(cat pr_context.json/pr_context.json)"
echo "${content}"
# the following lines are only required for multi line json
content="${content//'%'/'%25'}"
content="${content//$'\n'/'%0A'}"
content="${content//$'\r'/'%0D'}"
echo "::set-output name=pr_context::$(echo "${content}")"
- name: Find Comment
if: ${{ always() }}
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ fromJson(steps.output_pr_context.outputs.pr_context).pr_number }}
body-includes: "This is an auto-generated comment"
- name: Add test results
if: steps.fc.conclusion == 'success'
id: add_test_results
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ fromJson(steps.output_pr_context.outputs.pr_context).pr_number }}
token: "${{ secrets.GITHUB_TOKEN }}"
edit-mode: append
body: |
${{ steps.summary.outputs.summary }}
- name: Add failed comment
if: ${{ failure() && steps.fc.conclusion == 'success' }}
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ fromJson(steps.output_pr_context.outputs.pr_context).pr_number }}
token: "${{ secrets.GITHUB_TOKEN }}"
edit-mode: append
body: |
---------
Something bad happened :interrobang: :flushed: :boom: :fire::fire::fire: