FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
wordpress-develop/.github/workflows/slack-notifications.yml at trunk · dd32/wordpress-develop · GitHub
dd32
/
wordpress-develop
Public
forked from
WordPress/wordpress-develop
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Pull requests
2
Actions
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
wordpress-develop
/
.github
/
workflows
/
slack-notifications.yml
Copy path
View runs
More file actions
More file actions
Latest commit
History
History
History
267 lines (238 loc) · 10.5 KB
Breadcrumbs
wordpress-develop
/
.github
/
workflows
/
slack-notifications.yml
Copy path
File metadata and controls
267 lines (238 loc) · 10.5 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
259
260
261
262
263
264
265
266
267
#
#
#
A reusable workflow for posting messages to the Making WordPress
#
Core Slack Instance by submitting data to Slack webhook URLs
#
received by Slack Workflows.
#
#
name
:
Slack Notifications
on
:
workflow_call
:
inputs
:
calling_status
:
description
:
'
The status of the calling workflow
'
type
:
string
required
:
true
secrets
:
SLACK_GHA_SUCCESS_WEBHOOK
:
description
:
'
The Slack webhook URL for a successful build.
'
required
:
true
SLACK_GHA_CANCELLED_WEBHOOK
:
description
:
'
The Slack webhook URL for a cancelled build.
'
required
:
true
SLACK_GHA_FIXED_WEBHOOK
:
description
:
'
The Slack webhook URL for a fixed build.
'
required
:
true
SLACK_GHA_FAILURE_WEBHOOK
:
description
:
'
The Slack webhook URL for a failed build.
'
required
:
true
SLACK_GHA_TIMEOUT_WEBHOOK
:
description
:
'
The Slack webhook URL for a timed out build.
'
required
:
false
#
Disable permissions for all available scopes by default.
#
Any needed permissions should be configured at the job level.
permissions
:
{}
env
:
CURRENT_BRANCH
:
${{ github.ref_name }}
jobs
:
#
Gathers the details needed for Slack notifications.
#
#
These details are passed as outputs to the subsequent, dependant jobs that
#
submit data to Slack webhook URLs configured to post messages.
#
#
Performs the following steps:
#
- Retrieves the current workflow run.
#
- Determines the conclusion of the previous workflow run or run attempt.
#
- Sets the previous conclusion as an output.
#
- Prepares the commit message.
#
- Constructs and stores a message payload as an output.
prepare
:
name
:
Prepare notifications
runs-on
:
ubuntu-24.04
permissions
:
actions
:
read
contents
:
read
timeout-minutes
:
5
if
:
${{ github.repository == 'WordPress/wordpress-develop' && github.event.workflow_run.event != 'pull_request' }}
outputs
:
previous_conclusion
:
${{ steps.previous-attempt-result.outputs.result }}
timed_out
:
${{ steps.timeout-check.outputs.result }}
payload
:
${{ steps.create-payload.outputs.payload }}
steps
:
-
name
:
Determine the status of the previous attempt
id
:
previous-attempt-result
uses
:
actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3
#
v9.0.0
with
:
retries
:
2
retry-exempt-status-codes
:
418
result-encoding
:
string
script
:
|
const workflow_run = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: `${context.runId}`,
});
if ( process.env.CALLING_STATUS == 'failure' && workflow_run.data.run_attempt == 1 ) {
return 'first-failure';
}
// When a workflow has been restarted, check the previous run attempt. Because workflows are automatically
// restarted once and a failure on the first run is not reported, failures on the second run should not be
// considered.
if ( workflow_run.data.run_attempt > 2 ) {
const previous_run = await github.rest.actions.getWorkflowRunAttempt({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: `${context.runId}`,
attempt_number: workflow_run.data.run_attempt - 1
});
return previous_run.data.conclusion;
}
// Otherwise, check the previous workflow run.
const previous_runs = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: workflow_run.data.workflow_id,
branch: process.env.CURRENT_BRANCH,
exclude_pull_requests: true,
});
// This is the first workflow run for this branch or tag.
if ( previous_runs.data.workflow_runs.length < 2 ) {
return 'none';
}
const expected_events = new Array( 'push', 'schedule', 'workflow_dispatch' );
// Find the workflow run for the commit that immediately preceded this one.
for ( let i = 0; i < previous_runs.data.workflow_runs.length; i++ ) {
if ( previous_runs.data.workflow_runs[ i ].run_number == workflow_run.data.run_number ) {
let next_index = i;
do {
next_index++;
// Protects against a false notification when contributors use the trunk branch as the pull request head_ref.
if ( expected_events.indexOf( previous_runs.data.workflow_runs[ next_index ].event ) == -1 ) {
continue;
}
return previous_runs.data.workflow_runs[ next_index ].conclusion;
} while ( next_index < previous_runs.data.workflow_runs.length );
}
}
// Can't determine previous workflow conclusion.
return 'unknown';
env
:
CALLING_STATUS
:
${{ inputs.calling_status }}
#
The REST API exposes a distinct `timed_out` job conclusion that is unavailable through workflow contexts.
-
name
:
Determine whether the workflow timed out
id
:
timeout-check
uses
:
actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3
#
v9.0.0
if
:
${{ inputs.calling_status == 'cancelled' }}
with
:
retries
:
2
retry-exempt-status-codes
:
418
result-encoding
:
string
script
:
|
const jobs = await github.paginate( github.rest.actions.listJobsForWorkflowRunAttempt, {
owner: context.repo.owner,
repo: context.repo.repo,
run_id: `${context.runId}`,
attempt_number: Number( process.env.GITHUB_RUN_ATTEMPT ),
}, ( response ) => response.data.jobs );
return jobs.some( ( job ) => job.conclusion === 'timed_out' ) ? 'true' : 'false';
-
name
:
Get the commit message
id
:
current-commit-message
uses
:
actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3
#
v9.0.0
if
:
${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
with
:
retries
:
2
retry-exempt-status-codes
:
418
result-encoding
:
string
script
:
|
const commit_details = await github.rest.repos.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
ref: context.sha,
});
return commit_details.data.commit.message;
-
name
:
Construct payload and store as an output
id
:
create-payload
run
:
|
COMMIT_MSG="$(echo "${COMMIT_MSG_RAW}" | awk 'NR==1')"
PAYLOAD="$( jq \
-n \
--arg workflow_name "${GITHUB_WORKFLOW}" \
--arg ref_name "${CURRENT_BRANCH}" \
--arg run_url "https://github.com/WordPress/wordpress-develop/actions/runs/${GITHUB_RUN_ID}/attempts/${GITHUB_RUN_ATTEMPT}" \
--arg commit_message "${COMMIT_MSG}" \
'{workflow_name: $workflow_name, ref_name: $ref_name, run_url: $run_url, commit_message: $commit_message}' | jq -c .
)"
echo "payload=$PAYLOAD" >> "$GITHUB_OUTPUT"
env
:
COMMIT_MSG_RAW
:
${{ ( github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' ) && steps.current-commit-message.outputs.result || github.event.head_commit.message }}
#
Posts notifications when a workflow fails.
failure
:
name
:
Failure notifications
permissions
:
{}
runs-on
:
ubuntu-24.04
timeout-minutes
:
20
needs
:
[ prepare ]
if
:
${{ needs.prepare.outputs.previous_conclusion != 'first-failure' && inputs.calling_status == 'failure' || failure() }}
steps
:
-
name
:
Post failure notifications to Slack
uses
:
slackapi/slack-github-action@45a88b9581bfab2566dc881e2cd66d334e621e2c
#
v3.0.3
with
:
webhook-type
:
webhook-trigger
webhook
:
${{ secrets.SLACK_GHA_FAILURE_WEBHOOK }}
payload
:
${{ needs.prepare.outputs.payload }}
#
Posts notifications the first time a workflow run succeeds after previously failing.
fixed
:
name
:
Fixed notifications
permissions
:
{}
runs-on
:
ubuntu-24.04
timeout-minutes
:
20
needs
:
[ prepare ]
if
:
${{ contains( fromJson( '["failure", "cancelled", "none"]' ), needs.prepare.outputs.previous_conclusion ) && inputs.calling_status == 'success' && success() }}
steps
:
-
name
:
Post failure notifications to Slack
uses
:
slackapi/slack-github-action@45a88b9581bfab2566dc881e2cd66d334e621e2c
#
v3.0.3
with
:
webhook-type
:
webhook-trigger
webhook
:
${{ secrets.SLACK_GHA_FIXED_WEBHOOK }}
payload
:
${{ needs.prepare.outputs.payload }}
#
Posts notifications when a workflow is successful.
success
:
name
:
Success notifications
permissions
:
{}
runs-on
:
ubuntu-24.04
timeout-minutes
:
20
needs
:
[ prepare ]
if
:
${{ inputs.calling_status == 'success' && success() }}
steps
:
-
name
:
Post success notifications to Slack
uses
:
slackapi/slack-github-action@45a88b9581bfab2566dc881e2cd66d334e621e2c
#
v3.0.3
with
:
webhook-type
:
webhook-trigger
webhook
:
${{ secrets.SLACK_GHA_SUCCESS_WEBHOOK }}
payload
:
${{ needs.prepare.outputs.payload }}
cancelled
:
name
:
Cancelled notifications
permissions
:
{}
runs-on
:
ubuntu-24.04
timeout-minutes
:
20
needs
:
[ prepare ]
if
:
${{ ( inputs.calling_status == 'cancelled' && github.run_attempt == 2 && needs.prepare.outputs.timed_out != 'true' ) || cancelled() }}
steps
:
-
name
:
Post cancelled notifications to Slack
uses
:
slackapi/slack-github-action@45a88b9581bfab2566dc881e2cd66d334e621e2c
#
v3.0.3
with
:
webhook-type
:
webhook-trigger
webhook
:
${{ secrets.SLACK_GHA_CANCELLED_WEBHOOK }}
payload
:
${{ needs.prepare.outputs.payload }}
timeout
:
name
:
Timeout notifications
permissions
:
{}
runs-on
:
ubuntu-24.04
timeout-minutes
:
20
needs
:
[ prepare ]
if
:
${{ inputs.calling_status == 'cancelled' && github.run_attempt == 2 && needs.prepare.outputs.timed_out == 'true' }}
steps
:
-
name
:
Post timeout notifications to Slack
uses
:
slackapi/slack-github-action@45a88b9581bfab2566dc881e2cd66d334e621e2c
#
v3.0.3
with
:
webhook-type
:
webhook-trigger
webhook
:
${{ secrets.SLACK_GHA_TIMEOUT_WEBHOOK }}
payload
:
${{ needs.prepare.outputs.payload }}
Back
|
FazBrowse Home
|
New Git URL