4
0
Fork 0
mirror of https://github.com/actions/setup-go.git synced 2025-11-10 13:56:55 +00:00

Compare commits

..

1 commit

Author SHA1 Message Date
mahabaleshwars
4a5bb5bb23
Merge c19264c4e0 into c0137caad7 2025-10-27 16:30:02 +00:00
9 changed files with 33 additions and 117 deletions

View file

@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
steps:
- uses: actions/checkout@v5
- name: Setup Go Stable
@ -33,7 +33,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
steps:
- uses: actions/checkout@v5
- name: Setup Go oldStable
@ -48,13 +48,13 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
version: [stable, oldstable]
architecture: [x64, x32]
exclude:
- os: macos-latest
architecture: x32
- os: macos-latest-large
- os: macos-13
architecture: x32
steps:
- uses: actions/checkout@v5
@ -72,7 +72,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest, macos-latest-large]
os: [macos-latest, windows-latest, ubuntu-latest, macos-13]
go: [1.21.13, 1.22.8, 1.23.2]
include:
- os: windows-latest
@ -98,7 +98,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
go-version: ['1.20', '1.21', '1.22', '1.23']
steps:
- uses: actions/checkout@v5
@ -115,7 +115,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
steps:
- uses: actions/checkout@v5
- name: Setup Go and check latest
@ -131,7 +131,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
steps:
- uses: actions/checkout@v5
- name: Setup Go and check latest
@ -142,44 +142,12 @@ jobs:
run: __tests__/verify-go.sh 1.21
shell: bash
go-version-file-with-tool-versions:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
steps:
- uses: actions/checkout@v5
- name: Setup Go and check latest
uses: ./
with:
go-version-file: __tests__/data/.tool-versions
- name: verify go
run: __tests__/verify-go.sh 1.23.2
shell: bash
go-version-file-with-go-version:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
steps:
- uses: actions/checkout@v5
- name: Setup Go from .go-version file
uses: ./
with:
go-version-file: __tests__/data/.go-version
- name: verify go
run: __tests__/verify-go.sh 1.22.4
shell: bash
setup-versions-from-manifest:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest, macos-latest-large]
os: [macos-latest, windows-latest, ubuntu-latest, macos-13]
go: [1.20.14, 1.21.10, 1.22.8, 1.23.2]
steps:
- name: Checkout
@ -199,7 +167,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest-large]
os: [windows-latest, ubuntu-latest, macos-13]
go: [1.11.12]
steps:
- name: Checkout
@ -219,7 +187,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
go-version: [1.20.14, 1.21, 1.22, 1.23]
include:
- os: macos-latest
@ -228,7 +196,7 @@ jobs:
architecture: x64
- os: windows-latest
architecture: x64
- os: macos-latest-large
- os: macos-13
architecture: x64
steps:
- uses: actions/checkout@v5

View file

