go list and GO111MODULE in Go 1.17

201 views
Skip to first unread message

Dórian Langbeck

unread,
Apr 1, 2021, 12:58:33 PM4/1/21
to golang-nuts
Hi all,

We have a monorepo with a bunch of services in it.
Currently, in Go 1.16, I'm able to build each service using "docker build -" and generating the tar context "by hand" using something like: go list -deps ./services/s1 | sed -n 's#^github.com/org/monorepo/##p'

It works fine locally (as always) but when I started using Github Actions to run the build script I saw something peculiar: "go list -deps" was downloading packages

After looking around I saw that this is the expected behavior.
Though I would prefer to have a flag so "go list" could work offline, I figure out that using the following command did solved my issue:
GO111MODULE=off go list -deps ./services/s1 2> /dev/null | sed -n 's#^github.com/org/monorepo/##p'

Setting GO111MODULE to "off" gave me what I want! \o/
But then I remembered that Go 1.16 release notes did mentioned: "Go 1.17 will ignore GO111MODULE"

So, when Go 1.17 arrives I will need another solution.
Do you guys have any idea of a better way of getting the list of local package dependencies for a package (all this only inside that monorepo)?

Cheers,
Dórian 

Manlio Perillo

unread,
Apr 1, 2021, 3:50:40 PM4/1/21
to golang-nuts
Il giorno giovedì 1 aprile 2021 alle 18:58:33 UTC+2 dorianl...@gmail.com ha scritto:
Hi all,

We have a monorepo with a bunch of services in it.
Currently, in Go 1.16, I'm able to build each service using "docker build -" and generating the tar context "by hand" using something like: go list -deps ./services/s1 | sed -n 's#^github.com/org/monorepo/##p'

It works fine locally (as always) but when I started using Github Actions to run the build script I saw something peculiar: "go list -deps" was downloading packages

After looking around I saw that this is the expected behavior.
Though I would prefer to have a flag so "go list" could work offline, I figure out that using the following command did solved my issue:
GO111MODULE=off go list -deps ./services/s1 2> /dev/null | sed -n 's#^github.com/org/monorepo/##p'


Not tested and it changes your global state/environment:

# Mark your monorepo as private.
go env -w GOPRIVATE=github.com/org/monorepo/

# Tell git to fetch each Go module from your local filesystem instead of https.
# $root is the root directory where your monorepo is stored.
git config --global "url.file://$root/github.com/org/monorepo/".insteadOf "https://github.com/org/monorepo/"

< [...]


Manlio
Reply all
Reply to author
Forward
0 new messages