mirror of
https://github.com/coder/coder.git
synced 2026-06-03 13:08:25 +00:00
56960585af
pre-commit and pre-push only reported total elapsed time at the end, making it hard to identify which jobs are slow. Add a `MAKE_TIMED=1` mode that replaces `SHELL` with a wrapper (`scripts/lib/timed-shell.sh`) to print wall-clock time for each recipe. pre-commit and pre-push enable this on their sub-makes. Ad-hoc use: `make MAKE_TIMED=1 test`
42 lines
957 B
Bash
Executable File
42 lines
957 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# timed-shell.sh wraps bash with per-target wall-clock timing.
|
|
#
|
|
# Recipe invocation: timed-shell.sh <target> -ceu <recipe>
|
|
# $(shell ...) calls: timed-shell.sh -c <command>
|
|
#
|
|
# Enable via Makefile:
|
|
# SHELL := $(CURDIR)/scripts/lib/timed-shell.sh
|
|
# .SHELLFLAGS = $@ -ceu
|
|
#
|
|
# $(shell ...) uses SHELL but passes -c directly, not .SHELLFLAGS.
|
|
# Detect this and delegate to bash without timing output.
|
|
if [[ $1 == -* ]]; then
|
|
exec bash "$@"
|
|
fi
|
|
|
|
set -eu
|
|
|
|
target=$1
|
|
shift
|
|
|
|
bold=$(tput bold 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 "$@"
|
|
rc=$?
|
|
set -e
|
|
|
|
elapsed=$(($(date +%s) - start))
|
|
if ((rc == 0)); then
|
|
echo "${bold}${green}==> ${target} completed in ${elapsed}s${reset}"
|
|
else
|
|
echo "${bold}${red}==> ${target} FAILED after ${elapsed}s${reset}" >&2
|
|
exit $rc
|
|
fi
|