File: check-all.sh

package info (click to toggle)
pcs 0.12.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,580 kB
  • sloc: python: 228,655; xml: 20,710; ruby: 13,336; makefile: 1,554; sh: 485
file content (53 lines) | stat: -rwxr-xr-x 1,150 bytes parent folder | download
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
#!/bin/sh

# Check definition. Multiline string, every line is for one check.
# Format of line is:
# `Check title ./path/relative/to/this/script/check-script.sh`.
# The last space separates title from script path.
check_list="
RUFF LINT CHECK ./check-lint.sh
RUFF FORMAT CHECK ./check-format.sh
MAKEFILE FILE LISTING CHECK ./check-makefile-file-listing.sh
"

extract_title() {
  echo "$1" | awk '{$NF=""; print $0}'
}

extract_command() {
  realpath "$(dirname "$0")"/"$(echo "$1" | awk '{print $NF}')"
}

err_report=""
while IFS= read -r line; do
  [ -n "$line" ] || continue

  check=$(extract_command "$line")

  if ! output=$("$check" 2>&1); then
    err_report="${err_report}$(extract_title "$line") ($check)\n$output\n\n"
  fi
done << EOF
$check_list
EOF

if [ -z "$err_report" ]; then
  exit 0
fi

echo "Warning: some check failed"
printf "%b" "$err_report"

printf "Checks failed. Continue with commit? (c)Continue (a)Abort: " > /dev/tty
IFS= read -r resolution < /dev/tty

case "$resolution" in
  c | C) exit 0 ;;
  a | A)
    echo "Commit aborted."
    exit 1
    ;;
esac

echo "Unknown resolution '$resolution', aborting commit..."
exit 1