|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Canonical source: standard-tooling |
| 3 | +# validate_local.sh — shared driver for pre-PR local validation. |
| 4 | +# |
| 5 | +# Reads primary_language from docs/repository-standards.md, then runs: |
| 6 | +# 1. validate_local_common.sh (always) |
| 7 | +# 2. validate_local_<lang>.sh (if primary_language is set and script exists) |
| 8 | +# 3. validate_local_custom.sh (if exists — repo-specific escape hatch) |
| 9 | +set -euo pipefail |
| 10 | + |
| 11 | +scripts_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 12 | +repo_root="$(cd "$scripts_dir/../.." && pwd)" |
| 13 | +profile_file="$repo_root/docs/repository-standards.md" |
| 14 | + |
| 15 | +# -- helpers ----------------------------------------------------------------- |
| 16 | + |
| 17 | +run() { |
| 18 | + echo "Running: $*" |
| 19 | + "$@" |
| 20 | +} |
| 21 | + |
| 22 | +# -- read primary_language from repo profile --------------------------------- |
| 23 | + |
| 24 | +primary_language="" |
| 25 | +if [[ -f "$profile_file" ]]; then |
| 26 | + while IFS= read -r line; do |
| 27 | + if [[ "$line" =~ ^[[:space:]-]*primary_language:[[:space:]]*(.+)$ ]]; then |
| 28 | + primary_language="${BASH_REMATCH[1]}" |
| 29 | + break |
| 30 | + fi |
| 31 | + done < "$profile_file" |
| 32 | +fi |
| 33 | + |
| 34 | +echo "========================================" |
| 35 | +echo "validate_local.sh" |
| 36 | +echo "primary_language: ${primary_language:-<not set>}" |
| 37 | +echo "========================================" |
| 38 | +echo "" |
| 39 | + |
| 40 | +# -- common checks (always) ------------------------------------------------- |
| 41 | + |
| 42 | +common_script="$scripts_dir/validate_local_common.sh" |
| 43 | +if [[ -f "$common_script" ]]; then |
| 44 | + run "$common_script" |
| 45 | +else |
| 46 | + echo "WARNING: $common_script not found; skipping common checks" >&2 |
| 47 | +fi |
| 48 | + |
| 49 | +# -- language-specific checks ------------------------------------------------ |
| 50 | + |
| 51 | +if [[ -n "$primary_language" && "$primary_language" != "none" ]]; then |
| 52 | + lang_script="$scripts_dir/validate_local_${primary_language}.sh" |
| 53 | + if [[ -f "$lang_script" ]]; then |
| 54 | + echo "" |
| 55 | + run "$lang_script" |
| 56 | + fi |
| 57 | +fi |
| 58 | + |
| 59 | +# -- repo-specific custom checks -------------------------------------------- |
| 60 | + |
| 61 | +custom_script="$scripts_dir/validate_local_custom.sh" |
| 62 | +if [[ -f "$custom_script" ]]; then |
| 63 | + echo "" |
| 64 | + run "$custom_script" |
| 65 | +fi |
| 66 | + |
| 67 | +echo "" |
| 68 | +echo "========================================" |
| 69 | +echo "validate_local.sh: all checks passed" |
| 70 | +echo "========================================" |
0 commit comments