Repository navigation
fix(ci): fire CI hooks per-component in --all / --query plan mode (#2… - #2430
Conversation
…oudposse#2397) Previously, `atmos terraform plan --all` routed to ExecuteTerraformQuery which ran each component but only fired CI hooks once in PostRunE, using the last component's context and an empty capture buffer. This caused $GITHUB_STEP_SUMMARY to contain at most one (misattributed) entry instead of one entry per component. Fix: add an optional PerComponentHook callback to ConfigAndStacksInfo. When set, processTerraformComponent and executeNodeCommand capture each component's stdout+stderr individually and invoke the hook immediately after execution. terraformRunWithOptions wires runCIHooksForPlanComponent as the hook for `plan --all/--query`, and PostRunE is suppressed via a wasMultiComponentExecution sentinel to avoid double-firing. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a PerComponentHook to ConfigAndStacksInfo, captures per-component Terraform stdout/stderr in executor/utils, invokes per-component CI hooks during multi-component plan runs (stripping ANSI and forwarding exit codes), and suppresses the global post-plan hook when component hooks ran. ChangesPer-component CI hooks
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/exec/terraform_executor_test.go`:
- Around line 187-195: The test is flaky because it relies on the real
ExecuteTerraform failure; make it deterministic by stubbing/mocking
ExecuteTerraform to return a fixed error and then assert behavior against that
error. Modify the test for executeNodeCommand to inject a fake executor (or
temporarily replace the package-level ExecuteTerraform function) so that
ExecuteTerraform returns a known error (e.g., errUtils.ErrTerraformExecFailed or
a new sentinel error), then run executeNodeCommand and assert hookCalled,
hookComponent ("vpc"), hookStack ("dev"), hookErr equals the injected error, and
that the returned err is ErrTerraformExecFailed; reference ExecuteTerraform,
executeNodeCommand, hookCalled, hookComponent, hookStack, hookErr and
errUtils.ErrTerraformExecFailed when making the change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 59694ddf-f489-4583-af69-ba5fb9e212d1
📒 Files selected for processing (8)
cmd/terraform/plan.gocmd/terraform/utils.gocmd/terraform/utils_hooks_test.gointernal/exec/terraform_executor.gointernal/exec/terraform_executor_test.gointernal/exec/terraform_utils.gointernal/exec/terraform_utils_test.gopkg/schema/schema.go
Replace the real ExecuteTerraform call in the hook test with an injectable execTerraformFn package-level variable (same pattern as authManagerFactory in terraform_query.go). This makes the test environment-independent and enables a success-path sub-test. Addresses CodeRabbit review comment on PR cloudposse#2430. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (67.34%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #2430 +/- ##
==========================================
+ Coverage 78.11% 78.13% +0.02%
==========================================
Files 1112 1112
Lines 105147 105193 +46
==========================================
+ Hits 82140 82197 +57
+ Misses 18455 18437 -18
- Partials 4552 4559 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Andriy Knysh (aknysh)
left a comment
There was a problem hiding this comment.
thanks thejrose1984
81631f0
into
cloudposse:main
|
These changes were released in v1.219.0. |
…2475) Extends the per-component hook pattern from PR cloudposse#2430 (plan --all) to apply --all so each component produces its own CI summary entry instead of a single misattributed entry for the last component. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…#2476) Extends the per-component hook pattern from PR cloudposse#2430 (plan --all) and cloudposse#2475 (apply --all) to deploy --all so each component produces its own CI summary entry instead of a single misattributed entry for the last component. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…#2476) Extends the per-component hook pattern from PR cloudposse#2430 (plan --all) and cloudposse#2475 (apply --all) to deploy --all so each component produces its own CI summary entry instead of a single misattributed entry for the last component. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* fix(ci): fire CI hooks per-component in apply --all mode (#2475) Extends the per-component hook pattern from PR #2430 (plan --all) to apply --all so each component produces its own CI summary entry instead of a single misattributed entry for the last component. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * test: use apply command identity in PostRunE suppression test Addresses CodeRabbit review on PR #2477: newHookTestCmd() created a command with Use:"plan" but the test calls applyCmd.PostRunE, causing ProcessCommandLineArgs to see the wrong subcommand name in the non-suppressed path. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Claude Sonnet 4.6 <[email protected]> Co-authored-by: Andriy Knysh <[email protected]>
* fix(ci): fire CI hooks per-component in deploy --all mode (#2476) Extends the per-component hook pattern from PR #2430 (plan --all) and #2475 (apply --all) to deploy --all so each component produces its own CI summary entry instead of a single misattributed entry for the last component. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * test: clarify exit code 2 label in deploy hook forwarding test Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * test: use deploy command identity in PostRunE suppression test Same fix as PR #2477: newHookTestCmd() hardcodes Use:"plan" but the test calls deployCmd.PostRunE, causing ProcessCommandLineArgs to see the wrong subcommand name in the non-suppressed path. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * test(deploy): add RunE defer-guard regression test Convert runHooksOnErrorWithOutput to a package-level var so tests can stub it, and add TestDeployRunE_DeferGuard covering all four branches of the deploy.go RunE defer-guard contract: non-nil error must fire the global hook only when wasMultiComponentExecution is false, and nil error must never fire it. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * fix(ci): repair broken merge from main and refactor tests The previous merge from main left the branch unbuildable: - cmd/terraform/utils.go was missing a closing brace on the deploy PerComponentHook branch, producing a Go syntax error - cmd/terraform/utils_hooks_test.go had deploy and apply test bodies interleaved with overlapping function declarations and orphaned statements Reconstruct the test file to host both the deploy tests (this PR) and the apply tests (brought in from main via #2475), and address open CodeRabbit nitpicks at the same time: - Add a compile-time sentinel for schema.ConfigAndStacksInfo so a field rename surfaces as a build failure - Convert plan/deploy/apply demo-stacks tests and the deploy RunE defer-guard scenarios to table-driven subtests - Document why cmd.NewTestKit(t) cannot be used here (circular import between cmd/terraform and cmd, same workaround the workdir tests use) Co-Authored-By: Claude Opus 4.7 <[email protected]> * refactor: narrow test changes to deploy scope and fix comment Code review follow-ups: - Restore the linear style of plan/apply demo-stacks tests to match main; these tests came in via merge and aren't part of this PR's scope. Only the deploy demo-stacks test and the deploy RunE defer-guard scenarios are refactored to table-driven subtests, per the CodeRabbit nitpicks for this PR. - Update the per-component hook wiring comment in utils.go to read "plan, deploy, and apply" now that all three branches are wired. Co-Authored-By: Claude Opus 4.7 <[email protected]> --------- Co-authored-by: Claude Sonnet 4.6 <[email protected]> Co-authored-by: Andriy Knysh <[email protected]>
what
atmos terraform plan --all(and--query,--components, stack-without-component) producing only a single CI summary entry for the last component instead of one entry per componentPerComponentHookcallback toConfigAndStacksInfothat fires after each component executes in multi-component mode, with that component's captured stdout+stderr and exit coderunCIHooksForPlanComponentas the per-component hook for theplansubcommand so$GITHUB_STEP_SUMMARYreceives one entry per component with the correct component/stack contextwasMultiComponentExecutionsentinel so the globalPostRunECI hook call is suppressed when per-component hooks have already fired, preventing double-firingwhy
terraformRunWithOptionsroutes toExecuteTerraformQueryand discards theshellOptscapture buffers passed byplan.go RunE, socapturedPlanOutputwas always emptyPostRunEfired once after all components completed, callingRunCIHookswith an empty output buffer and the last component'sinfo.Component/info.Stack, misattributing the summaryreferences
Closes #2397
Summary by CodeRabbit
New Features
Bug Fixes
Tests