Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3.39.0] defer no longer evaluates variables #1803

Closed
robcao opened this issue Sep 11, 2024 · 10 comments · Fixed by #1814 or #1818
Closed

[v3.39.0] defer no longer evaluates variables #1803

robcao opened this issue Sep 11, 2024 · 10 comments · Fixed by #1814 or #1818
Assignees
Labels
type: bug Something not working as intended.

Comments

@robcao
Copy link

robcao commented Sep 11, 2024

defer is no longer evaluating variables in task 3.39.0. In the sample Taskfile.yml below, I've created a simple reproduction.

To reproduce:

Run task my-repro with the taskfile below.

See the following output is

my-value

Expected behavior (+ the behavior on v3.38.0):

my-value
my-value
# https://taskfile.dev

version: '3'
silent: true
tasks:
  my-repro:
    cmds:
      - defer: echo {{ .MY_VAR }}
      - echo {{ .MY_VAR }}
    vars:
      MY_VAR: my-value
  • Task version: 3.39.0
  • Operating system: wsl2/ubuntu22.04, Shell: GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
  • Experiments enabled:
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Sep 11, 2024
@robcao
Copy link
Author

robcao commented Sep 11, 2024

I believe this was the change that introduced the behavior change: #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

@officel
Copy link

officel commented Sep 16, 2024

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.

go-task/vscode-task#158

@mgbowman
Copy link

+1

  • Task version: v3.39.0 (h1:Loe6ppP1x38Puv1M2wigp91bH/garCt0vLWkJsiTWNI=)
  • Operating system: 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
  • Experiments enabled: ENV_PRECEDENCE GENTLE_FORCE REMOTE_TASKFILES

@mgbowman
Copy link

mgbowman commented Sep 18, 2024

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 "" 🙃

@andreynering andreynering self-assigned this Sep 18, 2024
@andreynering andreynering added type: bug Something not working as intended. and removed state: needs triage Waiting to be triaged by a maintainer. labels Sep 18, 2024
@kevintijssen
Copy link

Just updated to Task version: v3.39.1 (h1:yIaLD5TZWXU/SdmadBReQKu8jblRxzRT+lJG4xC3CMw=) but I still have the same issue

@mgbowman
Copy link

@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"
  • Task version: v3.39.1 (h1:yIaLD5TZWXU/SdmadBReQKu8jblRxzRT+lJG4xC3CMw=)
  • Operating system: 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
  • Experiments enabled: ENV_PRECEDENCE GENTLE_FORCE REMOTE_TASKFILES

@kevintijssen
Copy link

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

@mgbowman
Copy link

mgbowman commented Sep 19, 2024

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 :(

@vmaerten
Copy link
Member

You're totally right.
I've opened another PR to fix this!

@mgbowman
Copy link

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 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something not working as intended.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants