`::warning::go-version-file-behavior: latest-patch could not be honored: unable to resolve ~1.12.16 from the versions manifest. Falling back to the version spec, which may resolve to an older patch release from the runner's tool cache.${osm.EOL}`
);
expect(dlSpy).toHaveBeenCalled();
});
it('leaves a bare minor version unchanged with latest-patch',async()=>{
`::error::go-version-file-behavior: 'latest-patch' is not supported with a custom download base URL because version ranges cannot be resolved against it. Use the default 'exact' behavior.${osm.EOL}`
description:'The Go version to download (if necessary) and use. Supports semver spec and ranges. Be sure to enclose this option in single quotation marks.'
description:'The Go version to download (if necessary) and use. Supports semver spec and ranges. Be sure to enclose this option in single quotation marks.'
go-version-file:
go-version-file:
description:'Path to the go.mod, go.work, .go-version, or .tool-versions file.'
description:'Path to the go.mod, go.work, .go-version, or .tool-versions file.'
go-version-file-behavior:
description:'How to interpret an exact version read from go-version-file. Use "latest-patch" to resolve the newest available patch release of the same minor version (e.g. "1.22.0" in go.mod resolves to the newest 1.22.x); this implies check-latest and is not supported with go-download-base-url. Defaults to "exact", which uses the version as written.'
default:exact
check-latest:
check-latest:
description:'Set this option to true if you want the action to always check for the latest available version that satisfies the version spec'
description:'Set this option to true if you want the action to always check for the latest available version that satisfies the version spec'
// latest-patch depends on the manifest to see patches newer than
// the runner's tool cache, so a silent info line is not enough here
warning(`go-version-file-behavior: latest-patch could not be honored: unable to resolve ${versionSpec} from the versions manifest. Falling back to the version spec, which may resolve to an older patch release from the runner's tool cache.`);
}
else{
else{
core_info(`Failed to resolve version ${versionSpec} from manifest`);
core_info(`Failed to resolve version ${versionSpec} from manifest`);
}
}
@ -43865,18 +43870,37 @@ function parseGoVersionFile(versionFilePath) {
core_info(`Using toolchain directive version ${version} as written (latest-patch does not widen an explicit toolchain pin)`);
}
}
returnversion;
else{
constspec=latestPatchSpec(version);
if(spec===version){
core_info(`Using version ${version} as written (latest-patch only widens exact major.minor.patch versions)`);
}
else{
if(getInput('go-download-base-url')||
process.env['GO_DOWNLOAD_BASE_URL']){
thrownewError(`go-version-file-behavior: 'latest-patch' is not supported with a custom download base URL because version ranges cannot be resolved against it. Use the default 'exact' behavior.`);
- [Caching in monorepos](advanced-usage.md#caching-in-monorepos)
- [Caching in monorepos](advanced-usage.md#caching-in-monorepos)
@ -212,6 +213,37 @@ steps:
- run: go version
- run: go version
```
```
### Using the latest patch release
By default, an exact version read from the version file is used as written: a `go 1.22.0` directive installs exactly Go 1.22.0, even if newer 1.22.x patch releases with security fixes are available.
Set `go-version-file-behavior` to `latest-patch` to instead resolve the newest available patch release of the same minor version that is at least the version in the file (e.g., `go 1.22.0` resolves to the newest 1.22.x):
```yaml
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: 'go.mod'
go-version-file-behavior: 'latest-patch'
- run: go version
```
Because the newest patch release is often not yet present in the runner's tool cache, `latest-patch` implies `check-latest`: the newest matching patch is resolved from the versions manifest rather than from whatever the cache happens to hold.
Two operational effects to be aware of:
- The dependency cache key includes the installed Go version, so with `cache: true` each new Go patch release changes the key: the first run after a patch release rebuilds the module and build caches from scratch.
- If the versions manifest cannot be reached (for example on GitHub Enterprise Server or other runners without github.com access), the action emits a warning and falls back to resolving the version range locally, which may install an older patch release from the runner's tool cache.
Some versions are always used as written and are not affected by `latest-patch`:
- Versions without a patch component (e.g., `go 1.22`), which already resolve to the latest available patch release.
- Prerelease versions (e.g., `go1.22rc1`), which have no patch series to float within.
- An exact version pinned by a go.mod or go.work `toolchain` directive (e.g., `toolchain go1.22.3`): the pin is deliberate and is never widened.
`latest-patch` is not supported together with `go-download-base-url`, which requires an exact version.
## Check latest version
## Check latest version
The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability
The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability
// latest-patch depends on the manifest to see patches newer than
// the runner's tool cache, so a silent info line is not enough here
core.warning(
`go-version-file-behavior: latest-patch could not be honored: unable to resolve ${versionSpec} from the versions manifest. Falling back to the version spec, which may resolve to an older patch release from the runner's tool cache.`
);
}else{
}else{
core.info(`Failed to resolve version ${versionSpec} from manifest`);
core.info(`Failed to resolve version ${versionSpec} from manifest`);
}
}
@ -642,7 +649,16 @@ export function makeSemver(version: string): string {
`Using toolchain directive version ${version} as written (latest-patch does not widen an explicit toolchain pin)`
);
}else{
constspec=installer.latestPatchSpec(version);
if(spec===version){
core.info(
`Using version ${version} as written (latest-patch only widens exact major.minor.patch versions)`
);
}else{
if(
core.getInput('go-download-base-url')||
process.env['GO_DOWNLOAD_BASE_URL']
){
thrownewError(
`go-version-file-behavior: 'latest-patch' is not supported with a custom download base URL because version ranges cannot be resolved against it. Use the default 'exact' behavior.`