|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Runs the same checks as CI by parsing .github/workflows/ci.yml directly. |
| 3 | +# If CI steps change, this script automatically picks them up. |
| 4 | +# |
| 5 | +# Local adaptations: |
| 6 | +# - `npm ci` checks if node_modules is in sync with package-lock.json |
| 7 | +# and runs a clean install if not (CI always does npm ci). |
| 8 | +# - `npm run format:check` checks only git-tracked files because CI |
| 9 | +# runs on a clean checkout but locally we have untracked x.* scratch |
| 10 | +# files that fail prettier. |
| 11 | +set -euo pipefail |
| 12 | + |
| 13 | +cd "$(git rev-parse --show-toplevel)" |
| 14 | + |
| 15 | +ci_yaml=".github/workflows/ci.yml" |
| 16 | + |
| 17 | +if ! command -v yq &>/dev/null; then |
| 18 | + echo "error: yq is required (brew install yq)" >&2 |
| 19 | + exit 1 |
| 20 | +fi |
| 21 | + |
| 22 | +# Extract run steps |
| 23 | +mapfile -t names < <(yq '.jobs.build.steps[] | select(.run) | .name' "$ci_yaml") |
| 24 | +mapfile -t commands < <(yq '.jobs.build.steps[] | select(.run) | .run' "$ci_yaml") |
| 25 | + |
| 26 | +for i in "${!commands[@]}"; do |
| 27 | + cmd="${commands[$i]}" |
| 28 | + name="${names[$i]}" |
| 29 | + |
| 30 | + echo "=== ${name} ===" |
| 31 | + |
| 32 | + if [[ "$cmd" == "npm ci" ]]; then |
| 33 | + # Check if node_modules matches package-lock.json. If not, run |
| 34 | + # npm ci to match what CI does. This catches stale-dependency bugs |
| 35 | + # like sdk-tools.d.ts resolving locally but not in CI. |
| 36 | + if npm ls --all >/dev/null 2>&1; then |
| 37 | + echo "(node_modules in sync — skipping npm ci)" |
| 38 | + else |
| 39 | + echo "(node_modules out of sync — running npm ci)" |
| 40 | + npm ci |
| 41 | + fi |
| 42 | + elif [[ "$cmd" == "npm run format:check" ]]; then |
| 43 | + # Local override: format:check on git-tracked files only |
| 44 | + git ls-files -z '*.ts' '*.tsx' '*.js' '*.jsx' '*.json' '*.md' '*.yml' '*.yaml' '*.css' '*.html' \ |
| 45 | + | xargs -0 npx prettier --check |
| 46 | + else |
| 47 | + eval "$cmd" |
| 48 | + fi |
| 49 | + |
| 50 | + echo "" |
| 51 | +done |
| 52 | + |
| 53 | +echo "=== All CI checks passed ===" |
0 commit comments