feat: include resolved sources in task templating context#6180
feat: include resolved sources in task templating context#6180
Conversation
| continue; | ||
| } | ||
|
|
||
| match glob::glob_with( |
There was a problem hiding this comment.
this seems costly if there are a lot of sources
There was a problem hiding this comment.
maybe we could make this a function instead?
There was a problem hiding this comment.
maybe we could make this a function instead?
Apologies for the confusion. Do you mean the... match block? Or "make source resolution its own function"?
There was a problem hiding this comment.
FTR, I 100% agree that the implementation could be costly if there are a lot of sources, I just couldn't figure a better place for it. I did find the Run::sources_are_fresh method that seems to do something similar, but I had so much trouble figuring out where in the order of things it actually got called that I gave up and settled for this on the premise that it'd be better to get the idea out and then solicit input from someone more familiar with the mise codebase 😅.
tl;dr the feature would be hugely helpful to have I think, I'm just not 100% sure where it's best added and was hoping for guidance from the mise team.
There was a problem hiding this comment.
you can make it a function here so the cost would only be paid when this feature is actually used
mise/src/task/task_script_parser.rs
Line 114 in 5c2f066
There was a problem hiding this comment.
I went and took a pass at moving source file resolution to being a tera function, and it's actually super reasonable. I've got it working on this branch, I just haven't committed it (as I wanted some feedback before I pushed up the changes).
I think the only unclear part is how the task's sources are passed to the function. At the moment, I left the addition of task.sources to the tera context in place, and implemented exactly as you see it in the comment's example - {%- for source in resolve(task.sources) -%}.
If I'm interpreting correctly though, you probably agree that that seems a bit... ugly. Ideally, the function would just be something like task_source_files() (or whatever your preference is) and users would be able to call it as {%- for source in task_source_files() -%}. Is that more in line with what you were thinking?
Assuming it is, I just need some guidance on how you'd prefer to have the task sources made available to setup_tera_spec_for_parsing. In short - setup_... is only called in two specific places (here and here). Both of the places it calls have access to the Task being run, so that's obviously ideal. The simplest, most straight-forward way I can think of to do it would be to just straight up pass a reference to Task.sources to setup_tera_spec_for_parsing (i.e. change setup_tera_spec_for_parsing's signature from fn setup_tera_for_spec_parsing(&self) -> TeraSpecParsingResult to fn setup_tera_for_spec_parsing(&self, sources: &[String]) -> TeraSpecParsingResult and then just capture the passed sources in the closure registered with tera. That seems like setting things up to get out of hand in the future though, if/as more templating functions are added that want/need context from their associated task. It feels like it'd be better to do it as fn setup_tera_for_spec_parsing(&self, task: &Task) -> TeraSpecParsingResult.
Thoughts? If there aren't any objections to passing the task along to the setup method, I can get that done today or tomorrow, FWIW 🙂
There was a problem hiding this comment.
yeah something like this?
fn setup_tera_for_spec_parsing(&self, task: &Task) -> TeraSpecParsingResultI think that sounds good
There was a problem hiding this comment.
yeah something like this?
fn setup_tera_for_spec_parsing(&self, task: &Task) -> TeraSpecParsingResultI think that sounds good
Exactly 😁. I'll get on it shortly 🫡
There was a problem hiding this comment.
@jdx Do you happen to have an opinion on the name of the registered function? I think it'll be the first like... task-oriented template function in mise (i.e. template functions that rely on / implement reflection of the task definition in which they are called). Seems like a good idea to set a standard (start as we mean to proceed sorta deal).
There was a problem hiding this comment.
@jdx Okie doke, got it all reimplemented as a tera template function task_source_files. Obviously happy to change the registered function name if/as needed 😅.
Give it a look over, whenever you have time? Eager to hear your thoughts.
There was a problem hiding this comment.
Pull Request Overview
This PR adds task source file resolution to the Tera templating context, allowing tasks to access their resolved source files through {{ task.sources }} in templates. The feature resolves glob patterns and template strings from the task's sources configuration into actual file paths.
- Added
task_source_filesTera function to resolve task sources during templating - Modified
setup_tera_for_spec_parsingmethod to accept task parameter for source resolution - Updated all calls to
setup_tera_for_spec_parsingto pass task context
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/task/task_script_parser.rs | Implements task source file resolution logic and updates method signatures |
| src/task/mod.rs | Minor formatting change (added blank line) |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
ef588cc to
0983851
Compare
0983851 to
b8d4123
Compare
Signed-off-by: Mark S <the@wondersmith.dev>
d88310c to
dc120e1
Compare
|
bugbot run |
jdx
left a comment
There was a problem hiding this comment.
code seems fine, just remove the crate as mentioned
Signed-off-by: Mark S <the@wondersmith.dev>
Signed-off-by: Mark S <the@wondersmith.dev>
1acb941 to
9492849
Compare
…s-in-task-context # Conflicts: # Cargo.lock
Signed-off-by: Mark S <the@wondersmith.dev>
|
Apologies for the unintended closure, the GitHub UI spazzed out on me just now and I must've clicked an unintended button 🤔.
Removed the @jdx please let me know if there's anything else that needs doing 😁 |
Signed-off-by: Mark S <the@wondersmith.dev>
|
this looks good but we'll need to add it to the docs |
Is that a pre-merge task? If so, where/how would one accomplish it? |
|
yeah, otherwise nobody will know where this is. I don't know if we have a section on templates for tasks or not, if we do that would be the right place. Alternatively it could go in the templating doc. |
Signed-off-by: Mark S <the@wondersmith.dev>
|
@jdx docs updated, added it to the |
Signed-off-by: Mark S <the@wondersmith.dev>
c04ad90 to
5b0f82a
Compare
…s-in-task-context # Conflicts: # Cargo.lock # src/task/task_script_parser.rs
|
@jdx rebased and pushed 😁 |
### 🚀 Features - **(tasks)** modify usage spec parsing to return dummy strings by @iamkroot in [#6723](#6723) - include resolved sources in task templating context by @the-wondersmith in [#6180](#6180) - Add Tera function `absolute` by @iamkroot in [#6729](#6729) ### 🐛 Bug Fixes - **(cli)** respect os filter during upgrade by @iamkroot in [#6724](#6724) ### 📚 Documentation - fix RUNTIME.osType values in example snippet by @ofalvai in [#6732](#6732) - migrate issue links to GitHub discussions by @jdx in [#6740](#6740) - document Lua version by @ofalvai in [#6741](#6741) ### New Contributors - @ofalvai made their first contribution in [#6741](#6741) - @iamkroot made their first contribution in [#6729](#6729) - @the-wondersmith made their first contribution in [#6180](#6180) ## 📦 Aqua Registry Updates #### New Packages (8) - [`SUPERCILEX/fuc/cpz`](https://github.com/SUPERCILEX/fuc/cpz) - [`SUPERCILEX/fuc/rmz`](https://github.com/SUPERCILEX/fuc/rmz) - [`dinoDanic/diny`](https://github.com/dinoDanic/diny) - [`eth-p/bat-extras`](https://github.com/eth-p/bat-extras) - [`k1LoW/tailor-log`](https://github.com/k1LoW/tailor-log) - [`mashiike/acrun`](https://github.com/mashiike/acrun) - [`opengrep/opengrep`](https://github.com/opengrep/opengrep) - [`praetorian-inc/noseyparker`](https://github.com/praetorian-inc/noseyparker) #### Updated Packages (2) - [`bufbuild/buf`](https://github.com/bufbuild/buf) - [`bytecodealliance/wasm-tools`](https://github.com/bytecodealliance/wasm-tools)
PR includes the resolved paths of a tasks's
sourcesin its templating context as{{ task_source_files() }}Example Usage
Given a "project" directory of:
and a
mise.tomlof:mise run print-task-sourcesyields:Enabling verbose output shows source file resolution (as well as template string pass-through):
Note
Adds a
task_source_files()Tera function that resolves a task’ssources(globs, literals, and template strings) and integrates it into script/spec parsing with new tests.task_source_files()Tera function to expose resolvedtask.sources.setup_tera_for_spec_parsingnow accepts&Taskand registerstask_source_files.parse_run_scriptsandparse_run_scripts_for_spec_onlyupdated to passtask.task_source_files()resolution (globs, literals, passthrough, loops), including Windows path handling.rstestfor parameterized cases.rstestinCargo.toml.Written by Cursor Bugbot for commit 39b5217. This will update automatically on new commits. Configure here.