Last active
September 21, 2022 15:06
-
-
Save milas/cdd84f9edba318b5f2719b78f436a4ba to your computer and use it in GitHub Desktop.
Extract Go version from go.mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# These have been tested against: | |
# macOS 12.6 / built-in | |
# Alpine 3.16.2 / BusyBox v1.35 | |
# Debian 11.5 / GNU sed v4.7 | |
# short, readable, should be fine for most purposes! | |
sed -n -e 's/^go \(.*\)$/\1/p' go.mod | |
# strict based on https://go.dev/ref/mod#go-mod-file-go | |
# > The version must be a valid Go release version: a positive | |
# > integer followed by a dot and a non-negative integer | |
# > (for example, 1.9, 1.14). | |
sed -n -e 's/^go \([[:digit:]][[:digit:]]*\.[[:digit:]][[:digit:]]*\)$/\1/p' go.mod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# don't forget to escape the $ in Makefile! | |
GO_VERSION=$(shell sed -n -e 's/^go \(.*\)$$/\1/p' go.mod) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment