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

dynamic variables evaluated twice #2063

Open
mpeim opened this issue Feb 14, 2025 · 0 comments
Open

dynamic variables evaluated twice #2063

mpeim opened this issue Feb 14, 2025 · 0 comments
Labels
state: needs triage Waiting to be triaged by a maintainer.

Comments

@mpeim
Copy link

mpeim commented Feb 14, 2025

What did I do?

While writing a task file, I wanted to have a variable A having a value depending on the value of another B that could be passed by the user when calling the task.
I wanted to have a third variable C to use to use the resulting value of A.
The whole taskfile is then imported in another one.

What happened?

Depending on the position of B in the command line, C would be evaluated twice with two different values of A.
This only occurs if the first example.

First example:

included.yml

version: '3.41'

vars:
  A: '{{.B | default (.A | default "nope")}}'
  C:
    sh: echo {{.A}}

tasks:
  test: echo {{.C}}

task.yml

version: '3.41'

includes:
  fail:
    taskfile: ./include.yml

Execution:

# executed two times
$ task fail:test -v B=two
task: [/home/mpeim.linux/debug-taskfiles] Not found - Using alternative (taskfile.yml)
task: dynamic variable: "echo nope" result: "nope"
task: dynamic variable: "echo two" result: "two"
task: "fail:test" started
task: [fail:test] echo "two"
two
task: "fail:test" finished

$ B=one task fail:test -v
task: [/home/mpeim.linux/debug-taskfiles] Not found - Using alternative (taskfile.yml)
task: dynamic variable: "echo one" result: "one"
task: "fail:test" started
task: [fail:test] echo "one"
one
task: "fail:test" finished

Second example:

include.yml stays the same.

taskfile.yml

version: '3.41'

# note that the field `taskfile` is not given
includes:
  fail: ./include.yml

Execution:

$ task fail:test -v B=yup
task: [/home/mpeim.linux/debug-taskfiles] Not found - Using alternative (taskfile.yml)
task: dynamic variable: "echo nope" result: "nope"
task: "fail:test" started
task: [fail:test] echo "nope"
nope
task: "fail:test" finished

$ B=one task fail:test -v
task: [/home/mpeim.linux/debug-taskfiles] Not found - Using alternative (taskfile.yml)
task: dynamic variable: "echo one" result: "one"
task: "fail:test" started
task: [fail:test] echo "one"
one
task: "fail:test" finished

Expectated behavior

I would expect the dynamic variable to be executed once in every case.

Version

3.41

Operating system

Linux lima-vpp3 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:36 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux

Experiments Enabled

With and without TASK_X_MAP_VARIABLES=1

@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: needs triage Waiting to be triaged by a maintainer.
Projects
None yet
Development

No branches or pull requests

2 participants