-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathaudit
More file actions
executable file
·98 lines (86 loc) · 3.01 KB
/
Copy pathaudit
File metadata and controls
executable file
·98 lines (86 loc) · 3.01 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
set -euo pipefail
DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$DIR"
RED="\033[31m"
YELLOW="\033[33m"
GREEN="\033[32m"
DIM="\033[2m"
RESET="\033[0m"
BOLD="\033[1m"
CYAN="\033[36m"
has_issues=0
issues=()
fixes=()
local_version=$(grep '.version' build.zig.zon | head -1 | sed 's/.*"\(.*\)"/\1/')
echo -e "${BOLD}zphp${RESET} ${DIM}v${local_version}${RESET}"
echo ""
uncommitted=$(git status --short 2>/dev/null || true)
if [ -n "$uncommitted" ]; then
staged=$(git diff --cached --name-only 2>/dev/null | wc -l | tr -d ' ')
unstaged=$(git diff --name-only 2>/dev/null | wc -l | tr -d ' ')
untracked=$(git ls-files --others --exclude-standard 2>/dev/null | wc -l | tr -d ' ')
parts=()
[ "$staged" -gt 0 ] && parts+=("${staged} staged")
[ "$unstaged" -gt 0 ] && parts+=("${unstaged} modified")
[ "$untracked" -gt 0 ] && parts+=("${untracked} untracked")
issues+=("${YELLOW}uncommitted: $(IFS=', '; echo "${parts[*]}")${RESET}")
fixes+=("${CYAN}git add -A && git commit${RESET}")
has_issues=1
fi
unpushed=$(git log --oneline @{u}..HEAD 2>/dev/null | wc -l | tr -d ' ')
if [ "$unpushed" -gt 0 ]; then
issues+=("${YELLOW}${unpushed} unpushed commit(s)${RESET}")
fixes+=("${CYAN}git push${RESET}")
has_issues=1
fi
if [ -f "build.zig" ]; then
if ! make test >/dev/null 2>&1; then
issues+=("${RED}make test failed${RESET}")
fixes+=("${CYAN}make test${RESET}")
has_issues=1
fi
if command -v php >/dev/null 2>&1; then
if ! make compat >/dev/null 2>&1; then
issues+=("${RED}make compat failed${RESET}")
fixes+=("${CYAN}make compat${RESET}")
has_issues=1
fi
if ! make examples >/dev/null 2>&1; then
issues+=("${RED}make examples failed${RESET}")
fixes+=("${CYAN}make examples${RESET}")
has_issues=1
fi
else
issues+=("${YELLOW}php not found, skipped compat + examples${RESET}")
fixes+=("${CYAN}install php 8.4+${RESET}")
fi
fi
ci_result=$(gh run list --limit 1 --json conclusion,status 2>/dev/null || echo "[]")
ci_conclusion=$(echo "$ci_result" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d[0]['conclusion'] if d else 'none')" 2>/dev/null || echo "none")
ci_status=$(echo "$ci_result" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d[0]['status'] if d else 'none')" 2>/dev/null || echo "none")
if [ "$ci_status" = "in_progress" ] || [ "$ci_status" = "queued" ]; then
issues+=("${YELLOW}ci: ${ci_status}${RESET}")
fixes+=("${CYAN}gh run watch${RESET}")
has_issues=1
elif [ "$ci_conclusion" = "failure" ]; then
issues+=("${RED}ci: tests failing${RESET}")
fixes+=("${CYAN}gh run view --log-failed${RESET}")
has_issues=1
fi
if [ ${#issues[@]} -eq 0 ]; then
ci_label="${DIM}no ci${RESET}"
if [ "$ci_conclusion" = "success" ]; then
ci_label="${GREEN}tests pass${RESET}"
fi
echo -e " ${GREEN}ok${RESET} git clean, pushed ${ci_label}"
else
for i in "${!issues[@]}"; do
echo -e " ${issues[$i]}"
if [ -n "${fixes[$i]}" ]; then
echo -e " ${fixes[$i]}"
fi
done
fi
echo ""
exit $has_issues