mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
build(Makefile): capture pre-commit output to log files (#22978)
pre-commit was noisy: every sub-target dumped full stdout/stderr to the terminal, burying failures in pages of compiler output and lint details. Teach timed-shell.sh a quiet mode via MAKE_LOGDIR: when set, recipe output is redirected to per-target log files and a one-line status is printed instead. When unset, behavior is unchanged (with a refreshed output format). Makefile changes: - pre-commit creates a tmpdir, passes MAKE_LOGDIR to sub-makes - Drop --output-sync=target (log files eliminate interleaving) - Add --no-print-directory to suppress Entering/Leaving noise - Split check-unstaged and check-untracked into separate defines - Restyle both with colored indicators and clearer instructions - Clean up tmpdir on success, preserve on failure for debugging
This commit is contained in:
committed by
GitHub
parent
5130404f2a
commit
e7e2de99ba
@@ -8,6 +8,9 @@
|
||||
# SHELL := $(CURDIR)/scripts/lib/timed-shell.sh
|
||||
# .SHELLFLAGS = $@ -ceu
|
||||
#
|
||||
# When MAKE_LOGDIR is set, recipe output is captured to a log file.
|
||||
# Otherwise output goes to stdout/stderr as normal.
|
||||
#
|
||||
# $(shell ...) uses SHELL but passes -c directly, not .SHELLFLAGS.
|
||||
# Detect this and delegate to bash without timing output.
|
||||
if [[ $1 == -* ]]; then
|
||||
@@ -19,23 +22,32 @@ set -eu
|
||||
target=$1
|
||||
shift
|
||||
|
||||
bold=$(tput bold 2>/dev/null) || true
|
||||
dim=$(tput dim 2>/dev/null) || dim=$(tput setaf 8 2>/dev/null) || true
|
||||
green=$(tput setaf 2 2>/dev/null) || true
|
||||
red=$(tput setaf 1 2>/dev/null) || true
|
||||
reset=$(tput sgr0 2>/dev/null) || true
|
||||
|
||||
start=$(date +%s)
|
||||
echo "${bold}==> ${target}${reset}"
|
||||
|
||||
set +e
|
||||
bash "$@"
|
||||
if [[ -n ${MAKE_LOGDIR:-} ]]; then
|
||||
logfile="${MAKE_LOGDIR}/${target//\//-}.log"
|
||||
bash "$@" >"$logfile" 2>&1
|
||||
else
|
||||
printf '%s○%s %s\n' "$dim" "$reset" "$target"
|
||||
bash "$@"
|
||||
fi
|
||||
rc=$?
|
||||
set -e
|
||||
|
||||
elapsed=$(($(date +%s) - start))
|
||||
if ((rc == 0)); then
|
||||
echo "${bold}${green}==> ${target} completed in ${elapsed}s${reset}"
|
||||
printf '%s✓%s %s (%ds)\n' "$green" "$reset" "$target" "$elapsed"
|
||||
else
|
||||
echo "${bold}${red}==> ${target} FAILED after ${elapsed}s${reset}" >&2
|
||||
exit $rc
|
||||
if [[ -n ${MAKE_LOGDIR:-} ]]; then
|
||||
printf '%s✗%s %s (%ds) → %s\n' "$red" "$reset" "$target" "$elapsed" "$logfile"
|
||||
else
|
||||
printf '%s✗%s %s (%ds)\n' "$red" "$reset" "$target" "$elapsed"
|
||||
fi
|
||||
exit "$rc"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user