@ -146,7 +146,7 @@ steps:
**Previous Stable Release**
If `oldstable` is provided, when the current release is 1.23.x, the action will resolve version as 1.22.x, where x is the latest patch release.
If `oldstable` is provided, when current release is 1.23.x, action will resolve version as 1.22.x, where x is the latest patch release.
```yaml
steps:
- uses: actions/checkout@v5
@ -160,7 +160,7 @@ steps:
### Version from go.mod File
The action can automatically detect the Go version from your project's `go.mod`, `go.work`, `.go-version`, or `.tool-versions` file:
The action can automatically detect the Go version from your project's `go.mod` or `go.work` file:
```yaml
steps:
@ -176,50 +176,23 @@ steps:
2. Falls back to the `go` directive version
3. If no patch version is specified, uses the latest available patch
### Version from .go-version or .tool-versions Files
The action also supports reading the Go version from `.go-version` or [`.tool-versions`](https://asdf-vm.com/manage/configuration.html#tool-versions) files:
**Using .go-version file:**
```yaml
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version-file: '.go-version'
- run: go version
```
**Using .tool-versions file:**
```yaml
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version-file: '.tool-versions'
- run: go version
```
The action will search for these files relative to the repository root. You can also specify a custom path:
```yaml
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version-file: 'path/to/.go-version'
- run: go version
```
These files support either major and minor (e.g., 1.18) or major, minor and patch (e.g., 1.18.7) version formats. If the file contains only major and minor versions, the action will search for the latest available patch version.
> **Note**: If both `go-version` and `go-version-file` are provided, `go-version` takes precedence.
The action will search for the `go.mod` file relative to the repository root:
```yaml
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version-file: 'path/to/go.mod'
- run: go version
```
### Check Latest Version
The check-latest flag defaults to false for stability. This ensures your workflow uses a specific, predictable Go version.
When `check-latest: true`, the action verifies if your cached Go version is the latest available. If not, it downloads and uses the newest version.
When check-latest: true: The action verifies if your cached Go version is the latest available. If not, it downloads and uses the newest version.
```yaml
steps:
@ -241,7 +214,7 @@ The action features integrated caching for Go modules and build outputs. Built o
#### Automatic Caching
Default behavior: Searches for `go.sum` in the repository root and uses its hash for the cache key.
Default behavior: Searches for go.sum in the repository root and uses its hash for the cache key.
```yaml
steps:
@ -342,7 +315,7 @@ For more information about semantic versioning, see the [semver documentation](h
# Version or version range of Go to use
go-version: '1.23'
# Path to go.mod, go.work, .go-version, or .tool-versions file
# Path to go.mod or go.work file
go-version-file: 'go.mod'
# Check for latest version
@ -363,7 +336,7 @@ For more information about semantic versioning, see the [semver documentation](h
## Using setup-go on GHES
setup-go comes pre-installed on GHES when Actions is enabled. For dynamic Go version downloads, the action fetches distributions from the [go-versions repository](https://github.com/actions/go-versions/) on github.com (external to your appliance).
setup-go comes pre-installed on GHES when Actions is enabled. For dynamic Go version downloads, the action fetches distributions from actions/go-versions on github.com (external to your appliance).
These calls to `actions/go-versions` are made via unauthenticated requests, which are limited to 60 requests per hour per IP. If more requests are made within the time frame, then the action leverages the raw API to retrieve the version-manifest. This approach does not impose a rate limit and hence facilitates unrestricted consumption. This is particularly beneficial for GHES runners, which often share the same IP, to avoid the quick exhaustion of the unauthenticated rate limit. If that fails as well the action will try to download versions directly from [go.dev](https://storage.googleapis.com/golang).

View file

@ -1 +0,0 @@
1.22.4

View file

@ -1 +0,0 @@
golang 1.23.2

View file

@ -389,7 +389,7 @@ describe('setup-go', () => {
const expPath = path.win32.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalledWith(
'https://go.dev/dl/go1.13.1.windows-amd64.zip',
'https://storage.googleapis.com/golang/go1.13.1.windows-amd64.zip',
'C:\\temp\\go1.13.1.windows-amd64.zip',
undefined
);
@ -866,9 +866,6 @@ exclude example.com/thismodule v1.3.0
use .
`;
const toolVersionsContents = `golang 1.23
`;
it('reads version from go.mod', async () => {
@ -895,18 +892,6 @@ use .
expect(logSpy).toHaveBeenCalledWith('matching 1.19...');
});
it('reads version from .tool-versions', async () => {
inputs['go-version-file'] = '.tool-versions';
existsSpy.mockImplementation(() => true);
readFileSpy.mockImplementation(() => Buffer.from(toolVersionsContents));
await main.run();
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.23');
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.23...');
expect(logSpy).toHaveBeenCalledWith('matching 1.23...');
});
it('reads version from .go-version', async () => {
inputs['go-version-file'] = '.go-version';
existsSpy.mockImplementation(() => true);
@ -961,7 +946,7 @@ use .
const expectedUrl =
platform === 'win32'
? `https://github.com/actions/go-versions/releases/download/${version}/go-${version}-${platform}-${arch}.${fileExtension}`
: `https://go.dev/dl/go${version}.${osSpec}-${arch}.${fileExtension}`;
: `https://storage.googleapis.com/golang/go${version}.${osSpec}-${arch}.${fileExtension}`;
// ... but not in the local cache
findSpy.mockImplementation(() => '');

View file

@ -5,7 +5,7 @@ inputs:
go-version:
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:
description: 'Path to the go.mod, go.work, .go-version, or .tool-versions file.'
description: 'Path to the go.mod or go.work file.'
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'
default: false

6
dist/setup/index.js vendored
View file

@ -94583,7 +94583,7 @@ function getInfoFromDist(versionSpec, arch) {
if (!version) {
return null;
}
const downloadUrl = `https://go.dev/dl/${version.files[0].filename}`;
const downloadUrl = `https://storage.googleapis.com/golang/${version.files[0].filename}`;
return {
type: 'dist',
downloadUrl: downloadUrl,
@ -94679,10 +94679,6 @@ function parseGoVersionFile(versionFilePath) {
const matchGo = contents.match(/^go (\d+(\.\d+)*)/m);
return matchGo ? matchGo[1] : '';
}
else if (path.basename(versionFilePath) === '.tool-versions') {
const match = contents.match(/^golang\s+([^\n#]+)/m);
return match ? match[1].trim() : '';
}
return contents.trim();
}
function resolveStableVersionDist(versionSpec, arch) {

View file

@ -15,7 +15,6 @@ process.on('uncaughtException', e => {
// Added early exit to resolve issue with slow post action step:
// - https://github.com/actions/setup-node/issues/878
// https://github.com/actions/cache/pull/1217
export async function run(earlyExit?: boolean) {
try {
const cacheInput = core.getBooleanInput('cache');

View file

@ -389,7 +389,7 @@ async function getInfoFromDist(
return null;
}
const downloadUrl = `https://go.dev/dl/${version.files[0].filename}`;
const downloadUrl = `https://storage.googleapis.com/golang/${version.files[0].filename}`;
return <IGoVersionInfo>{
type: 'dist',
@ -513,9 +513,6 @@ export function parseGoVersionFile(versionFilePath: string): string {
// go directive: https://go.dev/ref/mod#go-mod-file-go
const matchGo = contents.match(/^go (\d+(\.\d+)*)/m);
return matchGo ? matchGo[1] : '';
} else if (path.basename(versionFilePath) === '.tool-versions') {
const match = contents.match(/^golang\s+([^\n#]+)/m);
return match ? match[1].trim() : '';
}
return contents.trim();