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

feat(tasks): allow mise-tasks or .mise-tasks directories #2610

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,8 @@ In .mise.toml, tasks take this form:
outputs = ["dist/**/*.js"]

Alternatively, tasks can be defined as standalone scripts.
These must be located in the `.mise/tasks`, `mise/tasks` or `.config/mise/tasks` directory.
These must be located in `mise-tasks`, `.mise-tasks`, `.mise/tasks`, `mise/tasks` or
`.config/mise/tasks`.
The name of the script will be the name of the tasks.

$ cat .mise/tasks/build<<EOF
Expand Down Expand Up @@ -1478,7 +1479,8 @@ In .mise.toml, tasks take this form:
outputs = ["dist/**/*.js"]

Alternatively, tasks can be defined as standalone scripts.
These must be located in the `.mise/tasks`, `mise/tasks` or `.config/mise/tasks` directory.
These must be located in `mise-tasks`, `.mise-tasks`, `.mise/tasks`, `mise/tasks` or
`.config/mise/tasks`.
The name of the script will be the name of the tasks.

$ cat .mise/tasks/build<<EOF
Expand Down
3 changes: 2 additions & 1 deletion docs/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ In .mise.toml, tasks take this form:
outputs = ["dist/**/*.js"]

Alternatively, tasks can be defined as standalone scripts.
These must be located in the `.mise/tasks`, `mise/tasks` or `.config/mise/tasks` directory.
These must be located in `mise-tasks`, `.mise-tasks`, `.mise/tasks`, `mise/tasks` or
`.config/mise/tasks`.
The name of the script will be the name of the tasks.

$ cat .mise/tasks/build<<EOF
Expand Down
3 changes: 2 additions & 1 deletion docs/cli/tasks/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ In .mise.toml, tasks take this form:
outputs = ["dist/**/*.js"]

Alternatively, tasks can be defined as standalone scripts.
These must be located in the `.mise/tasks`, `mise/tasks` or `.config/mise/tasks` directory.
These must be located in `mise-tasks`, `.mise-tasks`, `.mise/tasks`, `mise/tasks` or
`.config/mise/tasks`.
The name of the script will be the name of the tasks.

$ cat .mise/tasks/build<<EOF
Expand Down
11 changes: 9 additions & 2 deletions docs/tasks/script-tasks.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Script Tasks

In addition to defining tasks through the configuration, they can also be defined as standalone script files in
`.mise/tasks/:task_name` such as the following build script for cargo:
In addition to defining tasks through the configuration, they can also be defined as standalone script files in one of the following directories:

* `mise-tasks/:task_name`
* `.mise-tasks/:task_name`
* `mise/tasks/:task_name`
* `.mise/tasks/:task_name`
* `.config/mise/tasks/:task_name`

Here is an example of a script task that builds a Rust CLI:

```bash
#!/usr/bin/env bash
Expand Down
6 changes: 4 additions & 2 deletions mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,8 @@ In .mise.toml, tasks take this form:
outputs = ["dist/**/*.js"]

Alternatively, tasks can be defined as standalone scripts.
These must be located in the `.mise/tasks`, `mise/tasks` or `.config/mise/tasks` directory.
These must be located in `mise-tasks`, `.mise-tasks`, `.mise/tasks`, `mise/tasks` or
`.config/mise/tasks`.
The name of the script will be the name of the tasks.

$ cat .mise/tasks/build<<EOF
Expand Down Expand Up @@ -1064,7 +1065,8 @@ In .mise.toml, tasks take this form:
outputs = ["dist/**/*.js"]

Alternatively, tasks can be defined as standalone scripts.
These must be located in the `.mise/tasks`, `mise/tasks` or `.config/mise/tasks` directory.
These must be located in `mise-tasks`, `.mise-tasks`, `.mise/tasks`, `mise/tasks` or
`.config/mise/tasks`.
The name of the script will be the name of the tasks.

$ cat .mise/tasks/build<<EOF
Expand Down
3 changes: 2 additions & 1 deletion src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ use super::args::ToolArg;
/// outputs = ["dist/**/*.js"]
///
/// Alternatively, tasks can be defined as standalone scripts.
/// These must be located in the `.mise/tasks`, `mise/tasks` or `.config/mise/tasks` directory.
/// These must be located in `mise-tasks`, `.mise-tasks`, `.mise/tasks`, `mise/tasks` or
/// `.config/mise/tasks`.
/// The name of the script will be the name of the tasks.
///
/// $ cat .mise/tasks/build<<EOF
Expand Down
2 changes: 2 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@ impl Debug for Config {

fn default_task_includes() -> Vec<PathBuf> {
vec![
"mise-tasks".into(),
".mise-tasks".into(),
".mise/tasks".into(),
".config/mise/tasks".into(),
"mise/tasks".into(),
Expand Down
10 changes: 10 additions & 0 deletions src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ fn name_from_path(root: impl AsRef<Path>, path: impl AsRef<Path>) -> Result<Stri
.as_ref()
.strip_prefix(root)
.map(|p| match p {
p if p.starts_with("mise-tasks") => p.strip_prefix("mise-tasks"),
p if p.starts_with(".mise-tasks") => p.strip_prefix(".mise-tasks"),
p if p.starts_with(".mise/tasks") => p.strip_prefix(".mise/tasks"),
p if p.starts_with("mise/tasks") => p.strip_prefix("mise/tasks"),
p if p.starts_with(".config/mise/tasks") => p.strip_prefix(".config/mise/tasks"),
Expand Down Expand Up @@ -332,6 +334,14 @@ impl TreeItem for (&Graph<Task, ()>, NodeIndex) {

fn config_root(config_source: &impl AsRef<Path>) -> Option<&Path> {
for ancestor in config_source.as_ref().ancestors() {
if ancestor.ends_with("mise-tasks") {
return ancestor.parent();
}

if ancestor.ends_with(".mise-tasks") {
return ancestor.parent();
}

if ancestor.ends_with(".mise/tasks") {
return ancestor.parent()?.parent();
}
Expand Down
Loading