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

Consider merging hooks into tasks #3333

Closed
dudicoco opened this issue Dec 3, 2024 · 5 comments
Closed

Consider merging hooks into tasks #3333

dudicoco opened this issue Dec 3, 2024 · 5 comments

Comments

@dudicoco
Copy link

dudicoco commented Dec 3, 2024

Hi,

It would be great if we could define within a task if it should run as a hook as well instead of having separate definitions for hooks.

With the new hooks feature I can run some commands when files changed:

[hooks]
[[watch_files]]
patterns = [".mise.toml"]
run = "mise install"

[[watch_files]]
patterns = ["pyproject.toml", "uv.lock"]
run = "uv sync"

[[watch_files]]
patterns = ["package.json", "pnpm-lock.yaml"]
run = "pnpm install"

This is great, but there are a few problems:

  1. The hooks won't run when I enter the repository, so I need to add another hook:
enter = "mise install && uv sync && pnpm install"
  1. I can't run these hooks in CI
  2. The hooks run sequentially while I could run uv sync and pnpm install in parallel

As a workaround, we could do the following:

[tasks.mise-install]
sources = ['.mise.toml']
run = "mise install"

[tasks.uv-sync]
sources = ["pyproject.toml", "uv.lock"]
depends = ["mise-install"]
run = "uv sync"

[tasks.pnpm-install]
sources = ["package.json", "pnpm-lock.yaml"]
depends = ["mise-install"]
run = "pnpm install"

[tasks.all]
depends = ["mise-install", "uv-sync", "pnpm-install"]

[hooks]
enter = "mise run all"

[[watch_files]]
patterns = [".mise.toml"]
run = "mise run mise-install"

[[watch_files]]
patterns = ["pyproject.toml", "uv.lock"]
run = "mise run uv-sync"

[[watch_files]]
patterns = ["package.json", "pnpm-lock.yaml"]
run = "mise run pnpm-install"

We now have some unnecessary duplication.

What I suggest is to add a new field within tasks to also run them as a hook:

[tasks.mise-install]
sources = ['pyproject.toml']
run = "mise install"
hook = "watch"

[tasks.uv-sync]
sources = ["pyproject.toml", "uv.lock"]
depends = ["mise-install"]
run = "uv sync"
hook = "watch"

[tasks.pnpm-install]
sources = ["package.json", "pnpm-lock.yaml"]
depends = ["mise-install"]
run = "pnpm install"
hook = "watch"

[tasks.all]
depends = ["mise-install", "uv-sync", "pnpm-install"]
hook = "enter"
@dudicoco
Copy link
Author

dudicoco commented Dec 3, 2024

Bonus: don't run tasks which sources have not changed on enter - I assume mise saves some cache for that somewhere or is using timestamps.

@syhol
Copy link
Contributor

syhol commented Dec 3, 2024

How would this work with file tasks? Does that mean each file task needs to be read to check for hooks every hook-env? I wonder how that might impact performance 🤔.

@jdx
Copy link
Owner

jdx commented Dec 3, 2024

that's already happening when you use [[watch_files]]—so I would be judicious about how many files you're asking mise to read each time. Of course mise watch is available if you want to leverage fnotify/fsevent

@jdx
Copy link
Owner

jdx commented Dec 3, 2024

I feel like #3314 is all we actually need here without making the config more complex

@jdx jdx closed this as not planned Won't fix, can't repro, duplicate, stale Dec 3, 2024
@jdx
Copy link
Owner

jdx commented Dec 3, 2024

I also should mention I think this is a bad iea:

enter = "mise install && uv sync && pnpm install"

I would strongly not be in favor of projects doing something like that. hooks are available if you really want to do it, but I would find that behavior maddening on a project I worked on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants