-
Notifications
You must be signed in to change notification settings - Fork 468
258 lines (247 loc) · 12 KB
/
build-report.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
name: CICD Reports
run-name: Reports - ${{ github.event.workflow_run.name }}
on:
workflow_run:
workflows: ['PR Check','Merge Group Check']
types: [completed]
workflow_call:
inputs:
run-id:
description: 'The run id of the build to report on'
type: string
default: "${{ github.run_id }}"
slack-failure:
description: 'Indicates if the workflow should post to slack on failure'
type: boolean
default: false
secrets:
SLACK_BOT_TOKEN:
description: 'Slack Bot Token'
required: false
MASTER_BUILD_SLACK_WEBHOOK:
required: false
description: 'Slack Webhook'
permissions:
checks: write
jobs:
report:
runs-on: ubuntu-latest
steps:
- name: Log GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: actions/checkout@v4
- name: Download Workflow Data
id: data-download
uses: dawidd6/[email protected]
with:
name: 'workflow-data'
run_id: ${{ github.event.workflow_run.id || inputs.run-id }}
if_no_artifact_found: warn
- name: Download build reports
id: download-artifact
uses: dawidd6/[email protected]
with:
name: build-reports-test-.*
name_is_regexp: true
path: /tmp/build-reports-test
run_id: ${{ github.event.workflow_run.id || inputs.run-id }}
if_no_artifact_found: warn
- uses: phoenix-actions/test-reporting@v14
id: test-reporter
if: steps.data-download.outputs.found_artifact == 'true'
continue-on-error: true
with:
output-to: 'checks'
#artifact: /^build-reports-test-(.*)/ # artifact name uses runid from caller event is workflow_run
#name: 'MVN Test Report $1' # Name of the check run which will be created
name: 'Test Report'
path: '/tmp/build-reports-test/**/target/**/TEST-*.xml'
#path: '**/target/**/TEST-*.xml' # Path to test results (inside artifact .zip)
reporter: java-junit # Format of test results
fail-on-error: true
list-tests: 'failed'
- name: Get Workflow Data
id: workflow-data
run: |
if [[ ! -e "workflow-data.json" ]]
then
echo "::warn title=Artifact 'workflow-data' missing::Expected artifact 'workflow-data' does not exist for pull_request event."
else
jq . workflow-data.json
json=$(jq -c '.' workflow-data.json)
trigger_event_name=$(echo $json | jq -r '.trigger_event_name // "null"')
status=$(echo $json | jq -r '.aggregate_status // "null"')
pr_number=$(echo $json | jq -r '.pr_number // "null"')
pr_author=$(echo $json | jq -r '.pr_author // "null"')
run_id=$(echo $json | jq -r '.run_id // "null"')
first_fail_step=$(echo $json | jq -r '.first_fail_step // "None"')
first_fail_module=$(echo $json | jq -r '.first_fail_module // "None"')
first_fail_error=$(echo $json | jq -r '.first_fail_error // "None"')
pr_title=$(echo $json | jq -r '.pr_title // "null"')
branch=$(echo $json | jq -r '.branch // "null"')
head_sha=$(echo $json | jq -r '.head_sha // "null"')
head_author=$(echo $json | jq -r '.head_author // "null"')
head_name=$(echo $json | jq -r '.head_name // "null"')
source_repository=$(echo $json | jq -r '.source_repository // "null"')
action_run_url="https://github.com/$source_repository/actions/runs/$run_id"
pr_number_url="https://github.com/$source_repository/pull/$pr_number"
branch_url="https://github.com/$source_repository/tree/$branch"
commit_id_url="https://github.com/$source_repository/pull/$pr_number/commits/$head_sha"
test_results_url="https://github.com/$source_repository/pull/${pr_number}/checks"
if [[ -z "${{ steps.test-reporter.outputs.conclusion }}" ]]; then
test_conclusion="Not Run"
test_passed=0
test_failed=0
test_skipped=0
test_elapsed=0
else
test_conclusion=${{ steps.test-reporter.outputs.conclusion }}
test_passed=${{ steps.test-reporter.outputs.passed }}
test_failed=${{ steps.test-reporter.outputs.failed }}
test_skipped=${{ steps.test-reporter.outputs.skipped }}
test_elapsed=${{ steps.test-reporter.outputs.time }}
test_results_url=${{ steps.test-reporter.outputs.runHtmlUrl }}
fi
if [[ "$status" == "SUCCESS" ]]; then
echo "status_icon=✅" >> $GITHUB_OUTPUT
else
echo "status_icon=❌" >> $GITHUB_OUTPUT
fi
if [[ "$trigger_event_name" == "pull_request" ]]; then
echo "report_type=PR" >> $GITHUB_OUTPUT
elif [[ "$trigger_event_name" == "merge_group" ]]; then
echo "report_type=Merge Queue" >> $GITHUB_OUTPUT
elif [[ "$trigger_event_name" == "push" ]]; then
echo "report_type=Branch Merge" >> $GITHUB_OUTPUT
else
echo "report_type=$trigger_event_name" >> $GITHUB_OUTPUT
fi
echo "json=$json" >> $GITHUB_OUTPUT
echo "trigger_event_name=$trigger_event_name" >> $GITHUB_OUTPUT
echo "has_json=true" >> $GITHUB_OUTPUT
echo "status=$status" >> $GITHUB_OUTPUT
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
echo "pr_author=$pr_author" >> $GITHUB_OUTPUT
echo "run_id=$run_id" >> $GITHUB_OUTPUT
echo "first_fail_step=$first_fail_step" >> $GITHUB_OUTPUT
echo "first_fail_module=$first_fail_module" >> $GITHUB_OUTPUT
echo "first_fail_error=$first_fail_error" >> $GITHUB_OUTPUT
echo "pr_title=$pr_title" >> $GITHUB_OUTPUT
echo "branch=$branch" >> $GITHUB_OUTPUT
echo "head_sha=$head_sha" >> $GITHUB_OUTPUT
echo "head_author=$head_author" >> $GITHUB_OUTPUT
echo "head_name=$head_name" >> $GITHUB_OUTPUT
echo "source_repository=$source_repository" >> $GITHUB_OUTPUT
echo "action_run_url=$action_run_url" >> $GITHUB_OUTPUT
echo "pr_number_url=$pr_number_url" >> $GITHUB_OUTPUT
echo "branch_url=$branch_url" >> $GITHUB_OUTPUT
echo "commit_id_url=$commit_id_url" >> $GITHUB_OUTPUT
echo "test_results_url=$test_results_url" >> $GITHUB_OUTPUT
echo "test_conclusion=$test_conclusion" >> $GITHUB_OUTPUT
echo "test_passed=$test_passed" >> $GITHUB_OUTPUT
echo "test_failed=$test_failed" >> $GITHUB_OUTPUT
echo "test_skipped=$test_skipped" >> $GITHUB_OUTPUT
echo "test_elapsed=$test_elapsed" >> $GITHUB_OUTPUT
fi
- name: Slack Notification
uses: rtCamp/[email protected]
env:
SLACK_WEBHOOK: ${{ secrets.MASTER_BUILD_SLACK_WEBHOOK }}
SLACK_USERNAME: dotBot
SLACK_TITLE: "Broken build!"
SLACK_MSG_AUTHOR: " "
MSG_MINIMAL: true
SLACK_FOOTER: ""
SLACK_ICON: https://slackmojis.com/emojis/5432-this-is-fine/download
SLACK_MESSAGE: "Attention <!channel>! Broken build at `${{ github.ref_name }}`.\nPlease check the run at: ${{ steps.workflow-data.outputs.action_run_url }}"
if: steps.workflow-data.outputs.status != 'SUCCESS' && inputs.post-failure && github.repository == 'dotcms/core'
- name: Prepare Slack Message Payload
id: prepare-slack-message
run: |
payload=$(cat <<EOF
{
"text": "Github Action ${{ steps.workflow-data.outputs.status }} for ${{ steps.workflow-data.outputs.report_type }} #${{ steps.workflow-data.outputs.pr_number || steps.workflow-data.outputs.branch }}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "${{ steps.workflow-data.outputs.status_icon }} Github Action ${{ steps.workflow-data.outputs.status }} for ${{ steps.workflow-data.outputs.report_type }} #${{ steps.workflow-data.outputs.pr_number || steps.workflow-data.outputs.branch }}",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Action Run ID:* <${{ steps.workflow-data.outputs.action_run_url }} | ${{ steps.workflow-data.outputs.run_id }}> \n*Failure Step:* ${{ steps.workflow-data.outputs.first_fail_step }} \n*Failure Module:* ${{ steps.workflow-data.outputs.first_fail_module }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Failure Message:* ${{ steps.workflow-data.outputs.first_fail_error }}"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*${{ steps.workflow-data.outputs.report_type }} Details:* \nAuthor: ${{ steps.workflow-data.outputs.pr_author }} \nName: <${{ steps.workflow-data.outputs.pr_number_url || steps.workflow-data.outputs.branch_url }} | ${{ steps.workflow-data.outputs.pr_title || steps.workflow-data.outputs.branch }}> \nNumber: #${{ steps.workflow-data.outputs.pr_number || steps.workflow-data.outputs.branch }} \nBranch: <${{ steps.workflow-data.outputs.branch_url }} | ${{ steps.workflow-data.outputs.branch }}>"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Commit Details:* \nID: <${{ steps.workflow-data.outputs.commit_id_url }} | #${{ steps.workflow-data.outputs.head_sha }}> \nAuthor: ${{ steps.workflow-data.outputs.head_author }} \nName: ${{ steps.workflow-data.outputs.head_name }}"
}
},
{
"type": "divider"
},
{
"type": "header",
"text": {
"type": "plain_text",
"text": "🧪 Test Results = ${{ steps.workflow-data.outputs.test_conclusion }}",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Passed:* ${{ steps.workflow-data.outputs.test_passed }} \n*Failed:* ${{ steps.workflow-data.outputs.test_failed }} \n*Skipped:* ${{ steps.workflow-data.outputs.test_skipped }} \n*Elapsed Time:* ${{ steps.workflow-data.outputs.test_elapsed }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "🔍 <${{ steps.workflow-data.outputs.test_results_url }} | View Test Results>"
}
}
]
}
EOF
)
echo "payload=$(echo $payload | jq -c .)" >> $GITHUB_OUTPUT
echo "payload=$payload"
- name: Post to Slack
if: steps.workflow-data.outputs.has_json == 'true' && github.repository == 'dotcms/core'
uses: slackapi/[email protected]
with:
channel-id: ${{ vars.SLACK_REPORT_CHANNEL }}
payload: ${{ steps.prepare-slack-message.outputs.payload }}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}