Repository navigation
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6e7c0f2de3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR adds a mechanism for hooks to pass data back to Kamal by writing KEY=VALUE pairs to a file specified by the $KAMAL_OUTPUT environment variable. Hook outputs accumulate across the deploy lifecycle and are made available to subsequent hooks through environment variables, with a proper precedence order ensuring secrets and built-in tags cannot be overridden.
Changes:
- New
Kamal::HookOutputclass manages temporary file lifecycle and parses dotenv-formatted output - Hook outputs accumulate in
Commander#hook_outputsand are passed to subsequent hooks viaCommands::Hook#env - Special
KAMAL_MESSAGEkey is displayed to users after hook completion
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/kamal/hook_output.rb | New class for managing hook output tempfile and parsing dotenv format |
| lib/kamal/cli/base.rb | Creates HookOutput, passes path to hooks, parses output, displays messages, ensures cleanup |
| lib/kamal/commander.rb | Adds hook_outputs accumulator and merge_hook_output method |
| lib/kamal/commands/hook.rb | Merges accumulated hook outputs into hook environment with correct precedence (secrets > tags > hook_outputs) |
| lib/kamal/cli/templates/sample_hooks/*.sample | Documents KAMAL_OUTPUT environment variable availability |
| test/hook_output_test.rb | Comprehensive unit tests for HookOutput parsing and cleanup |
| test/commands/hook_test.rb | Tests for hook environment with hook_outputs and precedence rules |
| test/commander_test.rb | Tests for hook_outputs accumulation behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Hooks are fire-and-forget today: exit code is the only feedback channel. This adds a file-based output channel so hooks can set variables that Kamal reads back. Before each hook, Kamal creates a tempfile and passes its path as KAMAL_OUTPUT. The hook writes dotenv-format KEY=VALUE lines. Kamal parses them after the hook exits and accumulates them on Commander, merging into the env for subsequent hooks. A pre-deploy hook that writes DEPLOY_ID=123 makes $DEPLOY_ID available to post-deploy. KAMAL_MESSAGE is special: if present, Kamal prints it regardless of verbosity settings, giving hooks a dedicated user-facing output channel separate from stdout logging. Backward-compatible: hooks that don't write to KAMAL_OUTPUT behave identically to today.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Summary
KEY=VALUElines (dotenv format) to the file at$KAMAL_OUTPUTKAMAL_MESSAGEis printed to the user after the hook completespre-deployhook that writesDEPLOY_ID=123makes$DEPLOY_IDavailable topost-deploy$KAMAL_OUTPUTbehave identically to beforeFiles
lib/kamal/hook_output.rb— new: tempfile lifecycle + dotenv parsinglib/kamal/cli/base.rb—run_hookcreates HookOutput, passesKAMAL_OUTPUT, parses output, printsKAMAL_MESSAGE, cleans up inensurelib/kamal/commander.rb—hook_outputsaccumulator,merge_hook_outputlib/kamal/commands/hook.rb— merge accumulated hook outputs into hook env with correct precedenceKAMAL_OUTPUTTest plan
test/hook_output_test.rb— 7 tests: parse, cleanup, empty file, quoted values, path accesstest/commander_test.rb— 3 new tests: starts empty, accumulates, overwritestest/commands/hook_test.rb— 3 new tests: env with hook_outputs, cannot override tags, cannot override secrets