This repository has been archived by the owner on Aug 22, 2024. It is now read-only.
forked from stacks-network/actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
60 lines (52 loc) · 1.81 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
## Github workflow to check that all jobs parsed as input from 'needs' are successful
name: Check Jobs Status
inputs:
jobs:
description: "A list of jobs from the `needs` context."
required: true
summary_print:
description: "Print jobs status to GitHub Step Summary"
required: false
default: "false"
runs:
using: "composite"
steps:
- name: Check Jobs
id: check_jobs
shell: bash
run: |
# Check the jobs status and print the failures
failing_jobs=()
# Function to print output to GitHub Step Summary
print_to_step_summary() {
echo "### Jobs Status" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "Some jobs that are required to succeed have failed." >> "$GITHUB_STEP_SUMMARY"
}
# Check that 'jq' command exists
if ! command -v jq > /dev/null 2>&1; then
echo "jq command doesn't exist!";
exit 1;
fi
# Search for failures and append them to a list
for job_name in $(echo '${{ inputs.jobs }}' | jq -r 'keys[]'); do
result=$(echo '${{ inputs.jobs }}' | jq -r ".[\"$job_name\"].result")
if [[ "$result" != "success" ]]; then
failing_jobs+=("$job_name")
fi
done
# If there is no failing job, exit
if [[ ${#failing_jobs[@]} -eq 0 ]]; then
echo "All jobs were successful!"
exit 0
fi
# Print failing jobs to console
echo "Required jobs failed:"
for job in "${failing_jobs[@]}"; do
echo "- $job"
done
# If the 'summary_print' input is true, print jobs to GitHub Step Summary, then fail the job
if [[ "${{ inputs.summary_print }}" == "true" ]]; then
print_to_step_summary
fi
exit 1