documentation icon indicating copy to clipboard operation
documentation copied to clipboard

Add tool-versions file

Open ThisIsMissEm opened this issue 1 year ago • 8 comments

This helps software like asdf discover exactly what version of hugo to use, since hugo versions often have incompatibilities.

I've been bitten many times working on docs but having the wrong version of hugo in my $PATH

ThisIsMissEm avatar Nov 13 '24 18:11 ThisIsMissEm

Added comments to try to keep this in sync, since we can't reuse the tool-versions file in GitHub Actions directly

ThisIsMissEm avatar Nov 14 '24 09:11 ThisIsMissEm

@ClearlyClaire the main reason I ended up using asdf for Hugo was because I contribute to multiple Hugo sites each running different incompatible versions, so I'd constantly get weird breakages when switching between repos. asdf helps with that by automatically switching my hugo version to the right one for the project & the .tool-versions file in the root of the repo acts as a bit of a guide as to what we use.

ThisIsMissEm avatar Nov 14 '24 10:11 ThisIsMissEm

FYI, you can do something like...

echo ".tool-versions" >> .git/info/exclude

...which will let you get the benefits of asdf locally, w/out needing the project to adopt it or add to their gitignore.

mjankowski avatar Nov 26 '24 16:11 mjankowski

I'd be of the inclination to suggest we do adopt .tool-versions here, not necessarily to say adopt asdf, but rather to have a file in the root of the repository that does contain the version required.

ThisIsMissEm avatar Nov 26 '24 17:11 ThisIsMissEm

Yes, agreed on having it better locked/specified somewhere.

Im guessing theres no equivalent of .nvmrc or .ruby-version for hugo projects? Also, its too bad the format here with extended doesnt quite match the format needed in the CI config...

mjankowski avatar Nov 26 '24 17:11 mjankowski

Also, its too bad the format here with extended doesnt quite match the format needed in the CI config...

Yeah, that annoys me too, but there isn't really anything we can do about that, unless we do an upstream PR to the github action to support .tool-versions syntax?

ThisIsMissEm avatar Nov 26 '24 17:11 ThisIsMissEm

Sort of related - https://github.com/peaceiris/actions-hugo?tab=readme-ov-file#%EF%B8%8F-read-hugo-version-from-file - the GH action that publishes the site could pull that version value from a file (example there is a .env, but in theory could do whatever)

mjankowski avatar Dec 17 '24 17:12 mjankowski

This pull request has merge conflicts that must be resolved before it can be merged.

github-actions[bot] avatar Jan 10 '25 16:01 github-actions[bot]

A tool-versions was added (maybe by accident?) as side effect of: https://github.com/mastodon/documentation/pull/1560

However, the thing that comment warned about has happened ... and there now is a disconnect between the github action version (0.140.2) and the tool-versions version (extended_0.130.0)

Want to rebase this to increase the tool-versions version (and leave the comment)?

Possible follow-up ... there are a bunch of releases since the version GH actions is using, could bump a bit.

mjankowski avatar Nov 06 '25 19:11 mjankowski

@mjankowski an alternative way to do this is to actually parse the tool-versions file for the CI pipeline:

     - name: Setup Hugo Version
        id: hugo_version
        run: |
          HUGO_VERSION=$(cat .tool-versions | grep hugo | cut -d' ' -f2 | cut -d'_' -f2)
          echo "HUGO_VERSION=$HUGO_VERSION" >> "$GITHUB_ENV"

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v3
        with:
          hugo-version: ${{ env.HUGO_VERSION }}
          extended: true

Which may be easier to maintain long-term. (I worked this out for the hachyderm/community website)

ThisIsMissEm avatar Nov 06 '25 20:11 ThisIsMissEm

It'd probably actually be possible to write a small go program to convert from tool-versions to the environment variables: https://github.com/asdf-vm/asdf/blob/master/internal/toolversions/toolversions.go

ThisIsMissEm avatar Nov 06 '25 20:11 ThisIsMissEm

But yeah, it's just an annoying thing that actions-hugo splits the extended out of the version.

ThisIsMissEm avatar Nov 06 '25 20:11 ThisIsMissEm

Agreed that scripting would be nice, but at min we can sync them.

Similarly annoying, within .tool-versions, asdf uses a format like hugo extended_0.130.0, (keeping extended with the version) whereas mise (which uses tool-versions if it finds one) uses hugo-extended 0.142.0 style (keeps extended with package name and version separate)

mjankowski avatar Nov 06 '25 20:11 mjankowski

Anyway, it's a relatively simple improvement that could be done to the hugo action: https://github.com/peaceiris/actions-hugo/issues/670

ThisIsMissEm avatar Nov 06 '25 20:11 ThisIsMissEm

Going to close this because https://github.com/mastodon/documentation/pull/1762 bumped the hugo version, and added similar-ish comment to what was here.

Possible followup here would be some way to link those versions together, if we can do so simply and/or some more official way is supported by the actions, etc.

mjankowski avatar Nov 21 '25 19:11 mjankowski