From 1ab6710e4c44ef269e6dc2048f6962683b28147d Mon Sep 17 00:00:00 2001 From: Pascal Bleser Date: Mon, 31 Aug 2026 18:47:36 +0200 Subject: [PATCH] chore(mise): determine go version by parsing go.mod Instead of statically defining the version of Go in mise.toml as well as in its native files (go.mod), use a small shell script to parse go.mod and determine the version dynamically from there. That version is then available as an env variable in the mise.toml file and can be referenced for go, in order to avoid having to keep those versions in sync, especially since dependabot will update go in the go.mod file, but not in mise.toml. --- .mise-go-version.sh | 21 +++++++++++++++++++++ mise.toml | 5 ++++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100755 .mise-go-version.sh diff --git a/.mise-go-version.sh b/.mise-go-version.sh new file mode 100755 index 0000000000..3ea76554ed --- /dev/null +++ b/.mise-go-version.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -euo pipefail + +# Purpose of this script is to parse the go.mod file to retrieve the version of +# Go that we are using, either from a "toolchain" directive (preferred), or from +# a "go" directive as a fallback. +# +# The script then outputs that version, where it will be picked up as an environment +# variable in mise. + +F="./go.mod" + +AWK=awk +# prefer 'gawk' over 'awk' to make sure we get GNU awk +command -v gawk &>/dev/null && AWK=gawk + +[[ -e $F ]] || { echo "ERROR: failed to find $F" >&2; exit 1;} + +GO_VERSION=$("$AWK" '/^toolchain/ {print $2; exit} /^go / {print $2}' "$F") +GO_VERSION=${GO_VERSION#go} # strip the potential 'go' prefix: +echo "${GO_VERSION}" diff --git a/mise.toml b/mise.toml index 3f785a530d..2cc6ebb761 100644 --- a/mise.toml +++ b/mise.toml @@ -1,5 +1,8 @@ +[env] +GO_VERSION = "{{ exec(command='./.mise-go-version.sh') }}" + [tools] -go = "1.25.9" +go = "{{ env.GO_VERSION }}" node = "24" pnpm = "11.1.3" "go:github.com/go-delve/delve/cmd/dlv" = "1.27.1"