-
-
Notifications
You must be signed in to change notification settings - Fork 656
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
Add setup hook #668
Add setup hook #668
Conversation
Hi @tylermmorton,
Yeah. There's a refactor I have in mind that would benefit both this version: '3'
cmds:
default:
- export FOO=bar
- echo $FOO # has access to previous declared variables For this to be possible, I think we need to refactor the execext package so the For My proposal is to do this refactor alone on its own PR as a POC, and once in master we should work on |
I don't agree with this being an improvement. I think this would result in more confusion, especially given the precedent that no other tool combines cmd lists into a single shell. Not Make, not GitHub actions, not Docker, etc. |
@tylermmorton what I would like to understand in greater clarity is the use case that is solved by combining the separate commands into a single script, that a multiline yaml string cannot easily solve. |
@ghostsquad You bring up a good point that no other tool runs command lists in a single shell. I'm for keeping the precedent consistent across tools. There is also the problem that The use case where you can source an As a specific example, in a monorepo I'm working in, the goal is to have a script that can resolve relative paths and export them as a series of environment variables. Now that I'm thinking about it, perhaps this could be done with the I'm willing to close this and move on. Perhaps a better action item coming out of this is to document solutions for use cases mentioned in #204 |
@tylermmorton ok, sounds good. Ya, try the And if you run into a situation that isn't working, please open a new issue here. |
@ghostsquad So I just tried the build.env
Taskfile.yml version: 3
dotenv:
- ./build.env
tasks:
test:
cmds:
- echo $REPO_ROOT In this case, Obviously .env files are not shell scripts so it makes sense why this won't resolve to anything besides the literal string. But there is a workaround that isn't 100% apparent when reading the usage docs under Environment Variables. env.taskfile.yml version: 3
env:
REPO_ROOT:
sh: git rev-parse --show-toplevel Taskfile.yml version: 3
includes:
env: ./env.taskfile.yml
tasks:
test:
cmds:
- echo $REPO_ROOT This works as you would expect and feels like a good strategy. However, relying on the environment variables here to declare additional variables does not work: env.taskfile.yml version: 3
env:
REPO_ROOT:
sh: git rev-parse --show-toplevel
PROJECT1_ROOT:
sh: $REPO_ROOT/project1 Taskfile.yml version: 3
includes:
env: ./env.taskfile.yml
tasks:
test:
cmds:
- echo $PROJECT1_ROOT Output: stat /project1: no such file or directory
task: Command "$REPO_ROOT/project1" failed: exit status 127 I have not yet dug into the task source to figure out whats going on here. From an outside perspective it seems like the shell that is spawned under the |
I'm not totally sure what's going on in V3 here. My plan in v4 is to lazily evaluate variables. Essentially waiting until they are used before discovering (and caching) the value. This would allow |
I'm working on this in v4. I don't have anything yet that's ready for collaborative work yet. |
The discussion is #694 - but unfortunately, when you mention a discussion from an issue (or vice versa), it only makes a link in the comment, not a reference in the discussion (like it works in issues). |
This PR is in response to issues described in #204. I've modified
RunCommand
to accept a slice of strings to execute in the same shell. Each string in the slice is run throughsyntax.Parser
and the resulting statements are appended to a singlesyntax.File
as if it were a small script.This ultimately results in all commands under
setup
being run before every single command, the advantage here is that they are executed in the same shell.This is a rough draft for this feature. Personally I feel like there could be some performance implications with running setup commands before every single command in a task. I'm open to suggestions/feedback from the community!
It might make more sense to have all commands under a task run in the same shell by using the same strategy applied here, ie appending all commands into one script and passing them all at once to the shell.