-
-
Notifications
You must be signed in to change notification settings - Fork 637
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
Comments
I don't see anything wrong here. Some more context about what you're trying to do might help. |
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 |
version: '3'
vars:
LOC: "/tmp"
tasks:
test:
dir: "{{.LOC}}/a"
vars:
a:
sh: "echo 1 |grep 1"
cmds:
- echo "dir is {{.LOC}}"
- pwd
Also, if use sh for variable also behave buggy, looks like the grep command somehow affecte the location, which should be |
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 |
Same issue here. The problem arises from code calling filepathext.SmartJoin while the dir content is a variable that has not yet been expanded, therefore the dir is seen as relative even if it may be an absolute path |
Moreover it looks like the current code is working around this issue by using a hack for know-absolute variable: https://github.com/go-task/task/blob/main/internal/filepathext/filepathext.go#L28 IHOM a proper fix to this issue should also lead to remove this hack var knownAbsDirs = []string{
".ROOT_DIR",
".TASKFILE_DIR",
".USER_WORKING_DIR",
}
func isSpecialDir(dir string) bool {
for _, d := range knownAbsDirs {
if strings.Contains(dir, d) {
return true
}
}
return false
} |
Task dir may contain variables with either an absolute or a relative path. Keep track of the dirs instead of trying to join them in order to properly handle variables referencing an absolute PATH Fixes issue go-task#1838
Task version: Task version: v3.38.0 (h1:O7kgA6BfwktXHPrheByQO46p3teKtRuq1EpGnFxNzbo=)
Operating system: Ubuntu 2204
Experiments enabled: No
I suppose it should be /tmp? If I change to
dir: "/{{.location}}"
, it become what I expect.also, if I change to:
output is also correct:
The text was updated successfully, but these errors were encountered: