@@ -16,20 +16,26 @@ jobs:
16
16
runs-on : ubuntu-20.04
17
17
if : ${{ github.event.workflow_run.conclusion == 'failure' }}
18
18
steps :
19
- - name : Output Variables
19
+ - name : Data
20
+ uses : actions/github-script@v5
20
21
continue-on-error : true
21
- id : vars
22
- run : |
23
- suite_id=$(curl -sS -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }} | jq '.check_suite_id')
24
- event=$(curl -sS -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }} | jq -r '.event')
25
- name=$(curl -sS -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/check-suites/$suite_id/check-runs | jq -r '[.check_runs[] | select(.conclusion=="failure")][0].name')
26
- url=$(curl -sS -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/check-suites/$suite_id/check-runs | jq -r '[.check_runs[] | select(.conclusion=="failure")][0].html_url')
27
- message_sanitized=$(awk '{gsub("&","&");gsub("<","\\<");gsub(">","\\>");print}' <<<'${{ github.event.workflow_run.head_commit.message }}')
22
+ id : data
23
+ with :
24
+ script : |
25
+ const message = context.payload.workflow_run.head_commit.message
26
+ message_sanitized = message.split('\n')[0]
27
+
28
+ const check_data = (await github.rest.checks.listForRef({
29
+ owner: context.payload.repository.owner.login,
30
+ repo: context.payload.repository.name,
31
+ ref: context.payload.workflow_run.head_commit.id,
32
+ })).data.check_runs.filter(check_run => check_run.conclusion === 'failure')[0]
28
33
29
- echo "::set-output name=name::$name"
30
- echo "::set-output name=url::$url"
31
- echo "::set-output name=event::$event"
32
- echo "::set-output name=message::$message_sanitized"
34
+ return {
35
+ job_name: check_data.name,
36
+ job_url: check_data.html_url,
37
+ commit_message: message_sanitized,
38
+ }
33
39
34
40
- name : Send Notification
35
41
uses : 8398a7/action-slack@v3
@@ -41,16 +47,16 @@ jobs:
41
47
icon_emoji: ':github:',
42
48
mention: 'channel',
43
49
attachments: [{
44
- title: '[${{ github.event.repository.full_name }}] ${{ github.event.workflow.name }} pipeline has failed (${{ steps.vars.outputs .event }})',
50
+ title: '[${{ github.event.repository.full_name }}] ${{ github.event.workflow.name }} pipeline has failed (${{ github.event.workflow_run .event }})',
45
51
color: 'danger',
46
52
fields: [{
47
53
title: 'Commit',
48
- value: `<https://github.com/${{ github.repository }}/commit/${{ github.event.workflow_run.head_commit.id }}|${{ steps.vars .outputs.message }}>`,
54
+ value: `<https://github.com/${{ github.repository }}/commit/${{ github.event.workflow_run.head_commit.id }}|${{ fromJSON( steps.data .outputs.result).commit_message }}>`,
49
55
short: true
50
56
},
51
57
{
52
58
title: 'Failed Job',
53
- value: `<${{ steps.vars .outputs.url }}|${{ steps.vars .outputs.name }}>`,
59
+ value: `<${{ fromJSON( steps.data .outputs.result).job_url }}|${{ fromJSON( steps.data .outputs.result).job_name }}>`,
54
60
short: true
55
61
},
56
62
{
0 commit comments