Skip to content

feat: include resolved sources in task templating context#6180

Merged
jdx merged 27 commits intojdx:mainfrom
the-wondersmith:feat/include-sources-in-task-context
Oct 22, 2025
Merged

feat: include resolved sources in task templating context#6180
jdx merged 27 commits intojdx:mainfrom
the-wondersmith:feat/include-sources-in-task-context

Conversation

@the-wondersmith
Copy link
Copy Markdown
Contributor

@the-wondersmith the-wondersmith commented Sep 4, 2025

PR includes the resolved paths of a tasks's sources in its templating context as {{ task_source_files() }}

Example Usage

Given a "project" directory of:

/tmp/mise
├── foo
│   ├── bar.txt
│   ├── baz
│   │   └── qux.example
│   └── quux
│       └── corge.grault
└── mise.toml

and a mise.toml of:

[vars]
target_source_file = "foo/quux/corge.grault"

[tasks.print-task-sources]
description = "Demo the inclusion of task sources in task templating context."
sources = ["**/*.txt", "**/baz/qux.example", "{{ vars.target_source_file }}"]
run = """
{%- for source in task_source_files() -%}
printf "source file: {{ source }}\n"
{%- endfor -%}
"""

mise run print-task-sources yields:

print task sources

Enabling verbose output shows source file resolution (as well as template string pass-through):

source file resolution

Note

Adds a task_source_files() Tera function that resolves a task’s sources (globs, literals, and template strings) and integrates it into script/spec parsing with new tests.

  • Task templating
    • Introduces task_source_files() Tera function to expose resolved task.sources.
    • Resolves glob patterns and literal paths; preserves Tera-like template strings.
  • Parser integration
    • setup_tera_for_spec_parsing now accepts &Task and registers task_source_files.
    • parse_run_scripts and parse_run_scripts_for_spec_only updated to pass task.
  • Tests
    • Adds comprehensive tests for task_source_files() resolution (globs, literals, passthrough, loops), including Windows path handling.
    • Uses rstest for parameterized cases.
  • Dev dependencies
    • Adds rstest in Cargo.toml.

Written by Cursor Bugbot for commit 39b5217. This will update automatically on new commits. Configure here.

Comment thread src/task/mod.rs Outdated
continue;
}

match glob::glob_with(
Copy link
Copy Markdown
Owner

@jdx jdx Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems costly if there are a lot of sources

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we could make this a function instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can make it a function here so the cost would only be paid when this feature is actually used

fn setup_tera_for_spec_parsing(&self) -> TeraSpecParsingResult {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 🙂

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah something like this?

fn setup_tera_for_spec_parsing(&self, task: &Task) -> TeraSpecParsingResult

I think that sounds good

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah something like this?

fn setup_tera_for_spec_parsing(&self, task: &Task) -> TeraSpecParsingResult

I think that sounds good

Exactly 😁. I'll get on it shortly 🫡

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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).

Copy link
Copy Markdown
Contributor Author

@the-wondersmith the-wondersmith Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copilot AI review requested due to automatic review settings September 26, 2025 16:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_files Tera function to resolve task sources during templating
  • Modified setup_tera_for_spec_parsing method to accept task parameter for source resolution
  • Updated all calls to setup_tera_for_spec_parsing to 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.

Comment thread src/task/task_script_parser.rs Outdated
Comment thread src/task/task_script_parser.rs Outdated
Comment thread src/task/task_script_parser.rs
@the-wondersmith the-wondersmith force-pushed the feat/include-sources-in-task-context branch from ef588cc to 0983851 Compare September 26, 2025 18:18
@the-wondersmith the-wondersmith force-pushed the feat/include-sources-in-task-context branch from 0983851 to b8d4123 Compare September 26, 2025 18:27
@the-wondersmith the-wondersmith force-pushed the feat/include-sources-in-task-context branch from d88310c to dc120e1 Compare September 29, 2025 19:52
@jdx
Copy link
Copy Markdown
Owner

jdx commented Oct 5, 2025

bugbot run

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no bugs!


Comment thread Cargo.toml Outdated
Copy link
Copy Markdown
Owner

@jdx jdx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@the-wondersmith the-wondersmith force-pushed the feat/include-sources-in-task-context branch from 1acb941 to 9492849 Compare October 10, 2025 15:24
Signed-off-by: Mark S <the@wondersmith.dev>
@the-wondersmith
Copy link
Copy Markdown
Contributor Author

the-wondersmith commented Oct 10, 2025

Apologies for the unintended closure, the GitHub UI spazzed out on me just now and I must've clicked an unintended button 🤔.

code seems fine, just remove the crate as mentioned

Removed the rstest dependency and refactored the new tests to run without it (as requested 🫡).

@jdx please let me know if there's anything else that needs doing 😁

@jdx
Copy link
Copy Markdown
Owner

jdx commented Oct 18, 2025

this looks good but we'll need to add it to the docs

@the-wondersmith
Copy link
Copy Markdown
Contributor Author

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?

@jdx
Copy link
Copy Markdown
Owner

jdx commented Oct 19, 2025

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.

@jdx jdx marked this pull request as draft October 20, 2025 04:43
@the-wondersmith the-wondersmith marked this pull request as ready for review October 20, 2025 12:27
@the-wondersmith
Copy link
Copy Markdown
Contributor Author

@jdx docs updated, added it to the functions section of the templates page under the "Mise offers additional functions" note.

Comment thread docs/templates.md Outdated
Signed-off-by: Mark S <the@wondersmith.dev>
@the-wondersmith the-wondersmith force-pushed the feat/include-sources-in-task-context branch from c04ad90 to 5b0f82a Compare October 21, 2025 12:36
Copy link
Copy Markdown
Owner

@jdx jdx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good but needs a rebase

…s-in-task-context

# Conflicts:
#	Cargo.lock
#	src/task/task_script_parser.rs
@the-wondersmith
Copy link
Copy Markdown
Contributor Author

@jdx rebased and pushed 😁

@jdx jdx merged commit c083541 into jdx:main Oct 22, 2025
25 of 26 checks passed
jdx pushed a commit that referenced this pull request Oct 23, 2025
### 🚀 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)
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 this pull request may close these issues.

3 participants