go tool will attempt to modify the go.mod file if necessary. In CI contexts, this is sometimes not wanted. There are two ways to avoid this, either pass
-mod=readonly to the
go command or set an env var
GOFLAGS to have
-mod=readonly as an element.
In the case that Go versions prior to the existence of Go modules are being tested in the same matrix as versions that are module-aware, the first option is onerous as differential flags must be created depending on the Go version otherwise the non-module-aware versions will fail with an error. I have also found that the instructions at the Go language page either don’t work or I don’t understand and this approach fails anyway with the
gobuild_args looking like it’s being constructed as an array.
This leaves the second approach, using an env var
GOFLAGS="-mod=readonly". However, the
travis_install_go_dependencies bash function that is invoked during
install does not respect this as can be seen here.
See discussion at golang/go issue #32147.