-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrapids-check-pr-job-dependencies
executable file
·60 lines (50 loc) · 2.34 KB
/
rapids-check-pr-job-dependencies
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
#!/bin/bash
# Checks whether a particular GitHub workflow job depends on all of the
# other jobs in the workflow.
#
# This is necessary since the RAPIDS branch protections are configured to require
# the "pr-builder" job to pass for all PRs. It's implied that that job depends
# on all other jobs in the workflow.
#
# An optional argument can be passed to ignore certain jobs from the check.
# The argument should be a space-separated list of job names, e.g.:
# rapids-check-pr-job-dependencies "job1 job2 job3"
set -euo pipefail
export WORKFLOW_FILE=${WORKFLOW_FILE:-".github/workflows/pr.yaml"}
export PR_BUILDER_JOB_NAME=${PR_BUILDER_JOB_NAME:-"pr-builder"}
export IGNORED_JOBS=${1:-""}
WORKFLOW_JOBS=$(yq '((.jobs | keys) - [strenv(PR_BUILDER_JOB_NAME)])' "${WORKFLOW_FILE}")
export WORKFLOW_JOBS
PR_BUILDER_JOB_NEEDS=$(yq '(.jobs.[env(PR_BUILDER_JOB_NAME)].needs)' "${WORKFLOW_FILE}")
export PR_BUILDER_JOB_NEEDS
IGNORED_JOBS=$(yq -n 'strenv(IGNORED_JOBS) | trim | split(" ")')
export IGNORED_JOBS
MISSING_JOBS=$(yq -n '((env(WORKFLOW_JOBS) - env(PR_BUILDER_JOB_NEEDS)) - env(IGNORED_JOBS))')
export MISSING_JOBS
if yq -en 'env(MISSING_JOBS) | length != 0' >/dev/null 2>&1; then
echo "'${PR_BUILDER_JOB_NAME}' job is missing the following dependent jobs:"
yq -n 'env(MISSING_JOBS) | map(" - " + .) | join("\n")'
echo ""
echo "Update '${WORKFLOW_FILE}' to include these missing jobs for '${PR_BUILDER_JOB_NAME}'".
echo "Alternatively, you may ignore these jobs by passing them as an argument to this script."
exit 1
fi
if if_condition="$(yq -e '.jobs.[env(PR_BUILDER_JOB_NAME)].if' "${WORKFLOW_FILE}" 2>/dev/null)"; then
if [[ "${if_condition}" != "always()" ]]; then
echo "If '${PR_BUILDER_JOB_NAME}' job has an 'if' condition, it must be set to 'always()'."
echo ""
echo "Update '${WORKFLOW_FILE}' to set the correct 'if' condition."
exit 1
fi
# shellcheck disable=SC2016
if yq -e '.jobs.[env(PR_BUILDER_JOB_NAME)].with.needs != "${{ toJSON(needs) }}"' "${WORKFLOW_FILE}" >/dev/null 2>&1; then
echo "If '${PR_BUILDER_JOB_NAME}' job has an 'if' condition, it must also set the 'needs' input to '\${{ toJSON(needs) }}'."
echo ""
echo "Update '${WORKFLOW_FILE}' to add the following:"
echo ""
echo "with:"
echo " needs: \${{ toJSON(needs) }}"
exit 1
fi
fi
echo "${PR_BUILDER_JOB_NAME} depends on all other jobs."