Add posix and bash opts for status and precondition commands.#2538
Add posix and bash opts for status and precondition commands.#2538trulede wants to merge 1 commit intogo-task:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to ensure Taskfile set: (POSIX set -o) and shopt: (bash shopt -s) options are consistently applied beyond cmd/cmds, specifically to status, precondition, and if command execution paths, addressing issues where pipefail/other opts were previously ignored.
Changes:
- Plumb POSIX/Bash opts into
execext.RunCommandcalls for task/commandifconditions and task preconditions. - Extend fingerprint status checking to accept and apply POSIX/Bash opts when running
statuscommands. - Thread POSIX/Bash opts into dynamic env var (
env:)sh:evaluation during task compilation.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
variables.go |
Passes effective set/shopt options into dynamic env: sh: evaluation during compilation. |
task.go |
Applies set/shopt to task-level and command-level if: checks; passes opts into fingerprint status evaluation. |
status.go |
Passes Taskfile-level set/shopt into fingerprint status evaluation. |
precondition.go |
Applies set/shopt to preconditions[].sh execution. |
internal/fingerprint/task.go |
Adds functional options to carry POSIX/Bash opts into the default status checker. |
internal/fingerprint/status.go |
Runs status: commands with merged POSIX/Bash opts. |
compiler.go |
Extends dynamic var evaluation API to accept POSIX/Bash opts (but currently supplies empty opts from getVariables). |
Comments suppressed due to low confidence (1)
task.go:176
Ifconditions now receive PosixOpts/BashOpts, but there are no tests asserting thatset:options (notablypipefail) changeif:evaluation/skip behavior. Consider adding coverage for task-levelif:and command-levelif:with a failing pipeline to ensure the opts are actually applied and remain so.
if strings.TrimSpace(t.If) != "" {
if err := execext.RunCommand(ctx, &execext.RunCommandOptions{
Command: t.If,
Dir: t.Dir,
Env: env.Get(t),
PosixOpts: slicesext.UniqueJoin(e.Taskfile.Set, t.Set),
BashOpts: slicesext.UniqueJoin(e.Taskfile.Shopt, t.Shopt),
}); err != nil {
e.Logger.VerboseOutf(logger.Yellow, "task: if condition not met - skipped: %q\n", call.Task)
return nil
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hey Thanks for working on it. // variables.go
Set: slicesext.UniqueJoin(e.Taskfile.Set, origTask.Set),
Shopt: slicesext.UniqueJoin(e.Taskfile.Shopt, origTask.Shopt),Since compiledTask always runs before status checks, preconditions, if, etc., the compiled task already carries the merged opts and all the call just do What do you think ? |
|
@vmaerten I took your suggestion, but it did not help much with A bigger question is if the existing approach was actually correct. Consider this: Should these options be a set/merge of all provided options (taskfile, task, cmd)? Or, should it be an overriding selection, so use cmd.opts if defined, else use task.opts if defined, else use taskfile.opts. I think the latter is more correct, since it makes it possible to disable an earlier/lower setting. For example: |
dc9cfcd to
842f04d
Compare
set/shopts are applied to cmd variants:
fixes #2469
fixes #1901