-
-
Notifications
You must be signed in to change notification settings - Fork 634
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
Cannot correctly modify environment variable PATH for use in task commands #202
Comments
This at least works on Mac OS X: Assuming file structure:
Content of version: "2"
env:
PATH: "{{.PWD}}/bin:{{.PATH}}"
tasks:
foo:
cmds:
- hello-world Content of #!/bin/sh
echo "Hello World!" Running it:
Using task version:
|
No such luck for me (under
|
What if you add version: "2"
env:
PATH: "{{.PWD}}/bin:{{.PATH}}"
tasks:
foo:
cmds:
- echo $PATH
- hello-world |
Still no luck (extended to demonstrate more clearly that
Note, however, that this seems ok with other environment variables:
That is, |
Can you verify if your |
Natively (i.e., in a To be fair I hadn't noticed the difference until now; I'd been using I'd like to highlight part of the behaviour shown in the initial post, repeated here: e:
env:
PATH:
sh: echo "tools;$PATH"
cmds:
- echo "Task e"
- echo $PATH
f:
env:
PATH:
sh: echo "./tools;$PATH"
cmds:
- echo "Task f"
- echo $PATH Output (`WSL):
Output (via
The only difference between these two tasks is the leading These results suggest to me that, fundamentally, the environment variable is correctly being accessed, at least in terms of using its existing value initially. I've just noticed that something funny is going on with regards to the separator in task I've just looked more closely, and the output of task Is something in mvdan/sh at play here? |
@i-am-david-fernandez Sorry, I got out of time in last days to help you with this. I'll catch up once possible to try to understand the problem here. |
When I googled this earlier, I did find that WSL "inherits" the PATH from Windows (can be turned off by a register value apparently, but that sounds messy). From what you are describing, it can look like it's "validating" the paths when doing this. It may look like it doesn't like paths starting with Probably it's a good idea to add only global paths to Otherwise related to the colon v.s. semicolon, what is the output of a task with If it is, perhaps you can utilize the |
You are correct. The output is |
I should note that I've been providing output produced via I apologise if the Here's the output from
I clearly missed that For ease of reference, here is
Changing the method of specifying the
But, perhaps because of the colons, still doesn't ultimately work. |
I think the information you have provided @i-am-david-fernandez, has been very clear and useful, and it's nice that you tried both Obviously the colon replacement of @mvdan, Do you have any input on how |
@i-am-david-fernandez Sorry, I'll take long to debug this since my available time has being low recently, and I don't use Windows often nowadays. I do plan to debug and fix this, though. Just a friendly reminder that @mvdan has no interest in Task, and likely won't digest a long thread like this to understand the problem. If we think we found a problem on mvdan/sh we should try to reproducing it in a small Go script (importing the |
I just did a lot of debugging on this bug on Windows, but I couldn't find the source of the problem. This doesn't seem trivial to fix, specially on Windows which handles some stuff differently than Linux/macOS. My advice is to avoid overriding |
@andreynering Thanks for the effort you've put into this, it's certainly appreciated. Unfortunately, as best as I understand, the Again, thanks for the time and effort. |
I'm going to close this issue then (this doesn't seem to be a common use case). But feel free to add more comments or open other issues if needed, though. |
I'm running into this same thing, but on Linux. My use case: I'd like to append a repo-specific build path to I've tried the (e) iteration at the top of this issue, but I can't get it to work for me. |
Came here via Google, so for reference: Same here, running Linux (Fedora 37 wit Or not :/ might have myt test cases mixed up, sorry… version: '3'
vars:
PYTHON_VERSION:
sh: cat runtime.txt
PATH:
sh: echo $PATH
PYTHON_PATH: '/usr/bin/python{{ trim .PYTHON_VERSION }}'
VENV_PATH: '{{.PWD}}/.venv'
NEW_PATH: "{{.VENV_PATH}}/bin:{{.PATH}}"
env:
PATH: "{{.NEW_PATH}}"
NEW_PATH: "{{.NEW_PATH}}"
tasks:
py:
cmds:
- echo "$NEW_PATH"
- echo "$PATH"
- export PATH="$NEW_PATH"
- echo "$PATH"
- PATH="$NEW_PATH/bin:$PATH" echo $PATH
- echo "({{.PYTHON_VERSION}}) {{.PYTHON_PATH}}" % go-task py
task: [py] echo "$NEW_PATH"
/tmp/test/.venv/bin:/usr/share/Modules/bin:/home/…
task: [py] echo "$PATH"
/usr/share/Modules/bin:/home/…
task: [py] export PATH="$NEW_PATH"
task: [py] echo "$PATH"
/usr/share/Modules/bin:/home/…
task: [py] PATH="$NEW_PATH/bin:$PATH" echo $PATH
/usr/share/Modules/bin:/home/…
task: [py] echo "(3.11) /usr/bin/python3.11"
(3.11) /usr/bin/python3.11 Probably b/c #482 |
For whoever lands here from searching, this behavior is (most likely) caused by #1038 |
Hello. Firstly, thank-you for Task. It has, overall, made my development life easier and more pleasant.
I don't know if the problem I have is a bug or if I simply don't understand the correct way to achieve my goal. I'd like to be able to modify the environment variable
PATH
(either prepending or appending a project-specific directory to the existing value), but I can't figure out how to do this using the set of commands available withinTaskfiles
.To provide context, my
Taskfile
is for use in building go applications. Some applications (projects) require project-specific build tools/helpers that I place in a top-leveltools
subdirectory (i.e.,<project name>/tools
). Note that myTaskfile
resides at<project name>/Taskfile.yml
. I wish to use thego generate
command, which effectively requires that external generation tools be accessible viaPATH
, so I must add<project name>/tools
toPATH
before runninggo generate
in the task.While I'm working in Windows, I'm making effective use of busybox-w32 to provide a fairly comprehensive set of what are otherwise Linux tools, so things like
cp
,echo
andrealpath
are available. I've also tried this viaWSL
such that things are more like a real Linux environment, with the same results.The output I get from the above Taskfile (when run under
sh
orbash
viaWSL
) is as follows (results in native Windows are the same):Tasks
a
,b
,c
andd
are just simple tests; it's taskse
,f
andg
that illustrate the real issue. Taske
works correctly, prependingtools
to the currentPATH
, but neitherf
norg
have any effect. Taskg
is the closest to what I need in terms of operations (i.e., adding the absolute path of a project-specific directory).I'd greatly appreciate any input you could provide on this issue. Thanks in advance.
The text was updated successfully, but these errors were encountered: