Swadhin Biswas fix(ci): resolve Docker build, coverage deps, and perf script · 4/30/2026
8401215
39 lines · 961 Bytes
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
#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(git rev-parse --show-toplevel)"
SCAN_SCRIPT="$ROOT_DIR/scripts/security/pre-push-secret-scan.sh"

if [[ ! -f "$SCAN_SCRIPT" ]]; then
  echo "[pre-push] secret scan script not found: $SCAN_SCRIPT"
  echo "[pre-push] blocking push until security hook is restored."
  exit 1
fi

RANGES=()
while read -r local_ref local_sha remote_ref remote_sha; do
  [[ -z "${local_sha:-}" ]] && continue

  if [[ "$local_sha" =~ ^0+$ ]]; then
    continue
  fi

  if [[ "$remote_sha" =~ ^0+$ ]]; then
    # New branch push: scan a recent commit window ending at local SHA.
    local_base="${local_sha}~20"
    if git rev-parse --verify "$local_base" >/dev/null 2>&1; then
      RANGES+=("${local_base}..${local_sha}")
    else
      RANGES+=("${local_sha}")
    fi
  else
    RANGES+=("${remote_sha}..${local_sha}")
  fi
done

if [[ ${#RANGES[@]} -eq 0 ]]; then
  RANGES=("HEAD~20..HEAD")
fi

bash "$SCAN_SCRIPT" "${RANGES[@]}"