You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support for Outputting or Exporting Go Environment Variables #54
In some of our GitHub Actions workflows, we opt to cache the GOCACHE between jobs to save compilation time. It seems like we currently need to run go env GOCACHE to fetch the correct GOCACHE path after this action is run, e.g.
Thank you for the consideration! Please reach out if I'm missing something and this is already possible or if this would be acceptable as an enhancement.
Reacted by Stephan, swithek, Dominik Honnef, angie pinilla, Alex Page, Graham Davison, Jeremy Gustie, Eddie Knight, Anita Krueger, Narimasa Sakurai and 4 more
It definitely helps make workflow definitions platform agnostic. For example, it would allow all three platform specific cache action examples to be replaced with a single more robust example:
Would love this as well. I currently have extra steps like echo "dir=$(go env GOMODCACHE)" >> ${GITHUB_OUTPUT}, which are verbose and wasteful, since setup-go has already run go env.
Additionally, please let us know if there are any specific use cases where having these outputs would be beneficial. This helps us understand your requirements better and further enhance the action.
The built-in cache functionality now covers the original cache-path use case from this issue. For the common case, users no longer need to manually export GOCACHE and GOMODCACHE just to configure Go module/build-output caching, because setup-go already restores and saves the paths from:
go env GOMODCACHE
go env GOCACHE
So I would consider the original standard-cache motivation mostly addressed.
To check whether the broader output request still has value, I done a cursory GitHub search (source). The sampling focused on workflows, composite actions, shell scripts, Makefiles, Dockerfiles, and documentation snippets that call go env and then pass the result into $GITHUB_ENV, $GITHUB_OUTPUT, or $GITHUB_PATH.
The main conclusion is that built-in caching solves the standard GOCACHE/GOMODCACHE cache setup case, but it does not replace Go environment outputs in general. Code-search samples show continuing use cases such as:
GOPATH / GOPATH/bin: commonly used after go install to add installed tools to PATH.
GOBIN: used to find the effective Go binary install directory, often with fallback to GOPATH/bin.
GOROOT: used to locate files inside the installed toolchain, such as wasm_exec.js, LICENSE, or bin/go.
GOTOOLDIR: used by advanced workflows that invoke or inspect Go toolchain binaries like compile, link, or vet.
GOOS / GOARCH: used for release asset names, platform-specific downloads, and build metadata.
GOCACHE / GOMODCACHE: still useful for custom cache workflows, restore-only caches, cross-job/shared caches, Docker volume mounts, Bazel configuration, sudo env forwarding, and cache cleanup/statistics.
Representative public examples from the sampling included workflows and actions in diggerhq/digger, magnetikonline/action-golang-cache, GoogleCloudPlatform/k8s-config-connector, smartcontractkit/.github, openziti/ziti, tuananh/actions, kubernetes-sigs/cluster-api, buildkite/agent, github/gh-aw, milvus-io/milvus, and numtide/go2nix.
My recommendation would be to treat the built-in cache as solving the default caching use case, but keep the Go environment output feature because it addresses a broader set of real-world workflow needs that are separate from caching.
Hello everyone👋,
Thank you all for the helpful feedback on this! Since setup-go already runs go env, most of the variables mentioned here are already part of that single command's output - for example GOPATH, GOBIN, and GOROOT.
We would like to know: would simply exposing the go env as output be enough to cover your use case, or would you specifically need each variable as separate named outputs such as GOPATH, GOBIN, GOROOT, GOTOOLDIR, GOOS / GOARCH, and GOCACHE / GOMODCACHE?
Your feedback would be really helpful in choosing the best approach. Thank you so much for your patience!
This has been implemented in #791, which exposes the go env variables as action outputs. You can now reference them directly from the setup-go step outputs instead of running go env manually.
Is there any reason why you expose these env vars as e.g. go-mod-cache rather than the original and well known GOMODCACHE? Having to remember what the kebab case form looks like seems unfortunate and inconsistent with the Go ecosystem.
@v-mahabaleshwars can we reconsider the casing of the env vars, as request by @mvdan? I do think it make sense names as outputted by go env rather than inventing our own convention?
Hello @mvdan and @qmuntal 👋,
Thank you for sharing your feedback! We understand that aligning with the original go env names would be more consistent with the Go ecosystem. We're working on renaming the outputs(GOPATH, GOBIN, GOROOT, GOTOOLDIR, GOOS / GOARCH, and GOCACHE / GOMODCACHE) accordingly and will share an update here once the change is in.
Thanks for your patience!
If these are from older versions of setup-go, and hard to remove without breaking users, I'd suggest deprecating them so that the next major version of setup-go can remove them in favor of GOVERSION and GOBIN.
Thanks for the suggestion. go-version and GOVERSION identify the same toolchain, but the formats differ slightly: 1.24.11 versus go1.24.11. Workflows may rely on the unprefixed form, while the prefixed form matches Go's own version string.
go-bin-path is mainly a convenience for older toolchains: it uses GOBIN when non-empty, otherwise bin under the first GOPATH entry. On Go 1.27+ the outputs normally match; the fallback remains useful on Go 1.26, which is still supported upstream. We’ll update the docs accordingly.
Activity
Sergey-Murtazin commentedon Oct 19, 2021
Hi @bflad ! Sorry for the late response!
Could you please clarify if the issue is still actual for you?
Thanks!
jgustie commentedon Oct 19, 2021
It definitely helps make workflow definitions platform agnostic. For example, it would allow all three platform specific cache action examples to be replaced with a single more robust example:
This particular use case may not be as relevant if
setup-gohad acacheinput (likesetup-node) to handle cache setup.bflad commentedon Oct 19, 2021
Hi @Sergey-Murtazin 👋 Certainly still valid for our use cases, mostly to help with platform agnostic workflows as mentioned above. Thanks!
lucacome commentedon Jul 23, 2022
I was about to open a similar issue 🙂
I'm interested in
GOPATHand I know it's pretty simple to retrieve it, but having it as an output of the action would make the workflows cleaner IMHO.A JSON output of
go envwould work too.qrkourier commentedon Feb 15, 2023
It'd be helpful to have
go envas outputs from this action so that it's not necessary to solve for GOBIN, GOPATH, GOCACHE in the worflow.lucacome commentedon Feb 16, 2023
I've opened a #334 with some default outputs that I think will cover 99% of the cases, let me know what you think 🙏
urica12 commentedon Feb 16, 2023
Run
mvdan commentedon Mar 27, 2023
Would love this as well. I currently have extra steps like
echo "dir=$(go env GOMODCACHE)" >> ${GITHUB_OUTPUT}, which are verbose and wasteful, since setup-go has already rungo env.11 remaining items
qmuntal commentedon Jun 12, 2026
The built-in cache functionality now covers the original cache-path use case from this issue. For the common case, users no longer need to manually export
GOCACHEandGOMODCACHEjust to configure Go module/build-output caching, becausesetup-goalready restores and saves the paths from:So I would consider the original standard-cache motivation mostly addressed.
To check whether the broader output request still has value, I done a cursory GitHub search (source). The sampling focused on workflows, composite actions, shell scripts, Makefiles, Dockerfiles, and documentation snippets that call
go envand then pass the result into$GITHUB_ENV,$GITHUB_OUTPUT, or$GITHUB_PATH.The main conclusion is that built-in caching solves the standard
GOCACHE/GOMODCACHEcache setup case, but it does not replace Go environment outputs in general. Code-search samples show continuing use cases such as:GOPATH/GOPATH/bin: commonly used aftergo installto add installed tools toPATH.GOBIN: used to find the effective Go binary install directory, often with fallback toGOPATH/bin.GOROOT: used to locate files inside the installed toolchain, such aswasm_exec.js,LICENSE, orbin/go.GOTOOLDIR: used by advanced workflows that invoke or inspect Go toolchain binaries likecompile,link, orvet.GOOS/GOARCH: used for release asset names, platform-specific downloads, and build metadata.GOCACHE/GOMODCACHE: still useful for custom cache workflows, restore-only caches, cross-job/shared caches, Docker volume mounts, Bazel configuration, sudo env forwarding, and cache cleanup/statistics.Representative public examples from the sampling included workflows and actions in
diggerhq/digger,magnetikonline/action-golang-cache,GoogleCloudPlatform/k8s-config-connector,smartcontractkit/.github,openziti/ziti,tuananh/actions,kubernetes-sigs/cluster-api,buildkite/agent,github/gh-aw,milvus-io/milvus, andnumtide/go2nix.My recommendation would be to treat the built-in cache as solving the default caching use case, but keep the Go environment output feature because it addresses a broader set of real-world workflow needs that are separate from caching.
v-priya-kinthali commentedon Sep 11, 2026
Hello everyone👋,
Thank you all for the helpful feedback on this! Since
setup-goalready runs go env, most of the variables mentioned here are already part of that single command's output - for example GOPATH, GOBIN, and GOROOT.We would like to know: would simply exposing the go env as output be enough to cover your use case, or would you specifically need each variable as separate named outputs such as GOPATH, GOBIN, GOROOT, GOTOOLDIR, GOOS / GOARCH, and GOCACHE / GOMODCACHE?
Your feedback would be really helpful in choosing the best approach. Thank you so much for your patience!
v-mahabaleshwars commentedon Sep 22, 2026
Hi @bflad,
This has been implemented in #791, which exposes the go env variables as action outputs. You can now reference them directly from the setup-go step outputs instead of running go env manually.
You can try it out using actions/setup-go@main.
Closing as resolved.
mvdan commentedon Sep 22, 2026
Is there any reason why you expose these env vars as e.g. go-mod-cache rather than the original and well known GOMODCACHE? Having to remember what the kebab case form looks like seems unfortunate and inconsistent with the Go ecosystem.
qmuntal commentedon Sep 22, 2026
@v-mahabaleshwars can we reconsider the casing of the env vars, as request by @mvdan? I do think it make sense names as outputted by
go envrather than inventing our own convention?mvdan commentedon Sep 22, 2026
I made the same suggestion back in 2023, for what it's worth :) #334 (comment)
v-priya-kinthali commentedon Sep 24, 2026
Hello @mvdan and @qmuntal 👋,
Thank you for sharing your feedback! We understand that aligning with the original
go envnames would be more consistent with the Go ecosystem. We're working on renaming the outputs(GOPATH, GOBIN, GOROOT, GOTOOLDIR, GOOS / GOARCH, and GOCACHE / GOMODCACHE) accordingly and will share an update here once the change is in.Thanks for your patience!
mvdan commentedon Sep 28, 2026
Thanks very much! Looking forward to testing it out once it's in a release.
mvdan commentedon Sep 28, 2026
From looking at https://github.com/actions/setup-go/blob/main/action.yml, two questions pop to mind:
go-versiondifferent fromgo env GOVERSION? If not, I would rename it. If it is, then I would document it very clearly to avoid confusion.go-bin-pathis different toGOBIN. Note that, since May 2026, Go has printed a default forgo env GOBIN: cmd/go: default GOBIN to GOPATH[0]/bin when outside of GOPATH? golang/go#23439If these are from older versions of setup-go, and hard to remove without breaking users, I'd suggest deprecating them so that the next major version of setup-go can remove them in favor of GOVERSION and GOBIN.
v-mahabaleshwars commentedon Oct 7, 2026
Hi @mvdan,
Thanks for the suggestion.
go-versionandGOVERSIONidentify the same toolchain, but the formats differ slightly:1.24.11versusgo1.24.11. Workflows may rely on the unprefixed form, while the prefixed form matches Go's own version string.go-bin-pathis mainly a convenience for older toolchains: it usesGOBINwhen non-empty, otherwisebinunder the firstGOPATHentry. On Go 1.27+ the outputs normally match; the fallback remains useful on Go 1.26, which is still supported upstream. We’ll update the docs accordingly.v-mahabaleshwars commentedon Nov 4, 2026
Hi @mvdan,
The documentation concerns are addressed in #803.
Closing this issue as resolved.