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

Variables Megathread #2034

Open
pd93 opened this issue Feb 3, 2025 · 2 comments
Open

Variables Megathread #2034

pd93 opened this issue Feb 3, 2025 · 2 comments
Labels
area: variables Changes related to variables.

Comments

@pd93
Copy link
Member

pd93 commented Feb 3, 2025

Description

Now that the ENV_PRECEDENCE experiment is stable, it's about time we do a review of variables and environment variables and their behavior in Task. There are countless issues related to variables in v3 and we're going to be breaking them in the next major release anyway. This is the perfect time to have a think about whether there is anything else that we want to change.

This thread is a rollup issue (megathread, epic, whatever you want to call it) to discuss all variable-related ideas at a high level (no implementation details) so that we can discuss them together and in the context of a breaking change. Individual changes will be linked as child issues.

Here is a (non-exhaustive) list of the discussions that have been had elsewhere

@WinkelCode
Copy link

WinkelCode commented Feb 11, 2025

Something that would be very useful to me personally would be ways to pass information out of a task and/or command. For example, I really like the GitHub Actions approach to this: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/passing-information-between-jobs

Basically, they have a special file that key=value information can be written to, which then becomes a map that can be accessed in subsequent steps. For Task, I imagine this could be done via a single global variable or more granular, by introducing a name: or id: attribute for individual cmds.

On the topic of GitHub Actions-type functionality, I also want to mention conditional task execution based on variables, though this can already be accomplished by using templating in the task name which if it's empty, no task will run.

There are also two issues I want to mention here, both of which are about variable evaluation order becoming unexpectedly non-deterministic in some circumstances: #2058 (with included taskfiles) and #1847 (with .env files). Based on the other issues linked here, I suspect this will probably be addressed, but I still wanted to bring it up directly.

Edit: Passing information from a previous command combined with conditionally running a subsequent one (say with a command-level if: attribute) would be incredibly useful, in my opinion. I also too often up with small scripts in |- blocks because passing information isn't possible between steps.

@nhairs-lumin
Copy link

Posting some feedback here as although there are many more specific env / vars discussion threads, this is the megathread.

I'm a new user to Task. On the surface it looks pretty straight forward to use, but in practice the current state of vars and env is completely doing my head in to the point where I'm probably going to stop attempting to my existing shell scripts until a new version is dropped.

I'll detail my use case in case it helps.

Current Tools

I currently use a very heavily parametrized bash file to act as a template that I can drop into my various repositories. A public version of it can be found here. This is a sample, I have a customised version that I use for my business that does things like interacting with different AWS accounts.

Most parameters are generated from the project and but basically never change, though some are more configurable (e.g. parameters to do with AWS ECR depend on which environment I'm working with).

These parameters get used in all kinds of location, including being written to temporary dotenv files so that others tools (e.g. docker compose) can ingest them.

There are currently ~8 repositories that all work this way.

Taskfile Usage

There's a lot of things from Task to love here:

  • The include system
  • Passing variables and default variables

Misc

While I'm here, this link has a pretty good explainer on how vars / env passing works (at least in the current version 3). Leaving it here for other new people struggling.

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.
Projects
None yet
Development

No branches or pull requests

3 participants