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

includes doesn't interpolate paths #942

Closed
fatmcgav-depop opened this issue Nov 23, 2022 · 5 comments · Fixed by #943
Closed

includes doesn't interpolate paths #942

fatmcgav-depop opened this issue Nov 23, 2022 · 5 comments · Fixed by #943

Comments

@fatmcgav-depop
Copy link

fatmcgav-depop commented Nov 23, 2022

Hi there

Firstly, I'm not sure if this is strictly a bug or a feature request.
However the docs mention that it's possible to interpolate using the {{OS}} value, so I'd expect to be able to use other vars...

Anyhow, I've got a setup that leverages the includes functionality to dynamically include another Taskfile.
The challenge is that the path to that downstream taskfile varies based on user input.

E.g.

---
version: "3"

vars:
  MODULE_NAME:
    sh: jq -r .module_name cookiecutter.json

includes:
  # Support running tasks defined in the generated template module
  generated:
    taskfile: './cookiecutter-temp/{{ .MODULE_NAME }}'
    dir: './cookiecutter-temp/{{ .MODULE_NAME }}'
    optional: true

However the tasks don't get loaded by task.

If I replace {{.MODULE_NAME}} in the above with a "qualified" location then the includes work as expected:

task -l |grep generated
* generated:deps:               Install required dependencies
* generated:go-mod:             Downloads and tidy Go modules
* generated:pre-commit-install: Add `pre-commit` hook
* generated:python-deps:        Install required python dependencies in a virtualenv
* generated:terraform:          Set up and validate the Terraform Module
* generated:terraform-checkov:  Analyise the Terraform Configuration
* generated:terraform-docs:     Update the README.md file
* generated:terraform-e2e:      Run the Terraform integration test suite
* generated:terraform-fmt:      Format the Terraform module code
* generated:terraform-init:     Initialize the Terraform environment
* generated:terraform-validate: Validate the Terraform module code
* generated:test:               Run tests.
* generated:test-go:            Run tests for all Go code.
  • Task version: 3.18.0
  • Operating System: MacOS 12
@github-actions github-actions bot added the state: needs triage Waiting to be triaged by a maintainer. label Nov 23, 2022
@pd93
Copy link
Member

pd93 commented Nov 23, 2022

Looks like a bug to me unless I'm missing something. See #943

@pd93 pd93 added type: bug Something not working as intended. and removed state: needs triage Waiting to be triaged by a maintainer. labels Nov 23, 2022
@fatmcgav-depop
Copy link
Author

Looks like a bug to me unless I'm missing something. See #943

🍠 Thanks for the lightning fix!

@fatmcgav-depop
Copy link
Author

Hey...

So unfortunately it looks like the fix in #943 is only partial.
It works fine for "static" vars, but when I try and use a "dynamic" var as per my above example, it fails...

$ task -l
stat $HOME/cookiecutter-temp/Taskfile.yaml: no such file or directory

Any ideas?
Happy to open a new issue if easier...

@pd93
Copy link
Member

pd93 commented Dec 7, 2022

Had a very quick look at this. When replicating your issue, I only used a static variable, so didn't catch the problem with dynamic variables.

Unfortunately, it seems like handling dynamic variables is going to be much less simple than the fix for static variables. Currently, dynamic variables are resolved by the compiler and this runs when a task is being evaluated. This is significantly after included taskfiles are evaluated.

At the moment it doesn't look like dynamic variables are supported in any of the global keywords (i.e. outside of tasks:). Some thought would need to go into how to handle this best.

A new issue would be great as comments on closed issues tend to get forgotten otherwise. Please reference this issue in your new one though!

@fatmcgav-depop
Copy link
Author

A new issue would be great as comments on closed issues tend to get forgotten otherwise. Please reference this issue in your new one though!

Opened #951

@pd93 pd93 removed the type: bug Something not working as intended. label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants