Skip to content

Commit 12638b9

Browse files
committed
feat(chezmoi): add timing and exit-code reporting to apply steps
Apply duration and exit code are now printed after both the build-phase init --apply and the postCreate deferred scripts apply, so container build logs show at a glance how long chezmoi took and whether it succeeded.
1 parent df71290 commit 12638b9

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

src/chezmoi/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "chezmoi",
33
"id": "chezmoi",
4-
"version": "1.9.4",
4+
"version": "1.10.0",
55
"description": "Install chezmoi",
66
"documentationURL": "https://github.com/ckagerer/devcontainer-features/tree/main/src/chezmoi",
77
"options": {

src/chezmoi/install.sh

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,20 @@ if [ "${DEBUG:-false}" = "true" ]; then
155155
printf 'chezmoi debug log written to %s\n' "${CHEZMOI_DEBUG_LOG}"
156156
fi
157157

158-
sudo --user "${CHEZMOI_USER}" bash -c "cd '${CHEZMOI_USER_HOME}' && ${CHEZMOI_ENV_SOURCE}REMOTE_CONTAINERS=1 ${CMD}"
158+
CHEZMOI_APPLY_START="$(date +%s)"
159+
CHEZMOI_APPLY_RC=0
160+
sudo --user "${CHEZMOI_USER}" bash -c "cd '${CHEZMOI_USER_HOME}' && ${CHEZMOI_ENV_SOURCE}REMOTE_CONTAINERS=1 ${CMD}" || CHEZMOI_APPLY_RC=$?
161+
CHEZMOI_APPLY_ELAPSED=$(($(date +%s) - CHEZMOI_APPLY_START))
159162

160163
[ -n "${CHEZMOI_ENV_TMP}" ] && rm -f "${CHEZMOI_ENV_TMP}"
161164

165+
if [ "${CHEZMOI_APPLY_RC}" -eq 0 ]; then
166+
printf '[chezmoi] init --apply: SUCCESS (elapsed=%ds)\n' "${CHEZMOI_APPLY_ELAPSED}"
167+
else
168+
printf '[chezmoi] init --apply: FAILED exit=%d (elapsed=%ds)\n' "${CHEZMOI_APPLY_RC}" "${CHEZMOI_APPLY_ELAPSED}" >&2
169+
[ "${KEEP_GOING:-false}" != "true" ] && exit "${CHEZMOI_APPLY_RC}"
170+
fi
171+
162172
if [ "${DEBUG:-false}" = "true" ]; then
163173
{
164174
printf '\n-- Post-init: chezmoi status --\n'
@@ -208,13 +218,22 @@ fi
208218
# Run deferred chezmoi scripts (Nix install, home-manager switch, …).
209219
# The /nix named volume is mounted at this point, so the Nix store persists.
210220
if [[ "${DEFER_SCRIPTS}" == "true" ]]; then
221+
CHEZMOI_SCRIPTS_START="$(date +%s)"
222+
CHEZMOI_SCRIPTS_RC=0
211223
if [[ "${DEBUG}" == "true" ]]; then
212-
printf '\n-- chezmoi apply --include=scripts --\n' >> "${CHEZMOI_POSTCREATE_LOG}"
224+
printf '\n-- chezmoi apply --include=scripts --\n' >>"${CHEZMOI_POSTCREATE_LOG}"
213225
# shellcheck disable=SC2086
214-
chezmoi apply --include=scripts ${EXTRA_ARGS} 2>&1 | tee -a "${CHEZMOI_POSTCREATE_LOG}"
226+
chezmoi apply --include=scripts ${EXTRA_ARGS} 2>&1 | tee -a "${CHEZMOI_POSTCREATE_LOG}" || CHEZMOI_SCRIPTS_RC=$?
215227
else
216228
# shellcheck disable=SC2086
217-
chezmoi apply --include=scripts ${EXTRA_ARGS}
229+
chezmoi apply --include=scripts ${EXTRA_ARGS} || CHEZMOI_SCRIPTS_RC=$?
230+
fi
231+
CHEZMOI_SCRIPTS_ELAPSED=$(( $(date +%s) - CHEZMOI_SCRIPTS_START ))
232+
if [[ "${CHEZMOI_SCRIPTS_RC}" -eq 0 ]]; then
233+
printf '[chezmoi] apply --include=scripts: SUCCESS (elapsed=%ds)\n' "${CHEZMOI_SCRIPTS_ELAPSED}"
234+
else
235+
printf '[chezmoi] apply --include=scripts: FAILED exit=%d (elapsed=%ds)\n' "${CHEZMOI_SCRIPTS_RC}" "${CHEZMOI_SCRIPTS_ELAPSED}" >&2
236+
[[ "${KEEP_GOING}" != "true" ]] && exit "${CHEZMOI_SCRIPTS_RC}"
218237
fi
219238
fi
220239

0 commit comments

Comments
 (0)