casey / just

🤖 Just a command runner
https://just.systems
Creative Commons Zero v1.0 Universal
17.61k stars 399 forks source link

Bug: when recipe repeats recipe inside it, it only runs the first time #1985

Open whyboris opened 1 month ago

whyboris commented 1 month ago

Example justfile:

lol: hi hello hi

@hi:
  echo "1"

@hello:
  echo "2"

Expected output from just lol

1
2
1

Actual output from just lol

1
2

I think this is a bug because I had a command that did cleanup between various other commands and I spent 2 hours trying to figure out why cleanup wasn't working 😢

casey commented 1 month ago

This is actually as intended, although I can see why it would be confusing. Just will only run normal recipes once, even if they appear more than once on the command line, or more than once in recipe dependencies. Just also doesn't necessarily run recipes in the same order as they're passed on the command line. If you do just a b, and a is a dependency of b, it will run b first and then a.

whyboris commented 1 month ago

I suggest adding a quick note in the relevant section:

https://github.com/casey/just?tab=readme-ov-file#features

You can also use dependencies to run multiple recipes by default:

_Note:_ just will not run a recipe twice

The model I had in my head was "recipe", meaning a step-by-step instruction of what just will do. I'm puzzled why anyone would expect just to ignore an instruction.

I am not insisting on implementing changes - I super ❤️ love just ❤️ -- I just think that even though my use case is unusual, there may be others who will have cleanup steps in their script.

My example: https://github.com/whyboris/utilitarianism.net/blob/main/justfile I build a website in three steps: search, PDF, and production - so I had to duplicate a cleanup step :trollface:

casey commented 1 month ago

I think that's reasonable, I'll reopen this issue to track adding a note to the docs.