mirror of
https://github.com/actions/setup-go.git
synced 2026-09-19 01:51:15 +00:00
Expose go env variables as action outputs (#791)
* feature implementation - output go env * update action.yml * fix action.yml --------- Co-authored-by: mahabaleshwars <147705296+mahabaleshwars@users.noreply.github.com>
This commit is contained in:
+34
-1
@@ -12,6 +12,9 @@
|
||||
- [Restore-only caches](advanced-usage.md#restore-only-caches)
|
||||
- [Parallel builds](advanced-usage.md#parallel-builds)
|
||||
- [Outputs](advanced-usage.md#outputs)
|
||||
- [go-version](advanced-usage.md#go-version)
|
||||
- [cache-hit](advanced-usage.md#cache-hit)
|
||||
- [Go environment outputs](advanced-usage.md#go-environment-outputs)
|
||||
- [Custom download URL](advanced-usage.md#custom-download-url)
|
||||
- [Using `setup-go` on GHES](advanced-usage.md#using-setup-go-on-ghes)
|
||||
|
||||
@@ -420,6 +423,36 @@ jobs:
|
||||
- run: echo "Was the Go cache restored? ${{ steps.go124.outputs.cache-hit }}" # true if cache-hit occurred
|
||||
```
|
||||
|
||||
### Go environment outputs
|
||||
|
||||
Once Go is on the `PATH`, the action exposes the most commonly needed `go env` variables as outputs, so workflows don't have to query them in duplicated `bash`/`pwsh` steps — one expression works on Linux, macOS, and Windows. The values are a snapshot from setup time: anything a later step changes, such as setting `GOOS`/`GOARCH` to cross-compile, is not reflected.
|
||||
|
||||
| Output | `go env` variable | Notes |
|
||||
| --- | --- | --- |
|
||||
| `go-path` | `GOPATH` | Go workspace root; `bin` and `pkg/mod` live under it |
|
||||
| `go-bin` | `GOBIN` | Go 1.27+ reports an implicit `$GOPATH/bin` default; earlier releases are empty unless `GOBIN` is set |
|
||||
| `go-bin-path` | `GOBIN` or `$GOPATH/bin` | The base Go binary directory, using the first `GOPATH` entry. Cross-compiled binaries go one level deeper, in `$GOPATH/bin/$GOOS_$GOARCH` |
|
||||
| `go-root` | `GOROOT` | Installation directory of the Go toolchain in use |
|
||||
| `go-cache` | `GOCACHE` | Build cache directory |
|
||||
| `go-mod-cache` | `GOMODCACHE` | Module cache directory |
|
||||
| `go-os` | `GOOS` | Go notation (`linux`, `darwin`, `windows`), unlike `runner.os` |
|
||||
| `go-arch` | `GOARCH` | Go notation (`amd64`, `arm64`), unlike `runner.arch` or the `x64` in the action's cache key |
|
||||
| `go-tool-dir` | `GOTOOLDIR` | Holds `compile`, `link`, `vet` and the other toolchain binaries |
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/setup-go@v7
|
||||
id: setup-go
|
||||
with:
|
||||
go-version: '1.25.5'
|
||||
- run: echo "Modules are cached in ${{ steps.setup-go.outputs.go-mod-cache }}"
|
||||
```
|
||||
|
||||
Quote `go-bin-path` in shell commands, since it may contain spaces. Variables without a dedicated output are not exposed; run `go env <NAME>` in a step when you need one.
|
||||
|
||||
> [!NOTE]
|
||||
> These outputs need Go 1.9 or newer (`go env -json`); on older releases the action logs a message, leaves them unset and does not fail. `go-cache` needs Go 1.10 and `go-mod-cache` needs Go 1.15.
|
||||
|
||||
## Custom download URL
|
||||
|
||||
The `go-download-base-url` input lets you download Go from a mirror or alternative source instead of the default `https://go.dev/dl`. This can also be set via the `GO_DOWNLOAD_BASE_URL` environment variable; the input takes precedence over the environment variable.
|
||||
@@ -495,4 +528,4 @@ with:
|
||||
|
||||
If the runner is not able to access github.com, any Go versions requested during a workflow run must come from the runner's tool cache.
|
||||
See "[Setting up the tool cache on self-hosted runners without internet access](https://docs.github.com/en/enterprise-server@3.2/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)"
|
||||
for more information.
|
||||
for more information.
|
||||
Reference in New Issue
Block a user