aboutsummaryrefslogtreecommitdiffstats
path: root/tools/run_audits.sh
blob: cf6c548d9145d5fceea7eee302f75dfd43ce8284 (plain) (blame)
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
#!/usr/bin/env bash
# Run all repo audits and regenerate the sitemap.
# Suitable for cron; exits non-zero if anything failed.
#
# Env:
#   SILENT=1     suppress per-audit headers
#   STRICT=1     also exit non-zero if audits report issues
#                (default: only exit non-zero on script errors, not on findings —
#                so the cron mail surfaces the report without flapping daily)
#   CHECK_LINKS=1  also run the (slow, network-bound) external link rot check

set -u
cd "$(dirname "$0")/.."

ROOT="$(pwd)"
PY="${PYTHON:-python3}"

heading() { [ "${SILENT:-0}" = "1" ] || printf '\n=== %s ===\n' "$1"; }
run_audit() {
  local name="$1"; shift
  heading "$name"
  if "$@"; then
    return 0
  else
    local rc=$?
    [ "${STRICT:-0}" = "1" ] && return $rc
    return 0
  fi
}

# Generate sitemap first (unconditional, idempotent).
heading "generate_sitemap"
"$PY" "$ROOT/tools/generate_sitemap.py" || exit $?

# Audits — STRICT controls whether their findings fail the run.
run_audit "link_check" "$PY" "$ROOT/tools/link_check.py"
LC_RC=$?
run_audit "html_audit" "$PY" "$ROOT/tools/html_audit.py"
HA_RC=$?
run_audit "image_budget" "$PY" "$ROOT/tools/image_budget.py"
IB_RC=$?

LR_RC=0
if [ "${CHECK_LINKS:-0}" = "1" ]; then
  run_audit "link_rot" "$PY" "$ROOT/tools/link_rot.py"
  LR_RC=$?
fi

if [ "${STRICT:-0}" = "1" ]; then
  exit $(( LC_RC | HA_RC | IB_RC | LR_RC ))
fi
exit 0