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

USER_WORKING_DIR creates unexpected directory #1046

Closed
dvgitit opened this issue Mar 10, 2023 · 2 comments · Fixed by #1309
Closed

USER_WORKING_DIR creates unexpected directory #1046

dvgitit opened this issue Mar 10, 2023 · 2 comments · Fixed by #1309
Labels
area: variables Changes related to variables. type: bug Something not working as intended.

Comments

@dvgitit
Copy link

dvgitit commented Mar 10, 2023

  • Task version: v3.21.0 (h1:pVGAGXxJ9Pk5mvjqv/CsdAD4ZIzNMjF+vrXMueM/WFk=)
  • Operating System: Ubuntu 20.04.5 LTS

Symptoms

Unexpected directory created when using dir: {{.USER_WORKING_DIR}} in a task.

Reproduce

use gist https://gist.github.com/dvgitit/7554e02c75815ac155b3ceb2c283996c

git clone https://gist.github.com/dvgitit/7554e02c75815ac155b3ceb2c283996c test_uwd
cd test_uwd
chmod -R +x *.sh
./create_test_scenario.sh
cd test/test_uwd
./test.sh

directory ../../config/home is unexpected.

@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Mar 10, 2023
@pd93
Copy link
Member

pd93 commented Mar 10, 2023

Hey @dvgitit, thanks for the repro. It really helped me track this down.

What this boils down to: A task's dir field does not currently support variables that contain an absolute path. Using either a variable (with a relative path), or a static absolute path is fine, but the combination is not functioning as intended.


This is the offending line of code:

task.Dir = filepathext.SmartJoin(dir, task.Dir)

Basically, what's happening here is that when we provide filepathext.SmartJoin with a relative path to a task's dir field, we're calling filepath.Join to join it to the directory of the included Taskfile. If it's provided with an absolute path, we just use the given path instead (this is the behaviour that you're expecting).

However, since the task has not been compiled yet, it is not detecting the path as absolute and this means we're treating it as relative and joining /path/to/repo/test_uwd/config with the literal string {{.USER_WORKING_DIR}}.

Later, the task compiler converts this into the full path that you're seeing which makes no sense.


As we're supposed to be supporting variables in a task's dir field, I would consider this to be a bug, but we need to carefully consider how to approach a solution since there is currently no way to tell if the variable is an absolute/relative path in this bit of code.

I've recently been working on a change that will completely overhaul this part of the codebase (dag branch). There might be an easier way to solve this in that refactor. I'll have a think about this and post an update soon.

@pd93 pd93 added type: bug Something not working as intended. area: variables Changes related to variables. and removed state: needs triage Waiting to be triaged by a maintainer. labels Mar 10, 2023
@ghostwheel42
Copy link

I'm currently using dir: "/{{.USER_WORKING_DIR}}" to work around this.

andreynering added a commit that referenced this issue Aug 18, 2023
andreynering added a commit that referenced this issue Aug 18, 2023
Closes #1046
Closes #1205
Closes #1250
Closes #1293
Closes #1274
Closes #1309

Co-authored-by: Marcus Spading <ms@fragmentum.net>
andreynering added a commit that referenced this issue Aug 26, 2023
Closes #1046
Closes #1205
Closes #1250
Closes #1293
Closes #1274
Closes #1309
Closes #1312

Co-authored-by: Marcus Spading <ms@fragmentum.net>
andreynering added a commit that referenced this issue Aug 26, 2023
Closes #1046
Closes #1205
Closes #1250
Closes #1293
Closes #1274
Closes #1309
Closes #1312

Co-authored-by: Marcus Spading <ms@fragmentum.net>
andreynering added a commit that referenced this issue Aug 26, 2023
Closes #1046
Closes #1205
Closes #1250
Closes #1293
Closes #1274
Closes #1309
Closes #1312

Co-authored-by: Marcus Spading <ms@fragmentum.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: variables Changes related to variables. type: bug Something not working as intended.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants