Skip to content

Should the go directive in go.mod a semver version (including patch), or not? #68971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
StefMa opened this issue Aug 20, 2024 · 5 comments
Closed
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@StefMa
Copy link

StefMa commented Aug 20, 2024

Go version

go version go1.22.2 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/stefan/Library/Caches/go-build'
GOENV='/Users/stefan/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/stefan/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/stefan/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.2/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.2/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/m3/xsbbvz1j6sgd2_50b2m88vj80000gn/T/go-build1885746714=/tmp/go-build -gno-record-gcc-switches -fno-common

What did you do?

Given a simple go.mod file:

module github.com/cli/cli/v2

go 1.23

No other files are available.

Then I run go build.

What did you see happen?

When I run go build I get the following error:

go: downloading go1.23 (darwin/arm64)
go: download go1.23 for darwin/arm64: toolchain not available

What did you expect to see?

I don't expect an error.
According to this docs:

A go directive indicates that a module was written assuming the semantics of a given version of Go. The version must be a valid Go version, such as 1.9, 1.14, or 1.21rc1.

Heading over to the Go version link I can find this:

The syntax ‘1.N’ is called a “language version”. It denotes the overall family of Go releases implementing that version of the Go language and standard library.

Because of that, I would expect that I can use a "language version" as go directive.
But it is not working.
So either go behaves wrong (by not accepting a "langauge version" as a go directive), or the docs are not correct and needs to be changed. It seems only a "release name" is supported.
Looking at https://go.dev/doc/devel/release, I guess I can use each and every version mentioned here.
Hence, I can't use 1.21 (and up) anymore, since this release simply doesn't exist anymore.

I'm unsure what is the correct behaviour. Please let me know whats correct and what needs to be adjusted/fixed/changed.
Thanks! 🙃

Furhter reading where this is comming from (and for cress referencing):
cli/cli#9489

@dmitshur
Copy link
Contributor

This seems related or the same as #62278, which was fixed and backported to Go 1.22.4 (backport issue #67236). Can you try that version and see if it's fixed?

@dmitshur dmitshur added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Aug 20, 2024
@StefMa
Copy link
Author

StefMa commented Aug 20, 2024

Nice, thanks for the link!
I haven't tested it yet, but what I read so far seems that this fixes the bug.

However I still ask myself what the go team recommend to use as a version. The one with a patch, or without? What is considered as best practices?

@seankhliao
Copy link
Member

The release versions are expected and generated by go tooling.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 21, 2024
@StefMa
Copy link
Author

StefMa commented Aug 21, 2024

Just wanted to confirm that 1.22.6 fixed that problem and can work with a language version:
Screenshot 2024-08-21 at 8 13 41 AM

The release versions are expected and generated by go tooling.

Thank you! 🙂

jm33-m0 added a commit to jm33-m0/T00ls that referenced this issue Feb 3, 2025
see golang/go#68971, go directive without
patch can cause some go toolchains to fail, eg. go1.22.2 bundled with
Ubuntu 24.04 LTS
derekcollison added a commit to nats-io/nats-server that referenced this issue Feb 19, 2025
Setup-go has some non-straitforward tricks:

https://github.com/actions/setup-go?tab=readme-ov-file#getting-go-version-from-the-gomod-file
> The go directive in go.mod can specify a patch version or omit it
altogether (e.g., go 1.22.0 or go 1.22).
If a patch version is specified, that specific patch version will be
used.
If no patch version is specified, it will search for the latest
available patch version in the cache,
[versions-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json),
and the [official Go language
website](https://golang.org/dl/?mode=json&include=all), in that order.

This is an invention of setup-go action authors. Go team
[says](golang/go#68971 (comment))
that release version (e.g. 1.22.0) should be specified

That means, e.g. when [this
commit](8f46514#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6R3)
updated go.mod from 1.22 to 1.22.0, the "Long JetStream tests" silently
started to use 1.22.0, instead of 1.22.12.
"If nothing magically works, nothing magically breaks".

Since we update to the new toolchain version as soon as it is released,
and we usually use the latest toolchain for the releases, we should run
all tests using [go-version:
stable](https://github.com/actions/setup-go?tab=readme-ov-file#using-stableoldstable-aliases)


Signed-off-by: Alex Bozhenko <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants