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
Copy file name to clipboardexpand all lines: README.md
+66-33
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,16 @@ This action sets up a go environment for use in actions by:
8
8
- Optionally downloading and caching a version of Go by version and adding to `PATH`.
9
9
- Registering problem matchers for error output.
10
10
11
+
# V4
12
+
13
+
The V4 edition of the action offers:
14
+
15
+
- Enabled caching by default
16
+
17
+
The action will try to enable caching unless the `cache` input is explicitly set to false.
18
+
19
+
Please see "[Caching dependency files and build outputs](https://github.com/actions/setup-go#caching-dependency-files-and-build-outputs)" for more information.
20
+
11
21
# V3
12
22
13
23
The V3 edition of the action offers:
@@ -19,9 +29,14 @@ The V3 edition of the action offers:
19
29
- stable and oldstable aliases
20
30
- Bug Fixes (including issues around version matching and semver)
21
31
22
-
The action will first check the local cache for a version match. If a version is not found locally, it will pull it from the `main` branch of the [go-versions](https://github.com/actions/go-versions/blob/main/versions-manifest.json) repository. On miss or failure, it will fall back to downloading directly from [go dist](https://storage.googleapis.com/golang). To change the default behavior, please use the [check-latest input](#check-latest-version).
32
+
The action will first check the local cache for a version match. If a version is not found locally, it will pull it from
33
+
the `main` branch of the [go-versions](https://github.com/actions/go-versions/blob/main/versions-manifest.json)
34
+
repository. On miss or failure, it will fall back to downloading directly
35
+
from [go dist](https://storage.googleapis.com/golang). To change the default behavior, please use
36
+
the [check-latest input](#check-latest-version).
23
37
24
-
**Note:** The `setup-go` action uses executable binaries which are built by Golang side. The action does not build golang from source code.
38
+
**Note:** The `setup-go` action uses executable binaries which are built by Golang side. The action does not build
39
+
golang from source code.
25
40
26
41
Matching by [semver spec](https://github.com/npm/node-semver):
27
42
@@ -78,14 +93,17 @@ steps:
78
93
- run: go run hello.go
79
94
```
80
95
81
-
82
96
## Check latest version
83
97
84
-
The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific Go version is always used.
98
+
The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability
99
+
and if you want to ensure a specific Go version is always used.
85
100
86
-
If `check-latest` is set to `true`, the action first checks if the cached version is the latest one. If the locally cached version is not the most up-to-date, a Go version will then be downloaded. Set `check-latest` to `true` if you want the most up-to-date Go version to always be used.
101
+
If `check-latest` is set to `true`, the action first checks if the cached version is the latest one. If the locally
102
+
cached version is not the most up-to-date, a Go version will then be downloaded. Set `check-latest` to `true` if you
103
+
want the most up-to-date Go version to always be used.
87
104
88
-
> Setting `check-latest` to `true` has performance implications as downloading Go versions is slower than using cached versions.
105
+
> Setting `check-latest` to `true` has performance implications as downloading Go versions is slower than using cached
106
+
> versions.
89
107
90
108
```yaml
91
109
steps:
@@ -99,11 +117,14 @@ steps:
99
117
100
118
## Using stable/oldstable aliases
101
119
102
-
If `stable` is provided, action will get the latest stable version from the [`go-versions`](https://github.com/actions/go-versions/blob/main/versions-manifest.json) repository manifest.
120
+
If `stable` is provided, action will get the latest stable version from
121
+
the [`go-versions`](https://github.com/actions/go-versions/blob/main/versions-manifest.json) repository manifest.
103
122
104
-
If `oldstable` is provided, when current release is 1.19.x, action will resolve version as 1.18.x, where x is the latest patch release.
123
+
If `oldstable` is provided, when current release is 1.19.x, action will resolve version as 1.18.x, where x is the latest
124
+
patch release.
105
125
106
-
**Note:** using these aliases will result in same version as using corresponding minor release with `check-latest` input set to `true`
126
+
**Note:** using these aliases will result in same version as using corresponding minor release with `check-latest` input
127
+
set to `true`
107
128
108
129
```yaml
109
130
steps:
@@ -125,48 +146,47 @@ steps:
125
146
126
147
## Caching dependency files and build outputs:
127
148
128
-
The action has a built-in functionality for caching and restoring go modules and build outputs. It uses [actions/cache](https://github.com/actions/cache) under the hood but requires less configuration settings. The `cache` input is optional, and caching is turned off by default.
149
+
The action has a built-in functionality for caching and restoring go modules and build outputs. It
150
+
uses [toolkit/cache](https://github.com/actions/toolkit/tree/main/packages/cache) under the hood but requires less configuration settings.
151
+
The `cache` input is optional, and caching is turned on by default.
129
152
130
-
The action defaults to search for the dependency file - go.sum in the repository root, and uses its hash as a part of the cache key. Use `cache-dependency-path` input for cases when multiple dependency files are used, or they are located in different subdirectories.
153
+
The action defaults to search for the dependency file - go.sum in the repository root, and uses its hash as a part of
154
+
the cache key. Use `cache-dependency-path` input for cases when multiple dependency files are used, or they are located
155
+
in different subdirectories.
131
156
132
-
**Caching without specifying dependency file path**
133
-
```yaml
134
-
steps:
135
-
- uses: actions/checkout@v3
136
-
- uses: actions/setup-go@v3
137
-
with:
138
-
go-version: '1.17'
139
-
check-latest: true
140
-
cache: true
141
-
- run: go run hello.go
142
-
```
157
+
If some problem that prevents success caching happens then the action issues the warning in the log and continues the execution of the pipeline.
143
158
144
159
**Caching in monorepos**
160
+
145
161
```yaml
146
162
steps:
147
163
- uses: actions/checkout@v3
148
164
- uses: actions/setup-go@v3
149
165
with:
150
166
go-version: '1.17'
151
167
check-latest: true
152
-
cache: true
153
168
cache-dependency-path: subdir/go.sum
154
169
- run: go run hello.go
155
170
```
171
+
156
172
## Getting go version from the go.mod file
157
173
158
-
The `go-version-file` input accepts a path to a `go.mod` file or a `go.work` file that contains the version of Go to be used by a project. As the `go.mod` file contains only major and minor (e.g. 1.18) tags, the action will search for the latest available patch version sequentially in the runner's directory with the cached tools, in the [versions-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json) file or at the go servers.
174
+
The `go-version-file` input accepts a path to a `go.mod` file or a `go.work` file that contains the version of Go to be
175
+
used by a project. As the `go.mod` file contains only major and minor (e.g. 1.18) tags, the action will search for the
176
+
latest available patch version sequentially in the runner's directory with the cached tools, in
177
+
the [versions-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json) file or at the go
178
+
servers.
159
179
160
180
If both the `go-version` and the `go-version-file` inputs are provided then the `go-version` input is used.
161
181
> The action will search for the `go.mod` file relative to the repository root
162
182
163
183
```yaml
164
184
steps:
165
-
- uses: actions/checkout@v3
166
-
- uses: actions/setup-go@v3
167
-
with:
168
-
go-version-file: 'path/to/go.mod'
169
-
- run: go version
185
+
- uses: actions/checkout@v3
186
+
- uses: actions/setup-go@v3
187
+
with:
188
+
go-version-file: 'path/to/go.mod'
189
+
- run: go version
170
190
```
171
191
172
192
## Matrix testing
@@ -195,13 +215,23 @@ The `go-version` input supports the following syntax:
195
215
- Specific versions: `1.15`, `1.16.1`, `1.17.0-rc.2`, `1.16.0-beta.1`
196
216
- SemVer's version range syntax: `^1.13.1`, `>=1.18.0-rc.1`
197
217
198
-
For more information about semantic versioning, please refer to [semver](https://github.com/npm/node-semver) documentation.
218
+
For more information about semantic versioning, please refer to [semver](https://github.com/npm/node-semver)
219
+
documentation.
199
220
200
221
## Using `setup-go` on GHES
201
222
202
-
`setup-go`comes pre-installed on the appliance with GHES if Actions is enabled. When dynamically downloading Go distributions, `setup-go` downloads distributions from [`actions/go-versions`](https://github.com/actions/go-versions) on github.com (outside of the appliance). These calls to `actions/go-versions` are made via unauthenticated requests, which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting). If more requests are made within the time frame, then you will start to see rate-limit errors during downloading that looks like: `##[error]API rate limit exceeded for...`. After that error the action will try to download versions directly from https://storage.googleapis.com/golang, but it also can have rate limit so it's better to put token.
223
+
`setup-go`comes pre-installed on the appliance with GHES if Actions is enabled. When dynamically downloading Go
224
+
distributions, `setup-go` downloads distributions from [`actions/go-versions`](https://github.com/actions/go-versions)
225
+
on github.com (outside of the appliance). These calls to `actions/go-versions` are made via unauthenticated requests,
226
+
which are limited
227
+
to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting). If
228
+
more requests are made within the time frame, then you will start to see rate-limit errors during downloading that looks
229
+
like: `##[error]API rate limit exceeded for...`. After that error the action will try to download versions directly
230
+
from https://storage.googleapis.com/golang, but it also can have rate limit so it's better to put token.
203
231
204
-
To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new) and pass it as the `token` input for the action:
232
+
To get a higher rate limit, you
233
+
can [generate a personal access token on github.com](https://github.com/settings/tokens/new) and pass it as the `token`
234
+
input for the action:
205
235
206
236
```yaml
207
237
uses: actions/setup-go@v3
@@ -210,7 +240,10 @@ with:
210
240
go-version: 1.18
211
241
```
212
242
213
-
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/[email protected]/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)" for more information.
243
+
If the runner is not able to access github.com, any Go versions requested during a workflow run must come from the
244
+
runner's tool cache.
245
+
See "[Setting up the tool cache on self-hosted runners without internet access](https://docs.github.com/en/[email protected]/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)"
0 commit comments