run.sh (4379B)
1 #!/bin/bash 2 set -euo pipefail 3 4 # Jaypore CI: Lint & fix for a multi-language repo (Python/Go/JS) 5 # Intended to run as a pre-commit check via `git jci run`. 6 # 7 # Environment provided by Jaypore CI: 8 # JCI_COMMIT - the commit being checked 9 # JCI_REPO_ROOT - root of the git repository 10 # JCI_OUTPUT_DIR - directory for build artifacts (cwd at start) 11 12 RESULTS="${JCI_OUTPUT_DIR}/lint-results.txt" 13 : > "$RESULTS" 14 15 cd "$JCI_REPO_ROOT" 16 17 overall_status=0 18 19 # ── Python ────────────────────────────────────────────────────────── 20 echo "=== Python lint ===" | tee -a "$RESULTS" 21 22 # Syntax check every .py file 23 py_files=$(find . -name '*.py' -not -path './.git/*' -not -path './node_modules/*' || true) 24 if [ -n "$py_files" ]; then 25 py_errors=0 26 while IFS= read -r f; do 27 if ! python3 -m py_compile "$f" 2>>"$RESULTS"; then 28 py_errors=$((py_errors + 1)) 29 fi 30 done <<< "$py_files" 31 32 if [ "$py_errors" -gt 0 ]; then 33 echo "FAIL: $py_errors Python file(s) have syntax errors" | tee -a "$RESULTS" 34 overall_status=1 35 else 36 echo "OK: all Python files pass syntax check" | tee -a "$RESULTS" 37 fi 38 39 # Formatter check (black) 40 if command -v black &>/dev/null; then 41 echo "--- black --check ---" | tee -a "$RESULTS" 42 if ! black --check . 2>&1 | tee -a "$RESULTS"; then 43 echo "FAIL: black found files that need reformatting" | tee -a "$RESULTS" 44 echo " Run 'black .' to fix, then re-commit." | tee -a "$RESULTS" 45 overall_status=1 46 else 47 echo "OK: black is happy" | tee -a "$RESULTS" 48 fi 49 else 50 echo "SKIP: black not installed" | tee -a "$RESULTS" 51 fi 52 else 53 echo "SKIP: no .py files found" | tee -a "$RESULTS" 54 fi 55 56 # ── Go ────────────────────────────────────────────────────────────── 57 echo "" | tee -a "$RESULTS" 58 echo "=== Go lint ===" | tee -a "$RESULTS" 59 60 go_files=$(find . -name '*.go' -not -path './.git/*' -not -path './vendor/*' || true) 61 if [ -n "$go_files" ]; then 62 if command -v gofmt &>/dev/null; then 63 unformatted=$(gofmt -l . 2>&1 || true) 64 if [ -n "$unformatted" ]; then 65 echo "FAIL: the following Go files need formatting:" | tee -a "$RESULTS" 66 echo "$unformatted" | tee -a "$RESULTS" 67 echo " Run 'gofmt -w .' to fix, then re-commit." | tee -a "$RESULTS" 68 overall_status=1 69 else 70 echo "OK: all Go files are formatted" | tee -a "$RESULTS" 71 fi 72 else 73 echo "SKIP: gofmt not installed" | tee -a "$RESULTS" 74 fi 75 else 76 echo "SKIP: no .go files found" | tee -a "$RESULTS" 77 fi 78 79 # ── JavaScript ────────────────────────────────────────────────────── 80 echo "" | tee -a "$RESULTS" 81 echo "=== JavaScript lint ===" | tee -a "$RESULTS" 82 83 js_files=$(find . -name '*.js' -not -path './.git/*' -not -path './node_modules/*' || true) 84 if [ -n "$js_files" ]; then 85 if [ -f package.json ] && command -v npx &>/dev/null; then 86 echo "--- eslint --fix ---" | tee -a "$RESULTS" 87 # --fix rewrites files in place; the pre-commit hook should 88 # stage the corrections automatically. 89 if ! npx eslint --fix . 2>&1 | tee -a "$RESULTS"; then 90 echo "FAIL: eslint reported errors that could not be auto-fixed" | tee -a "$RESULTS" 91 overall_status=1 92 else 93 echo "OK: eslint passed (auto-fixable issues were corrected)" | tee -a "$RESULTS" 94 fi 95 else 96 echo "SKIP: npx/package.json not available" | tee -a "$RESULTS" 97 fi 98 else 99 echo "SKIP: no .js files found" | tee -a "$RESULTS" 100 fi 101 102 # ── Summary ───────────────────────────────────────────────────────── 103 echo "" | tee -a "$RESULTS" 104 if [ "$overall_status" -eq 0 ]; then 105 echo "✅ All lint checks passed." | tee -a "$RESULTS" 106 else 107 echo "❌ Some lint checks failed. See above for details." | tee -a "$RESULTS" 108 fi 109 110 exit "$overall_status"