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

docs: Add more examples for toml tasks #3491

Merged
merged 10 commits into from
Dec 12, 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
90 changes: 59 additions & 31 deletions docs/tasks/file-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,72 @@ Here is an example of a file task that builds a Rust CLI:
cargo build
```

::: tip Important
Ensure that the file is executable, otherwise mise will not be able to detect it.

:::tip
The `mise:description` comment is optional but recommended. It will be used in the output of `mise tasks`.
The other configuration for "script" tasks is supported in this format so you can specify things like the
following-note that this is parsed a TOML table:
```shell
chmod +x mise-tasks/build
```

:::

Having the code in a bash file and not TOML helps make it work
better in editors since they can do syntax highlighting and linting more easily.

They also still work great for non-mise users—though
of course they'll need to find a different way to install their dev tools the tasks might use.

## Task Configuration

The same configuration options as for [TOML tasks](/tasks/toml-tasks.html) are supported.
You can provide additional configuration for file tasks by adding `#MISE` comments at the top of the file.

```bash
#MISE description="Build the CLI"
#MISE alias="b"
#MISE sources=["Cargo.toml", "src/**/*.rs"]
#MISE outputs=["target/debug/mycli"]
#MISE env={RUST_BACKTRACE = "1"}
#MISE depends=["lint", "test"]
```

Assuming that file was located in `.mise/tasks/build`, it can then be run with `mise run build` (or with its alias: `mise run b`).
This script can be edited with by running `mise task edit build` (using $EDITOR). If it doesn't exist it will be created.
These are convenient for quickly making new scripts. Having the code in a bash file and not TOML helps make it work
better in editors since they can do syntax highlighting and linting more easily. They also still work great for non-mise users—though
of course they'll need to find a different way to install their dev tools the tasks might use.
Assuming that file was located in `mise-tasks/build`, it can then be run with `mise run build` (or with its alias: `mise run b`).

## Shebang

The shebang line is optional, but if it is present, it will be used to determine the shell to run the script with.
You can also use it to run the script with various programming languages.

::: code-group

```js [node]
#!/usr/bin/env node

console.log("Hello, World!");
```

```python
#!/usr/bin/env python

print('Hello, World!')
```

```ts [deno]
#!/usr/bin/env -S deno run --allow-env

console.log(`PATH, ${Deno.env.get("PATH")}`);
```

:::

## Editing tasks

This script can be edited with by running `mise task edit build` (using `$EDITOR`). If it doesn't exist it will be created.
This is convenient for quickly editing or creating new scripts.

## Task Grouping

File tasks in `.mise/tasks`, `mise/tasks`, or `.config/mise/tasks` can be grouped into
File tasks in `mise-tasks`, `.mise/tasks`, `mise/tasks`, or `.config/mise/tasks` can be grouped into
sub-directories which will automatically apply prefixes to their names
when loaded.

Expand All @@ -51,22 +92,21 @@ when loaded.
With a folder structure like below:

```text
.mise
└── tasks
├── build
└── test
├── integration
└── units
mise-tasks
├── build
└── test
├── integration
└── units
```

Running `mise tasks` will give the below output:

```text
$ mise tasks
Name Description Source
build .../.mise/tasks/build
test:integration .../.mise/tasks/test/integration
test:units .../.mise/tasks/test/units
build .../mise-tasks/build
test:integration .../mise-tasks/test/integration
test:units .../mise-tasks/test/units
```

## Arguments
Expand Down Expand Up @@ -132,15 +172,3 @@ mise run ./path/to/script.sh
```

Note that the path must start with `/` or `./` to be considered a file path. (On Windows it can be `C:\` or `.\`)

## Remote tasks

Task files can be fetched via http:

```toml
[tasks.build]
file = "https://example.com/build.sh"
```

Currently, they're fetched everytime they're executed, but we may add some cache support later.
This could be extended with other protocols like mentioned in [this ticket](https://github.com/jdx/mise/issues/2488) if there were interest.
6 changes: 3 additions & 3 deletions docs/tasks/running-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ It wouldn't be hard to add checksum support.

## Watching files

Run a task when the source changes with `mise watch`:
Run a task when the source changes with [`mise watch`](/cli/watch.html)

```bash
mise watch build
```

Currently, this just shells out to watchexec-which you can install however you want including with mise: `mise use -g watchexec@latest`.
This may change in the future.
Currently, this just shells out to `watchexec` (which you can install however you want including with mise: `mise use -g watchexec@latest`.
This may change in the future.)

## `mise run` shorthand

Expand Down
Loading
Loading