Closed robcao closed 1 month ago
I believe this was the change that introduced the behavior change: https://github.com/go-task/task/pull/1762
I pulled down the commit before the change: git co 35119c12ab222fc5a2a1d28536f5e575136e103e
, and validated that the command works as expected on this commit via task my-repro
.
Pulling down the change: git co b259edeb65e24f28c41604b9819869aca082d3b6
and running the task my-repro
shows the erroneous behavior
I have the same problem. However, I have been able to pass variables to defer for some time now, but it seems that was not correct in the schema, so I am having trouble.
+1
v3.39.0 (h1:Loe6ppP1x38Puv1M2wigp91bH/garCt0vLWkJsiTWNI=)
Linux ubuntu20 6.8.0-40-generic #40~22.04.3-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 30 17:30:19 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
ENV_PRECEDENCE GENTLE_FORCE REMOTE_TASKFILES
This seems like a major regression that should have been caught by a test case.
All my defer: rm -f "{{.VAR}}"
statements are now evaluating to rm -f ""
🙃
Just updated to Task version: v3.39.1 (h1:yIaLD5TZWXU/SdmadBReQKu8jblRxzRT+lJG4xC3CMw=) but I still have the same issue
@kevintijssen are you sure? I just updated and it works fine on linux/amd64
(which I think you're using from your version hash) ...
# Taskfile.1803.yml
version: "3"
vars:
FILE_VAR: "file-issue-1803"
tasks:
repro:
vars:
TASK_VAR: "task-issue-1803"
cmds:
- defer: rmdir "{{.FILE_VAR}}"
- defer: rmdir "{{.TASK_VAR}}"
- mkdir -p "{{.FILE_VAR}}"
- mkdir -p "{{.TASK_VAR}}"
❯ task -t Taskfile.1803.yml repro
task: [repro] mkdir -p "file-issue-1803"
task: [repro] mkdir -p "task-issue-1803"
task: [repro] rmdir "task-issue-1803"
task: [repro] rmdir "file-issue-1803"
v3.39.1 (h1:yIaLD5TZWXU/SdmadBReQKu8jblRxzRT+lJG4xC3CMw=)
Linux ubuntu20 6.8.0-40-generic #40~22.04.3-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 30 17:30:19 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
ENV_PRECEDENCE GENTLE_FORCE REMOTE_TASKFILES
Task version: v3.39.1 (h1:yIaLD5TZWXU/SdmadBReQKu8jblRxzRT+lJG4xC3CMw=) Linux 828aaae9a89d 6.4.16-linuxkit #1 SMP PREEMPT Fri Nov 10 14:49:23 UTC 2023 aarch64 GNU/Linux
wait-for:
desc: "Will wait for resources to gain the requested condition."
deps:
- task: check-tools
requires:
vars:
- RESOURCE
- CONDITION
vars:
CONDITIONAL_ARGUMENTS: "{{if .KUBECONTEXT}}--context={{.KUBECONTEXT}} {{end}} {{if .NAMESPACE}} --namespace={{.NAMESPACE}} {{end}}"
TEMP_FILE:
sh: mktemp
cmds:
- defer: rm {{.TEMP_FILE}}
- cmd: |
cat > {{.TEMP_FILE}} <<EOF
until kubectl {{.CONDITIONAL_ARGUMENTS}} get {{.RESOURCE}} &> /dev/null; do
sleep 2
done
{{- if ne .CONDITION "exists"}}
kubectl {{ .CONDITIONAL_ARGUMENTS }} wait --for condition={{.CONDITION}} {{.RESOURCE}} --timeout 500s
{{end}}
EOF
- task: execute-bash
vars:
GUM_SPIN_TITLE: "{{.GUM_SPIN_TITLE}}"
TEMP_FILE: "{{.TEMP_FILE}}"
- cmd: gum log --level info "{{.RESOURCE}} condition {{.CONDITION}} met"
INFO deployment/coredns condition available met
task: "dev:k3d:utils:wait-for" finished
task: [dev:k3d:utils:wait-for] rm
rm: missing operand
Try 'rm --help' for more information.
task: ignored error in deferred cmd: exit status 1
Looks like the bug is partially fixed 🙈
@andreynering @vmaerten the fix in #1814 doesn't seem to support dynamic vars
# Taskfile.1803.yml
version: "3"
vars:
FILE_VAR: "file-issue-1803"
tasks:
repro:
vars:
TASK_VAR: "task-issue-1803"
SH_TASK_VAR:
sh: echo "sh-task-issue-1803"
cmds:
- defer: rmdir "{{.FILE_VAR}}"
- defer: rmdir "{{.TASK_VAR}}"
- defer: rmdir "{{.SH_TASK_VAR}}"
- mkdir -p "{{.FILE_VAR}}"
- mkdir -p "{{.TASK_VAR}}"
- mkdir -p "{{.SH_TASK_VAR}}"
❯ task -t Taskfile.1803.yml repro
task: [repro] mkdir -p "file-issue-1803"
task: [repro] mkdir -p "task-issue-1803"
task: [repro] mkdir -p "sh-task-issue-1803"
task: [repro] rmdir ""
rmdir: failed to remove '': No such file or directory
task: [repro] rmdir "task-issue-1803"
task: [repro] rmdir "file-issue-1803"
❯ test -d sh-task-issue-1803 && echo 'directory still exists :('
directory still exists :(
You're totally right. I've opened another PR to fix this!
woohoo! 🚀
❯ task --version
Task version: v3.39.2 (h1:Zt7KXHmMNq5xWZ1ihphDb+n2zYLCo4BdRe09AnMMIgA=)
❯ task -t Taskfile.1803.yml repro
task: [repro] mkdir -p "file-issue-1803"
task: [repro] mkdir -p "task-issue-1803"
task: [repro] mkdir -p "sh-task-issue-1803"
task: [repro] rmdir "sh-task-issue-1803"
task: [repro] rmdir "task-issue-1803"
task: [repro] rmdir "file-issue-1803
Thanks @vmaerten for the quick turn around on this 💪
It's still broken on snapcraft.io stable channel. It doesn't seem to make sense for me to manually switch to the edge channel for this snap to get a working version, or no?!
@cwegener I just released on Snapcraft. Sorry, it was just forgotten.
Thanks! The stable snapcraft channel works again now..
defer
is no longer evaluating variables in task 3.39.0. In the sampleTaskfile.yml
below, I've created a simple reproduction.To reproduce:
Run
task my-repro
with the taskfile below.See the following output is
Expected behavior (+ the behavior on v3.38.0):