Debian Codegraph @

scripts/check-workflow-make-targets.sh

raw
1 #!/usr/bin/env bash
2
3 set -euo pipefail
4
5 [[ $# -eq 0 ]] || { echo "usage: $0" >&2; exit 2; }
6
7 mapfile -t targets < <(
8 make -qp |
9 sed -n 's/^\([A-Za-z0-9][A-Za-z0-9_-]*\):\([^=]\|$\).*/\1/p' |
10 sort -u
11 )
12
13 bad=0
14 while IFS= read -r hit; do
15 target="${hit##*make }"
16 target="${target%%[^A-Za-z0-9_-]*}"
17 [[ -n "$target" ]] || continue
18
19 if [[ ! " ${targets[*]} " =~ [[:space:]]${target}[[:space:]] ]]; then
20 if (( bad == 0 )); then
21 echo "workflow make target check failed:" >&2
22 fi
23 echo " unknown make target '${target}' in ${hit%%:*}" >&2
24 bad=1
25 fi
26 done < <(grep -RHEo 'make[[:space:]]+[A-Za-z0-9][A-Za-z0-9_-]*' .github/workflows/*.y*ml || true)
27
28 (( bad == 0 )) || exit 1
29 echo "workflow make target check passed"