-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
90 lines (85 loc) · 2.99 KB
/
action.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
name: "GitHub action Slack notification"
description: "GitHub action to send Slack notification when GitHub workflow start and finish"
inputs:
type:
description: could be message, start, finish
required: false
default: message
project:
description: name of the project (repository name is used if omitted)
default: ""
message:
description: message to post on Slack
default: ""
extra_message:
description: message to append to autogenerated message
default: ""
job_url:
description: deprecated not used anymore
default: ""
SLACK_WEBHOOK_URL:
description: Slack webhook url for all notifications
required: true
FAILURE_ONLY_SLACK_WEBHOOK_URL:
description: Slack webhook url for error notification
required: false
default: ""
OVERRIDE_JOB_STATUS:
description: The hardcoded JOB status (in case of action is used in an composite action)
required: false
default: ""
runs:
using: "composite"
steps:
- name: Fetch job check run information
id: fetch-check-run
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const { data } = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId
});
// Looks for exact match
let job = data.jobs.find(
(j) => j.name === context.job
)
if (!job) {
// matrix? let's do a loose match and pick the first one
// FIXME: can we do better?
job = data.jobs.find(
(j) => j.name.includes(context.job)
)
}
core.setOutput("job_url", job.html_url);
core.setOutput("job_id", String(job.id));
- name: Prepare report status
shell: bash
id: report-status
env:
NOTIF_TYPE: ${{ inputs.type }}
SLACK_TEXT_MESSAGE: ${{ inputs.message }}
PROJECT: ${{ inputs.project }}
REPOSITORY: ${{ github.repository }}
JOB_ID: ${{ steps.fetch-check-run.outputs.job_id }}
JOB_URL: ${{ steps.fetch-check-run.outputs.job_url }}
JOB_STATUS: ${{ job.status }}
REF_NAME: ${{ github.ref_name }}
OVERRIDE_JOB_STATUS: ${{ inputs.OVERRIDE_JOB_STATUS }}
EXTRA_MESSAGE: ${{ inputs.extra_message }}
run: python "${GITHUB_ACTION_PATH}/generate_slack_payload.py"
- uses: slackapi/slack-github-action@v1.23.0
with:
payload: ${{ steps.report-status.outputs.SLACK_PAYLOAD }}
env:
SLACK_WEBHOOK_URL: ${{ inputs.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
- uses: slackapi/slack-github-action@v1.23.0
if: ${{ job.status == 'failure' && inputs.FAILURE_ONLY_SLACK_WEBHOOK_URL != '' }}
with:
payload: ${{ steps.report-status.outputs.SLACK_PAYLOAD }}
env:
SLACK_WEBHOOK_URL: ${{ inputs.FAILURE_ONLY_SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK