just icon indicating copy to clipboard operation
just copied to clipboard

Set minimal required `just` version for a justfile

Open nyurik opened this issue 1 year ago • 18 comments

just is rapidly evolving, frequently adding new features. justfiles are frequently shared between users, and those users may have different Just versions installed, which means in some cases some newer features might not be available in the older just versions.

We need a way to specify the minimum required version for just, similar to how cmake and many other similar tools do it. The actual syntax is up for a discussion:

Naming is hard

Some ideas...

set mjv := '1.32.0'
set minimum-just := '1.32.0'
set require-just-at-least := '1.32.0'
set min-required-just := '1.32.0'
set min-just-version := '1.32.0'

nyurik avatar Aug 02 '24 13:08 nyurik

set min-just-version := '1.32.0'

hustcer avatar Aug 02 '24 14:08 hustcer

This is actually quite a tricky problem. Let's say there's a new function foo() in just 1.50.0, so when using it, you put set minimum-just-version := '1.50.0':

set minimum-just-version := '1.50.0'

foo:
  echo {{ foo() }}

However, a call to a new function in just 1.49.0 is a compilation error, so when you're producing an error message, you do not have a Justfile whose settings you can inspect for a minimum-just-version to produce a better error message.

This is a somewhat trivial example, because a missing function error could be deferred until the end of compilation, so you did have a Justfile you could get the minimum just version from, however in the case of, for example, new grammatical constructs, there's no way you can parse the justfile at all, so you can't extract the minimum just version to improve the error message.

There are a few solutions, but none of them seem very nice:

  • Have a separatefile, like .justversion, which is a file which only contains the minimum version, and refer to that when an error happens.
  • Try to grep through the file if you get an error, and just search for a line that matches set min-just-version := '.*'
  • Have a special form for directives embedded in comments, so they don't depend on parsing anything else #! just-version 1.50.0

I'm not convinced though that any of these are worth it though.

casey avatar Aug 02 '24 19:08 casey

Just a thought, Would it make sense to only allow the minimum version as the very first tokens of a Justfile, but still as optional?

Spatenheinz avatar Aug 06 '24 09:08 Spatenheinz

Just a thought, Would it make sense to only allow the minimum version as the very first tokens of a Justfile, but still as optional?

This is possible, although I'd like to avoid adding special case parsing logic just for this feature.

casey avatar Aug 06 '24 20:08 casey

what if add version into filename? like

.a.b.c.justfile
a.b.c@justfile

which can be created by just --init and in justfile, when add new function,

[min(a.b.c)]
foo:
  ...

i think not all func need to work at the same version

windl1n avatar Oct 18 '24 09:10 windl1n

lets not, min version is a small implementation detail, and most users of the repo shouldn't be aware of it. First non-comment line could work ok though

nyurik avatar Oct 18 '24 17:10 nyurik

As a simpler temporary solution we could also use a function that returns current just's version as described in #2616

[private]
validate_just:
    if [ {{semver_matches(just_version(), ">1.38")}} != 'true' ]; then \
        echo "Your just runner is too old, please update" ;\
        exit 1 ;\
    fi

foo: validate_just
    echo "running foo"

nyurik avatar Feb 03 '25 01:02 nyurik

FWIW I think this would be really valuable. One of the most frequently 'wtf' moments I see as our team is starting to adopt just more is where someone uses new recipe annotations, for example, and other haven't updated their just version in a while and they get an immediate failure when they try to run any recipe (because the Justfile can't be parsed). It would be a huge help to have an error message for this that tells the user what they can do to fix it. Rather than "I've got no idea what this syntax means", which looks like an error on the Justfile-contributor's part, it would be really lovely to report "You need to update just in order to use this Justfile".

andyn-ff avatar Aug 14 '25 09:08 andyn-ff

Just put this on the top of your justfile:

PLEASE_RUN_BREW_UPGRADE_JUST := `min_version=1.45.0; [[ "$(printf '%s\n' "${min_version}" "$(just --version | cut -d' ' -f2)" | sort -V | head -n1)" == "${min_version}" ]]`

just will eagerly evaluate the expression, and fail the execution if exiting with non zero value. Above uses sort -V which is supported on most OS (including macOS.)

$ just
error: Backtick failed with exit code 1
  ——▶ justfile:14:33
   │
14 │ PLEASE_RUN_BREW_UPGRADE_JUST := `min_version=1.45.0; [[ "$(printf '%s\n' "${min_version}" "$(just --version | cut -d' ' -f2)" | sort -V | head -n1)" == "${min_version}" ]]`
   │                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This is fully backward compatible and anyone who reads the error message, should have a sense to update their just runner.

Even if just added a new func/keyword/conffile to assert the version, people with historical just runner will not be able to get any useful information from the backtrace.

ashi009 avatar Sep 18 '25 00:09 ashi009

wouldn't work on windows i guess...

nyurik avatar Sep 18 '25 01:09 nyurik

Note that merging #2892 would solve this issue, albeit a bit more verbose than needed:

_required_just_ver := if semver_matches(just_version(), '>=1.43.0') == 'true' {
  'yes'
} else {
  error('just version 1.43.0 or greater is required, found ' + just_version())
}

nyurik avatar Sep 28 '25 02:09 nyurik

Note that merging #2892 would solve this issue, albeit a bit more verbose than needed:

_required_just_ver := if semver_matches(just_version(), '>=1.43.0') == 'true' {
  'yes'
} else {
  error('just version 1.43.0 or greater is required, found ' + just_version())
}

:confused: I was not able to get this error to show when making up fictitious unimplemented syntaxes or functions in the justfile?

laniakea64 avatar Sep 28 '25 03:09 laniakea64

I am not sure i understood what you mean

nyurik avatar Sep 28 '25 03:09 nyurik

I am not sure i understood what you mean

It means you need a version that supports this new function and syntax to even show the error message.

Or to say if your user is not with the latest version won't even know they need the latest version.

ashi009 avatar Sep 28 '25 03:09 ashi009

true - but that's true regardless of the changes just introduces -- because all the existing versions already do not have any way to set min req version

nyurik avatar Sep 28 '25 04:09 nyurik

true - but that's true regardless of the changes just introduces -- because all the existing versions already do not have any way to set min req version

https://github.com/casey/just/issues/2290#issuecomment-3304994239

Do something like this ☝️

Or at least create some syntax that the error message is self-explanatory for users with older versions of just.

ashi009 avatar Sep 28 '25 04:09 ashi009

ah, yes, i remember - that's the workaround that's limited to linux and possibly mac - which is what many folks would be happy with, but not any proper CI setups with multi-OS support. Going forward, i would still like to have a proper way to do it. Eventually, 99.99% of the people will install the version that will support that check, thus addressing it

nyurik avatar Sep 28 '25 04:09 nyurik

What about [since(version)] as an attribute?

kylichist avatar Sep 30 '25 06:09 kylichist