-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathci
More file actions
executable file
·25 lines (22 loc) · 954 Bytes
/
Copy pathci
File metadata and controls
executable file
·25 lines (22 loc) · 954 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
#!/usr/bin/env bash
# Project CI entrypoint. Default: fix formatting locally.
# Use --action=check (dry-run, non-zero on diff) in a git hook / CI.
set -euo pipefail
cd "$(dirname "$0")"
check=lint action=fix
for a in "$@"; do case $a in
--check=*) check=${a#*=} ;;
--action=*) action=${a#*=} ;;
*) echo "usage: ./ci [--check=lint] [--action=fix|check]" >&2; exit 2 ;;
esac; done
srcs() { git ls-files '*.c' '*.h' ':!:libs/**' ':!:version.h'; }
shells() { git ls-files ':!:libs/**' | while read -r f; do
if head -1 -- "$f" | grep -q '^#!.*sh'; then printf '%s\n' "$f"; fi
done; }
case $check.$action in
lint.fix) srcs | xargs -r clang-format -i
shells | xargs -r shellcheck ;; # no autofix; reports only
lint.check) srcs | xargs -r clang-format --dry-run --Werror
shells | xargs -r shellcheck ;;
*) echo "unknown --check=$check --action=$action" >&2; exit 2 ;;
esac