fix: extract apply logic to script file for CI log visibility #448
No reviewers
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ldraney/pal-e-platform!448
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/ci-apply-log-visibility"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Extract the apply step's init + apply logic into a script file to fix CI log visibility.
Changes
/tmp/apply.shvia single-quoted heredoc (same pattern as existingpost-comment.sh)tofu initoutput to a file — only shown on failure, saving ~40 lines of ANSI-heavy provider download output from the log buffertail -100) now survives Woodpecker's log buffer limitEvery push-to-main pipeline since PR #446 showed logs ending at "Running full apply" with no apply output visible. The Woodpecker trace echo plus
tofu initANSI output consumed the entire log buffer beforetail -100could appear.Test Plan
=== APPLY OUTPUT (last 100 lines) ===in logsReview Checklist
post-comment.shheredoc pattern$inside<<'APPLYEOF'heredoc (no Woodpecker$$escaping needed)Related Notes
tail -100but didn't solve the underlying log buffer exhaustionCloses #448
PR #448 Review
DOMAIN REVIEW
Tech stack: Woodpecker CI / shell scripting / OpenTofu (Terraform Plugin Framework context)
Heredoc pattern consistency. The new
apply.shheredoc follows the samecat > /tmp/script.sh <<'DELIMITER'pattern already used bypost-comment.sh(lines 229-260). Single-quoted delimiter prevents shell expansion during write, so$is correct inside the body. The$$to$conversion across all variable references is consistent and complete -- I count 16 substitutions and all are accounted for.Init output suppression. Redirecting
tofu initto/tmp/init-output.txtand only showing it on failure is a sound approach. The nested retry logic (if ! init; then sleep 3; if ! init; then show output + exit 1) is an improvement over the old|| (sleep 3 && init)one-liner because it now captures and displays the failure output. The old pattern silently swallowed init errors.cd terraform placement. The old code had
cd terraformas a separate Woodpecker command step (line 394 in main). The new code moves it inside the script. This is correct -- the script runs in a subshell via/bin/sh /tmp/apply.sh, so thecdneeds to be inside that script's scope.Environment variable inheritance. The
post-comment.shpattern explicitly passes Woodpecker CI variables (FORGEJO_TOKEN,CI_REPO,CI_COMMIT_PULL_REQUEST) on the invocation line because those are$$-escaped CI variables that need Woodpecker expansion at invocation time. Theapply.shscript does not reference anyCI_*variables -- it only uses file-based state (/tmp/apply-mode.txt,/tmp/changed-modules.txt) andTF_VAR_*environment variables inherited from Woodpecker'senvironment:block. No explicit passing needed. Correct.Lock retry path. The lock-retry logic is unchanged in substance. The retry
eval $APPLY_CMDon line aftertofu force-unlockstill runs without output capture -- same as before. This means a second failure during retry won't be captured in/tmp/apply-output.txt. This is a pre-existing concern, not introduced by this PR.BLOCKERS
None.
NITS
Missing
set -ein apply.sh. Thepost-comment.shscript includesset -e(fail-fast on error). Theapply.shscript omits it. This is likely intentional since the script manually checks exit codes (echo $? > /tmp/apply-exit), but it is worth noting the inconsistency. Theset -ewould actually be incompatible with theeval $APPLY_CMD > /tmp/apply-output.txt 2>&1 ; echo $? > /tmp/apply-exitpattern sinceset -ewould abort on the non-zero eval before capturing the exit code. So the omission is correct. No action needed.Retry apply output not captured. The lock-retry path runs
eval $APPLY_CMDwithout redirecting to a file or tailing output. If the retry also fails, its output goes to stdout without the "last 100 lines" formatting. This is pre-existing behavior not introduced by this PR, but could be a follow-up improvement.SOP COMPLIANCE
PROCESS OBSERVATIONS
tofu initchange is actually an improvement (error output now visible on failure).post-comment.shandapply.sh), creating a clear convention for future CI script additions.VERDICT: APPROVED