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

dir in task is buggy when using variables #1838

Open
ccxuy opened this issue Sep 26, 2024 · 4 comments
Open

dir in task is buggy when using variables #1838

ccxuy opened this issue Sep 26, 2024 · 4 comments

Comments

@ccxuy
Copy link

ccxuy commented Sep 26, 2024

Task version: Task version: v3.38.0 (h1:O7kgA6BfwktXHPrheByQO46p3teKtRuq1EpGnFxNzbo=)
Operating system: Ubuntu 2204
Experiments enabled: No

version: '3'

includes:
  taska:
    taskfile: tmp/a.yml

tasks:
  empty:
    cmds:
      - task: taska:task1
version: '3'

vars:
  location:
    sh: echo "/tmp"

tasks:
  task1:
    dir: "{{.location}}"
    cmds:
      - echo "dir is {{.location}}"
      - pwd
> task empty
task: [taska:task1] echo "dir is /tmp"
dir is /tmp
task: [taska:task1] pwd
/home/xxxx/tmp

I suppose it should be /tmp? If I change to dir: "/{{.location}}", it become what I expect.

  task1:
    dir: "/{{.location}}"
    cmds:
      - echo "dir is {{.location}}"
      - pwd
> task empty
task: [taska:task1] echo "dir is /tmp"
dir is /tmp
task: [taska:task1] pwd
/tmp

also, if I change to:

includes:
  taska: tmp/a.yml

output is also correct:

> task empty
task: [taska:task1] echo "dir is /tmp"
dir is /tmp
task: [taska:task1] pwd
/tmp
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Sep 26, 2024
@pd93
Copy link
Member

pd93 commented Sep 26, 2024

I don't see anything wrong here. LOC is being set to "tmp" which is then being used as a relative directory in none. When you add the leading /, that path becomes absolute instead.

Some more context about what you're trying to do might help.

@pd93 pd93 added state: awaiting response Waiting for issue author to respond. and removed state: needs triage Waiting to be triaged by a maintainer. labels Sep 26, 2024
@ccxuy
Copy link
Author

ccxuy commented Sep 27, 2024

My bad, I posted a wrong example. Sorry for that, and I have update the original post. The bug is sub-task's dir creates a new sub-folder and execute on that new sub-folder, but location is set to /tmp

@task-bot task-bot removed the state: awaiting response Waiting for issue author to respond. label Sep 27, 2024
@ccxuy
Copy link
Author

ccxuy commented Sep 27, 2024

version: '3'

vars:
  LOC: "/tmp"

tasks:
  test:
    dir: "{{.LOC}}/a"
    vars:
      a:
        sh: "echo 1 |grep 1"
    cmds:
      - echo "dir is {{.LOC}}"
      - pwd
> task test
task: Command "echo 1 |grep 1" failed: chdir /a: no such file or directory
Failed at 55: task test

Also, if use sh for variable also behave buggy, looks like the grep command somehow affecte the location, which should be /tmp/a instead of /a

@yonas
Copy link

yonas commented Oct 4, 2024

I'm having the same issue:

> mkdir /tmp/{a,b}
> cd /tmp/a
> task -v
task: [/tmp/a] Not found - Using alternative (Taskfile.yaml)
task: "default" started
task: [default] echo tmpdir = $TMP
tmpdir = /tmp/b
task: [default] echo inside dir $PWD
inside dir /tmp/a
task: "default" finished

Taskfile.yaml

version: '3'

dotenv: [.env]

vars:
  tmpdir: $TMP

tasks:

  default:
    dir: "{{ .tmpdir }}"
    cmds:
      - echo tmpdir = {{ .tmpdir }}
      - echo inside dir $PWD

.env

TMP=/tmp/b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants