Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot]
0955f25542 Bump undici and @actions/http-client
Bumps [undici](https://github.com/nodejs/undici) to 6.23.0 and updates ancestor dependency [@actions/http-client](https://github.com/actions/toolkit/tree/HEAD/packages/http-client). These dependencies need to be updated together.


Updates `undici` from 5.29.0 to 6.23.0
- [Release notes](https://github.com/nodejs/undici/releases)
- [Commits](https://github.com/nodejs/undici/compare/v5.29.0...v6.23.0)

Updates `@actions/http-client` from 2.2.3 to 4.0.0
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/http-client/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/@actions/cache@4.0.0/packages/http-client)

---
updated-dependencies:
- dependency-name: undici
  dependency-version: 6.23.0
  dependency-type: indirect
- dependency-name: "@actions/http-client"
  dependency-version: 4.0.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-02 21:44:42 +00:00
29 changed files with 85439 additions and 32435 deletions

View File

@@ -1,143 +0,0 @@
name: Validate Microsoft build of Go
on:
push:
branches:
- main
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
jobs:
microsoft-basic:
name: 'Microsoft build of Go ${{ matrix.go-version }} on ${{ matrix.os }}'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
go-version: ['1.25', '1.24']
steps:
- uses: actions/checkout@v6
- name: Setup Microsoft build of Go ${{ matrix.go-version }}
uses: ./
with:
go-version: ${{ matrix.go-version }}
go-download-base-url: 'https://aka.ms/golang/release/latest'
cache: false
- name: Verify Go installation
run: go version
- name: Verify Go env
run: go env
- name: Verify Go is functional
shell: bash
run: |
# Create a simple Go program and run it
mkdir -p /tmp/test-go && cd /tmp/test-go
cat > main.go << 'EOF'
package main
import "fmt"
func main() {
fmt.Println("Hello from Microsoft build of Go!")
}
EOF
go run main.go
microsoft-env-var:
name: 'Microsoft build of Go via env var on ${{ matrix.os }}'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
env:
GO_DOWNLOAD_BASE_URL: 'https://aka.ms/golang/release/latest'
steps:
- uses: actions/checkout@v6
- name: Setup Microsoft build of Go via environment variable
uses: ./
with:
go-version: '1.25'
cache: false
- name: Verify Go installation
run: go version
- name: Verify Go is functional
shell: bash
run: |
mkdir -p /tmp/test-go && cd /tmp/test-go
cat > main.go << 'EOF'
package main
import "fmt"
func main() {
fmt.Println("Hello from Microsoft build of Go via env var!")
}
EOF
go run main.go
microsoft-architecture:
name: 'Microsoft build of Go arch ${{ matrix.architecture }} on ${{ matrix.os }}'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
architecture: [x64]
include:
- os: macos-latest
architecture: arm64
steps:
- uses: actions/checkout@v6
- name: Setup Microsoft build of Go with architecture
uses: ./
with:
go-version: '1.25'
go-download-base-url: 'https://aka.ms/golang/release/latest'
architecture: ${{ matrix.architecture }}
cache: false
- name: Verify Go installation
run: go version
microsoft-with-cache:
name: 'Microsoft build of Go with caching on ${{ matrix.os }}'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v6
- name: Setup Microsoft build of Go with caching
uses: ./
with:
go-version: '1.25'
go-download-base-url: 'https://aka.ms/golang/release/latest'
cache: true
- name: Verify Go installation
run: go version
- name: Verify Go is functional
shell: bash
run: |
mkdir -p /tmp/test-go && cd /tmp/test-go
go mod init test
cat > main.go << 'EOF'
package main
import "fmt"
func main() {
fmt.Println("Hello from cached Microsoft build of Go!")
}
EOF
go run main.go

View File

@@ -1,6 +1,6 @@
--- ---
name: "@actions/cache" name: "@actions/cache"
version: 5.0.5 version: 5.0.1
type: npm type: npm
summary: Actions cache lib summary: Actions cache lib
homepage: https://github.com/actions/toolkit/tree/main/packages/cache homepage: https://github.com/actions/toolkit/tree/main/packages/cache

View File

@@ -0,0 +1,20 @@
---
name: "@actions/core"
version: 1.11.1
type: npm
summary: Actions core lib
homepage: https://github.com/actions/toolkit/tree/main/packages/core
license: mit
licenses:
- sources: LICENSE.md
text: |-
The MIT License (MIT)
Copyright 2019 GitHub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
notices: []

View File

@@ -1,6 +1,6 @@
--- ---
name: "@actions/core" name: "@actions/core"
version: 2.0.3 version: 2.0.1
type: npm type: npm
summary: Actions core lib summary: Actions core lib
homepage: https://github.com/actions/toolkit/tree/main/packages/core homepage: https://github.com/actions/toolkit/tree/main/packages/core

View File

@@ -0,0 +1,20 @@
---
name: "@actions/exec"
version: 1.1.1
type: npm
summary: Actions exec lib
homepage: https://github.com/actions/toolkit/tree/main/packages/exec
license: mit
licenses:
- sources: LICENSE.md
text: |-
The MIT License (MIT)
Copyright 2019 GitHub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
notices: []

View File

@@ -1,6 +1,6 @@
--- ---
name: "@actions/glob" name: "@actions/glob"
version: 0.5.1 version: 0.5.0
type: npm type: npm
summary: Actions glob lib summary: Actions glob lib
homepage: https://github.com/actions/toolkit/tree/main/packages/glob homepage: https://github.com/actions/toolkit/tree/main/packages/glob

View File

@@ -0,0 +1,32 @@
---
name: "@actions/http-client"
version: 2.2.3
type: npm
summary: Actions Http Client
homepage: https://github.com/actions/toolkit/tree/main/packages/http-client
license: mit
licenses:
- sources: LICENSE
text: |
Actions Http Client for Node.js
Copyright (c) GitHub, Inc.
All rights reserved.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
notices: []

20
.licenses/npm/@actions/io-1.1.3.dep.yml generated Normal file
View File

@@ -0,0 +1,20 @@
---
name: "@actions/io"
version: 1.1.3
type: npm
summary: Actions io lib
homepage: https://github.com/actions/toolkit/tree/main/packages/io
license: mit
licenses:
- sources: LICENSE.md
text: |-
The MIT License (MIT)
Copyright 2019 GitHub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
notices: []

View File

@@ -1,6 +1,6 @@
--- ---
name: "@actions/tool-cache" name: "@actions/tool-cache"
version: 3.0.1 version: 2.0.2
type: npm type: npm
summary: Actions tool-cache lib summary: Actions tool-cache lib
homepage: https://github.com/actions/toolkit/tree/main/packages/tool-cache homepage: https://github.com/actions/toolkit/tree/main/packages/tool-cache

30
.licenses/npm/@fastify/busboy.dep.yml generated Normal file
View File

@@ -0,0 +1,30 @@
---
name: "@fastify/busboy"
version: 2.1.1
type: npm
summary: A streaming parser for HTML form data for node.js
homepage:
license: mit
licenses:
- sources: LICENSE
text: |-
Copyright Brian White. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
notices: []

View File

@@ -1,6 +1,6 @@
--- ---
name: brace-expansion name: brace-expansion
version: 1.1.13 version: 1.1.12
type: npm type: npm
summary: Brace expansion as known from sh/bash summary: Brace expansion as known from sh/bash
homepage: https://github.com/juliangruber/brace-expansion homepage: https://github.com/juliangruber/brace-expansion

View File

@@ -1,6 +1,6 @@
--- ---
name: fast-xml-builder name: fast-xml-builder
version: 1.1.4 version: 1.0.0
type: npm type: npm
summary: Build XML from JSON without C/C++ based libraries summary: Build XML from JSON without C/C++ based libraries
homepage: homepage:

View File

@@ -1,6 +1,6 @@
--- ---
name: fast-xml-parser name: fast-xml-parser
version: 5.5.11 version: 5.4.1
type: npm type: npm
summary: Validate XML, Parse XML, Build XML without C/C++ based libraries summary: Validate XML, Parse XML, Build XML without C/C++ based libraries
homepage: homepage:

View File

@@ -1,6 +1,6 @@
--- ---
name: strnum name: strnum
version: 2.2.3 version: 2.1.2
type: npm type: npm
summary: Parse String to Number based on configuration summary: Parse String to Number based on configuration
homepage: homepage:

View File

@@ -1,6 +1,6 @@
--- ---
name: undici name: undici
version: 6.24.1 version: 5.29.0
type: npm type: npm
summary: An HTTP/1.1 client, written from scratch for Node.js summary: An HTTP/1.1 client, written from scratch for Node.js
homepage: https://undici.nodejs.org homepage: https://undici.nodejs.org

View File

@@ -1,16 +1,16 @@
--- ---
name: path-expression-matcher name: undici
version: 1.4.0 version: 6.23.0
type: npm type: npm
summary: Efficient path tracking and pattern matching for XML/JSON parsers summary: An HTTP/1.1 client, written from scratch for Node.js
homepage: https://github.com/NaturalIntelligence/path-expression-matcher#readme homepage: https://undici.nodejs.org
license: mit license: mit
licenses: licenses:
- sources: LICENSE - sources: LICENSE
text: | text: |
MIT License MIT License
Copyright (c) 2024 Copyright (c) Matteo Collina and Undici contributors
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@@ -29,4 +29,6 @@ licenses:
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
- sources: README.md
text: MIT
notices: [] notices: []

View File

@@ -54,9 +54,6 @@ See [action.yml](action.yml).
# Architecture to install (auto-detected if not specified) # Architecture to install (auto-detected if not specified)
architecture: 'x64' architecture: 'x64'
# Custom base URL for Go downloads (e.g., for mirrors)
go-download-base-url: ''
``` ```
<!-- end usage --> <!-- end usage -->
@@ -133,7 +130,6 @@ For examples of using `cache-dependency-path`, see the [Caching](docs/advanced-u
- [Check latest version](docs/advanced-usage.md#check-latest-version) - [Check latest version](docs/advanced-usage.md#check-latest-version)
- [Caching](docs/advanced-usage.md#caching) - [Caching](docs/advanced-usage.md#caching)
- [Outputs](docs/advanced-usage.md#outputs) - [Outputs](docs/advanced-usage.md#outputs)
- [Custom download URL](docs/advanced-usage.md#custom-download-url)
- [Using `setup-go` on GHES](docs/advanced-usage.md#using-setup-go-on-ghes) - [Using `setup-go` on GHES](docs/advanced-usage.md#using-setup-go-on-ghes)
## License ## License

View File

@@ -45,7 +45,6 @@ describe('setup-go', () => {
let mkdirSpy: jest.SpyInstance; let mkdirSpy: jest.SpyInstance;
let symlinkSpy: jest.SpyInstance; let symlinkSpy: jest.SpyInstance;
let execSpy: jest.SpyInstance; let execSpy: jest.SpyInstance;
let execFileSpy: jest.SpyInstance;
let getManifestSpy: jest.SpyInstance; let getManifestSpy: jest.SpyInstance;
let getAllVersionsSpy: jest.SpyInstance; let getAllVersionsSpy: jest.SpyInstance;
let httpmGetJsonSpy: jest.SpyInstance; let httpmGetJsonSpy: jest.SpyInstance;
@@ -72,10 +71,6 @@ describe('setup-go', () => {
archSpy = jest.spyOn(osm, 'arch'); archSpy = jest.spyOn(osm, 'arch');
archSpy.mockImplementation(() => os['arch']); archSpy.mockImplementation(() => os['arch']);
execSpy = jest.spyOn(cp, 'execSync'); execSpy = jest.spyOn(cp, 'execSync');
execFileSpy = jest.spyOn(cp, 'execFileSync');
execFileSpy.mockImplementation(() => {
throw new Error('ENOENT');
});
// switch path join behaviour based on set os.platform // switch path join behaviour based on set os.platform
joinSpy = jest.spyOn(path, 'join'); joinSpy = jest.spyOn(path, 'join');
@@ -134,9 +129,8 @@ describe('setup-go', () => {
}); });
afterEach(() => { afterEach(() => {
// clear out env vars set during 'run' // clear out env var set during 'run'
delete process.env[im.GOTOOLCHAIN_ENV_VAR]; delete process.env[im.GOTOOLCHAIN_ENV_VAR];
delete process.env['GO_DOWNLOAD_BASE_URL'];
//jest.resetAllMocks(); //jest.resetAllMocks();
jest.clearAllMocks(); jest.clearAllMocks();
@@ -1111,456 +1105,4 @@ use .
expect(vars).toStrictEqual({GOTOOLCHAIN: 'local'}); expect(vars).toStrictEqual({GOTOOLCHAIN: 'local'});
expect(process.env).toHaveProperty('GOTOOLCHAIN', 'local'); expect(process.env).toHaveProperty('GOTOOLCHAIN', 'local');
}); });
describe('go-download-base-url', () => {
it('downloads a version from custom base URL using version listing', async () => {
os.platform = 'linux';
os.arch = 'x64';
const versionSpec = '1.13.1';
const customBaseUrl = 'https://example.com/golang';
inputs['go-version'] = versionSpec;
inputs['go-download-base-url'] = customBaseUrl;
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
const toolPath = path.normalize('/cache/go/1.13.1/x64');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
const expPath = path.join(toolPath, 'bin');
expect(logSpy).toHaveBeenCalledWith(
`Using custom Go download base URL: ${customBaseUrl}`
);
expect(logSpy).toHaveBeenCalledWith('Install from custom download URL');
// Version listing should use custom base URL, not go.dev
expect(getSpy).toHaveBeenCalledWith(
`${customBaseUrl}/?mode=json&include=all`
);
expect(dlSpy).toHaveBeenCalled();
expect(extractTarSpy).toHaveBeenCalled();
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
it('skips version listing for known direct-download URL (aka.ms)', async () => {
os.platform = 'linux';
os.arch = 'x64';
const versionSpec = '1.25.0';
const customBaseUrl = 'https://aka.ms/golang/release/latest';
inputs['go-version'] = versionSpec;
inputs['go-download-base-url'] = customBaseUrl;
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
const toolPath = path.normalize('/cache/go/1.25.0/x64');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
const expPath = path.join(toolPath, 'bin');
expect(logSpy).toHaveBeenCalledWith(
'Skipping version listing for known direct-download URL. Constructing download URL directly.'
);
expect(logSpy).toHaveBeenCalledWith(
`Constructed direct download URL: ${customBaseUrl}/go1.25.0.linux-amd64.tar.gz`
);
expect(logSpy).toHaveBeenCalledWith('Install from custom download URL');
expect(getSpy).not.toHaveBeenCalled();
expect(dlSpy).toHaveBeenCalled();
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
it('constructs correct direct download URL for windows (aka.ms)', async () => {
os.platform = 'win32';
os.arch = 'x64';
const versionSpec = '1.25.0';
const customBaseUrl = 'https://aka.ms/golang/release/latest';
inputs['go-version'] = versionSpec;
inputs['go-download-base-url'] = customBaseUrl;
process.env['RUNNER_TEMP'] = 'C:\\temp\\';
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => 'C:\\temp\\some\\path');
extractZipSpy.mockImplementation(() => 'C:\\temp\\some\\other\\path');
const toolPath = path.normalize('C:\\cache\\go\\1.25.0\\x64');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
expect(getSpy).not.toHaveBeenCalled();
expect(dlSpy).toHaveBeenCalledWith(
`${customBaseUrl}/go1.25.0.windows-amd64.zip`,
'C:\\temp\\go1.25.0.windows-amd64.zip',
undefined
);
});
it('skips manifest and downloads directly from custom URL', async () => {
os.platform = 'linux';
os.arch = 'x64';
const versionSpec = '1.12.16';
const customBaseUrl = 'https://example.com/golang';
inputs['go-version'] = versionSpec;
inputs['go-download-base-url'] = customBaseUrl;
inputs['token'] = 'faketoken';
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
const toolPath = path.normalize('/cache/go/1.12.16/x64');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
// Should not try to use the manifest at all
expect(logSpy).not.toHaveBeenCalledWith(
expect.stringContaining('Not found in manifest')
);
expect(logSpy).toHaveBeenCalledWith('Install from custom download URL');
});
it('strips trailing slashes from custom base URL', async () => {
os.platform = 'linux';
os.arch = 'x64';
const versionSpec = '1.13.1';
const customBaseUrl = 'https://example.com/golang/';
inputs['go-version'] = versionSpec;
inputs['go-download-base-url'] = customBaseUrl;
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
const toolPath = path.normalize('/cache/go/1.13.1/x64');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
expect(logSpy).toHaveBeenCalledWith(
`Acquiring go1.13.1 from https://example.com/golang/go1.13.1.linux-amd64.tar.gz`
);
});
it('reads custom base URL from environment variable', async () => {
os.platform = 'linux';
os.arch = 'x64';
const versionSpec = '1.13.1';
const customBaseUrl = 'https://example.com/golang';
inputs['go-version'] = versionSpec;
process.env['GO_DOWNLOAD_BASE_URL'] = customBaseUrl;
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
const toolPath = path.normalize('/cache/go/1.13.1/x64');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
expect(logSpy).toHaveBeenCalledWith(
`Using custom Go download base URL: ${customBaseUrl}`
);
expect(logSpy).toHaveBeenCalledWith('Install from custom download URL');
});
it('input takes precedence over environment variable', async () => {
os.platform = 'linux';
os.arch = 'x64';
const versionSpec = '1.13.1';
const inputUrl = 'https://input.example.com/golang';
const envUrl = 'https://env.example.com/golang';
inputs['go-version'] = versionSpec;
inputs['go-download-base-url'] = inputUrl;
process.env['GO_DOWNLOAD_BASE_URL'] = envUrl;
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
const toolPath = path.normalize('/cache/go/1.13.1/x64');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
expect(logSpy).toHaveBeenCalledWith(
`Using custom Go download base URL: ${inputUrl}`
);
expect(logSpy).toHaveBeenCalledWith(
`Acquiring go1.13.1 from ${inputUrl}/go1.13.1.linux-amd64.tar.gz`
);
});
it('errors when stable alias is used with custom URL', async () => {
os.platform = 'linux';
os.arch = 'x64';
inputs['go-version'] = 'stable';
inputs['go-download-base-url'] = 'https://example.com/golang';
findSpy.mockImplementation(() => '');
await main.run();
expect(cnSpy).toHaveBeenCalledWith(
`::error::Version aliases 'stable' are not supported with a custom download base URL. Please specify an exact Go version.${osm.EOL}`
);
});
it('logs info when check-latest is used with custom URL', async () => {
os.platform = 'linux';
os.arch = 'x64';
const versionSpec = '1.13.1';
const customBaseUrl = 'https://example.com/golang';
inputs['go-version'] = versionSpec;
inputs['go-download-base-url'] = customBaseUrl;
inputs['check-latest'] = true;
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
const toolPath = path.normalize('/cache/go/1.13.1/x64');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
expect(logSpy).toHaveBeenCalledWith(
'check-latest is not supported with a custom download base URL. Using the provided version spec directly.'
);
});
it('constructs direct download info correctly', () => {
os.platform = 'linux';
os.arch = 'x64';
const info = im.getInfoFromDirectDownload(
'1.25.0',
'x64',
'https://aka.ms/golang/release/latest'
);
expect(info.type).toBe('dist');
expect(info.downloadUrl).toBe(
'https://aka.ms/golang/release/latest/go1.25.0.linux-amd64.tar.gz'
);
expect(info.fileName).toBe('go1.25.0.linux-amd64.tar.gz');
expect(info.resolvedVersion).toBe('1.25.0');
});
it('constructs direct download info for windows', () => {
os.platform = 'win32';
os.arch = 'x64';
const info = im.getInfoFromDirectDownload(
'1.25.0',
'x64',
'https://aka.ms/golang/release/latest'
);
expect(info.type).toBe('dist');
expect(info.downloadUrl).toBe(
'https://aka.ms/golang/release/latest/go1.25.0.windows-amd64.zip'
);
expect(info.fileName).toBe('go1.25.0.windows-amd64.zip');
});
it('constructs direct download info for arm64', () => {
os.platform = 'darwin';
os.arch = 'arm64';
const info = im.getInfoFromDirectDownload(
'1.25.0',
'arm64',
'https://aka.ms/golang/release/latest'
);
expect(info.type).toBe('dist');
expect(info.downloadUrl).toBe(
'https://aka.ms/golang/release/latest/go1.25.0.darwin-arm64.tar.gz'
);
expect(info.fileName).toBe('go1.25.0.darwin-arm64.tar.gz');
});
it('caches under actual installed version when it differs from input spec', async () => {
os.platform = 'linux';
os.arch = 'x64';
const versionSpec = '1.20';
const customBaseUrl = 'https://aka.ms/golang/release/latest';
inputs['go-version'] = versionSpec;
inputs['go-download-base-url'] = customBaseUrl;
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
// Mock the installed Go binary reporting a different patch version
execFileSpy.mockImplementation(() => 'go version go1.20.14 linux/amd64');
const expectedToolName = im.customToolCacheName(customBaseUrl);
const toolPath = path.normalize(`/cache/${expectedToolName}/1.20.14/x64`);
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
expect(logSpy).toHaveBeenCalledWith(
"Requested version '1.20' resolved to installed version '1.20.14'"
);
// Cache key should use actual version, not the input spec
expect(cacheSpy).toHaveBeenCalledWith(
expect.any(String),
expectedToolName,
'1.20.14',
'x64'
);
});
it('shows clear error with platform/arch and URL on 404', async () => {
os.platform = 'linux';
os.arch = 'arm64';
const versionSpec = '1.25.0';
const customBaseUrl = 'https://example.com/golang';
inputs['go-version'] = versionSpec;
inputs['go-download-base-url'] = customBaseUrl;
getSpy.mockImplementationOnce(() => {
throw new Error('Not a JSON endpoint');
});
findSpy.mockImplementation(() => '');
const httpError = new tc.HTTPError(404);
dlSpy.mockImplementation(() => {
throw httpError;
});
await main.run();
expect(cnSpy).toHaveBeenCalledWith(
expect.stringContaining(
'The requested Go version 1.25.0 is not available for platform linux/arm64'
)
);
expect(cnSpy).toHaveBeenCalledWith(expect.stringContaining('HTTP 404'));
});
it('shows clear error with platform/arch and URL on download failure', async () => {
os.platform = 'linux';
os.arch = 'x64';
const versionSpec = '1.25.0';
const customBaseUrl = 'https://example.com/golang';
inputs['go-version'] = versionSpec;
inputs['go-download-base-url'] = customBaseUrl;
getSpy.mockImplementationOnce(() => {
throw new Error('Not a JSON endpoint');
});
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(() => {
throw new Error('connection refused');
});
await main.run();
expect(cnSpy).toHaveBeenCalledWith(
expect.stringContaining(
'Failed to download Go 1.25.0 for platform linux/x64'
)
);
expect(cnSpy).toHaveBeenCalledWith(
expect.stringContaining(customBaseUrl)
);
});
it.each(['^1.25.0', '~1.25', '>=1.25.0', '<1.26.0', '1.25.x', '1.x'])(
'errors on version range "%s" when version listing is unavailable',
async versionSpec => {
os.platform = 'linux';
os.arch = 'x64';
inputs['go-version'] = versionSpec;
inputs['go-download-base-url'] = 'https://example.com/golang';
// Simulate version listing not available
getSpy.mockImplementationOnce(() => {
throw new Error('Not a JSON endpoint');
});
findSpy.mockImplementation(() => '');
await main.run();
expect(cnSpy).toHaveBeenCalledWith(
expect.stringContaining(
`Version range '${versionSpec}' is not supported with a custom download base URL`
)
);
}
);
it('rejects version range in getInfoFromDirectDownload', () => {
os.platform = 'linux';
os.arch = 'x64';
expect(() =>
im.getInfoFromDirectDownload(
'^1.25.0',
'x64',
'https://example.com/golang'
)
).toThrow(
"Version range '^1.25.0' is not supported with a custom download base URL"
);
});
it('passes token as auth header for custom URL downloads', async () => {
os.platform = 'linux';
os.arch = 'x64';
const versionSpec = '1.25.0';
const customBaseUrl = 'https://private-mirror.example.com/golang';
inputs['go-version'] = versionSpec;
inputs['go-download-base-url'] = customBaseUrl;
inputs['token'] = 'ghp_testtoken123';
getSpy.mockImplementationOnce(() => {
throw new Error('Not a JSON endpoint');
});
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
const expectedToolName = im.customToolCacheName(customBaseUrl);
const toolPath = path.normalize(`/cache/${expectedToolName}/1.25.0/x64`);
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
expect(dlSpy).toHaveBeenCalledWith(
`${customBaseUrl}/go1.25.0.linux-amd64.tar.gz`,
undefined,
'token ghp_testtoken123'
);
});
});
}); });

View File

@@ -19,8 +19,6 @@ inputs:
description: 'Used to specify the path to a dependency file (e.g., go.mod, go.sum)' description: 'Used to specify the path to a dependency file (e.g., go.mod, go.sum)'
architecture: architecture:
description: 'Target architecture for Go to use. Examples: x86, x64. Will use system architecture by default.' description: 'Target architecture for Go to use. Examples: x86, x64. Will use system architecture by default.'
go-download-base-url:
description: 'Custom base URL for downloading Go distributions. Use this to download Go from a mirror or custom source. Defaults to "https://go.dev/dl". Can also be set via the GO_DOWNLOAD_BASE_URL environment variable. The input takes precedence over the environment variable.'
outputs: outputs:
go-version: go-version:
description: 'The installed Go version. Useful when given a version range as input.' description: 'The installed Go version. Useful when given a version range as input.'

58071
dist/cache-save/index.js vendored

File diff suppressed because one or more lines are too long

58422
dist/setup/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -12,7 +12,6 @@
- [Restore-only caches](advanced-usage.md#restore-only-caches) - [Restore-only caches](advanced-usage.md#restore-only-caches)
- [Parallel builds](advanced-usage.md#parallel-builds) - [Parallel builds](advanced-usage.md#parallel-builds)
- [Outputs](advanced-usage.md#outputs) - [Outputs](advanced-usage.md#outputs)
- [Custom download URL](advanced-usage.md#custom-download-url)
- [Using `setup-go` on GHES](advanced-usage.md#using-setup-go-on-ghes) - [Using `setup-go` on GHES](advanced-usage.md#using-setup-go-on-ghes)
## Using the `go-version` input ## Using the `go-version` input
@@ -223,8 +222,6 @@ want the most up-to-date Go version to always be used. It supports major (e.g.,
> Setting `check-latest` to `true` has performance implications as downloading Go versions is slower than using cached > Setting `check-latest` to `true` has performance implications as downloading Go versions is slower than using cached
> versions. > versions.
>
> `check-latest` is ignored when `go-download-base-url` is set. See [Custom download URL](#custom-download-url) for details.
```yaml ```yaml
steps: steps:
@@ -420,57 +417,6 @@ jobs:
- run: echo "Was the Go cache restored? ${{ steps.go124.outputs.cache-hit }}" # true if cache-hit occurred - run: echo "Was the Go cache restored? ${{ steps.go124.outputs.cache-hit }}" # true if cache-hit occurred
``` ```
## 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.
When a custom base URL is provided, the action skips the `actions/go-versions` manifest lookup and downloads directly from the specified URL.
**Using the [Microsoft build of Go](https://github.com/microsoft/go):**
```yaml
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: '1.25'
go-download-base-url: 'https://aka.ms/golang/release/latest'
- run: go version
```
**Using an environment variable:**
```yaml
env:
GO_DOWNLOAD_BASE_URL: 'https://aka.ms/golang/release/latest'
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: '1.25'
- run: go version
```
> **Note:** Version range syntax (`^1.25`, `~1.24`, `>=1.25.0`) and aliases (`stable`, `oldstable`) are not supported with custom download URLs. Use exact versions such as `1.25`, `1.25.0`, or `1.25.0-1` (for sources that use revision numbers). If the custom server provides a version listing endpoint (`/?mode=json&include=all`), semver ranges will work; otherwise only exact versions are accepted.
> **Note:** The `check-latest` option is ignored when a custom download base URL is set. The action cannot query the custom server for the latest version, so it uses the version you specify directly. If you provide a partial version like `1.25`, the server determines which patch release to serve.
**Authenticated downloads:**
If your custom download source requires authentication, the `token` input is forwarded as an `Authorization` header. For example, to download from a private mirror:
```yaml
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: '1.25'
go-download-base-url: 'https://private-mirror.example.com/golang'
token: ${{ secrets.MIRROR_TOKEN }}
- run: go version
```
## Using `setup-go` on GHES ## Using `setup-go` on GHES
### Avoiding rate limit issues ### Avoiding rate limit issues

256
package-lock.json generated
View File

@@ -9,13 +9,13 @@
"version": "6.2.0", "version": "6.2.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/cache": "^5.0.5", "@actions/cache": "^5.0.1",
"@actions/core": "^2.0.3", "@actions/core": "^1.11.1",
"@actions/exec": "^2.0.0", "@actions/exec": "^1.1.1",
"@actions/glob": "^0.5.1", "@actions/glob": "^0.5.0",
"@actions/http-client": "^3.0.2", "@actions/http-client": "^4.0.0",
"@actions/io": "^2.0.0", "@actions/io": "^1.0.2",
"@actions/tool-cache": "^3.0.1", "@actions/tool-cache": "^2.0.2",
"semver": "^7.7.3" "semver": "^7.7.3"
}, },
"devDependencies": { "devDependencies": {
@@ -41,15 +41,14 @@
} }
}, },
"node_modules/@actions/cache": { "node_modules/@actions/cache": {
"version": "5.0.5", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/@actions/cache/-/cache-5.0.5.tgz", "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-5.0.1.tgz",
"integrity": "sha512-jiQSg0gfd+C2KPgcmdCOq7dCuCIQQWQ4b1YfGIRaaA9w7PJbRwTOcCz4LiFEUnqZGf0ha/8OKL3BeNwetHzYsQ==", "integrity": "sha512-c+oH047Z2zmXLhjMZfEKjxZfv6Ou7T0sn5fhz6yupICXm5OOR47oZn5zxNO8MP7ttkxv5TOg3WsMrffri5Xhfw==",
"license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^2.0.0", "@actions/core": "^2.0.0",
"@actions/exec": "^2.0.0", "@actions/exec": "^2.0.0",
"@actions/glob": "^0.5.1", "@actions/glob": "^0.5.0",
"@actions/http-client": "^3.0.2", "@actions/http-client": "^3.0.0",
"@actions/io": "^2.0.0", "@actions/io": "^2.0.0",
"@azure/abort-controller": "^1.1.0", "@azure/abort-controller": "^1.1.0",
"@azure/core-rest-pipeline": "^1.22.0", "@azure/core-rest-pipeline": "^1.22.0",
@@ -58,6 +57,41 @@
"semver": "^6.3.1" "semver": "^6.3.1"
} }
}, },
"node_modules/@actions/cache/node_modules/@actions/core": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-2.0.1.tgz",
"integrity": "sha512-oBfqT3GwkvLlo1fjvhQLQxuwZCGTarTE5OuZ2Wg10hvhBj7LRIlF611WT4aZS6fDhO5ZKlY7lCAZTlpmyaHaeg==",
"license": "MIT",
"dependencies": {
"@actions/exec": "^2.0.0",
"@actions/http-client": "^3.0.0"
}
},
"node_modules/@actions/cache/node_modules/@actions/exec": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-2.0.0.tgz",
"integrity": "sha512-k8ngrX2voJ/RIN6r9xB82NVqKpnMRtxDoiO+g3olkIUpQNqjArXrCQceduQZCQj3P3xm32pChRLqRrtXTlqhIw==",
"license": "MIT",
"dependencies": {
"@actions/io": "^2.0.0"
}
},
"node_modules/@actions/cache/node_modules/@actions/http-client": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-3.0.2.tgz",
"integrity": "sha512-JP38FYYpyqvUsz+Igqlc/JG6YO9PaKuvqjM3iGvaLqFnJ7TFmcLyy2IDrY0bI0qCQug8E9K+elv5ZNfw62ZJzA==",
"license": "MIT",
"dependencies": {
"tunnel": "^0.0.6",
"undici": "^6.23.0"
}
},
"node_modules/@actions/cache/node_modules/@actions/io": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@actions/io/-/io-2.0.0.tgz",
"integrity": "sha512-Jv33IN09XLO+0HS79aaODsvIRyduiF7NY/F6LYeK5oeUmrsz7aFdRphQjFoESF4jS7lMauDOttKALcpapVDIAg==",
"license": "MIT"
},
"node_modules/@actions/cache/node_modules/semver": { "node_modules/@actions/cache/node_modules/semver": {
"version": "6.3.1", "version": "6.3.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
@@ -68,38 +102,60 @@
} }
}, },
"node_modules/@actions/core": { "node_modules/@actions/core": {
"version": "2.0.3", "version": "1.11.1",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-2.0.3.tgz", "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.11.1.tgz",
"integrity": "sha512-Od9Thc3T1mQJYddvVPM4QGiLUewdh+3txmDYHHxoNdkqysR1MbCT+rFOtNUxYAz+7+6RIsqipVahY2GJqGPyxA==", "integrity": "sha512-hXJCSrkwfA46Vd9Z3q4cpEpHB1rL5NG04+/rbqW9d3+CSvtB1tYe8UTpAlixa1vj0m/ULglfEK2UKxMGxCxv5A==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/exec": "^2.0.0", "@actions/exec": "^1.1.1",
"@actions/http-client": "^3.0.2" "@actions/http-client": "^2.0.1"
}
},
"node_modules/@actions/core/node_modules/@actions/http-client": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.3.tgz",
"integrity": "sha512-mx8hyJi/hjFvbPokCg4uRd4ZX78t+YyRPtnKWwIl+RzNaVuFpQHfmlGVfsKEJN8LwTCvL+DfVgAM04XaHkm6bA==",
"license": "MIT",
"dependencies": {
"tunnel": "^0.0.6",
"undici": "^5.25.4"
}
},
"node_modules/@actions/core/node_modules/undici": {
"version": "5.29.0",
"resolved": "https://registry.npmjs.org/undici/-/undici-5.29.0.tgz",
"integrity": "sha512-raqeBD6NQK4SkWhQzeYKd1KmIG6dllBOTt55Rmkt4HtI9mwdWtJljnrXjAFUBLTSN67HWrOIZ3EPF4kjUw80Bg==",
"license": "MIT",
"dependencies": {
"@fastify/busboy": "^2.0.0"
},
"engines": {
"node": ">=14.0"
} }
}, },
"node_modules/@actions/exec": { "node_modules/@actions/exec": {
"version": "2.0.0", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-2.0.0.tgz", "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz",
"integrity": "sha512-k8ngrX2voJ/RIN6r9xB82NVqKpnMRtxDoiO+g3olkIUpQNqjArXrCQceduQZCQj3P3xm32pChRLqRrtXTlqhIw==", "integrity": "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/io": "^2.0.0" "@actions/io": "^1.0.1"
} }
}, },
"node_modules/@actions/glob": { "node_modules/@actions/glob": {
"version": "0.5.1", "version": "0.5.0",
"resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.5.1.tgz", "resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.5.0.tgz",
"integrity": "sha512-+dv/t2aKQdKp9WWSp+1yIXVJzH5Q38M0Mta26pzIbeec14EcIleMB7UU6N7sNgbEuYfyuVGpE5pOKjl6j1WXkA==", "integrity": "sha512-tST2rjPvJLRZLuT9NMUtyBjvj9Yo0MiJS3ow004slMvm8GFM+Zv9HvMJ7HWzfUyJnGrJvDsYkWBaaG3YKXRtCw==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^2.0.3", "@actions/core": "^1.9.1",
"minimatch": "^3.0.4" "minimatch": "^3.0.4"
} }
}, },
"node_modules/@actions/http-client": { "node_modules/@actions/http-client": {
"version": "3.0.2", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-3.0.2.tgz", "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-4.0.0.tgz",
"integrity": "sha512-JP38FYYpyqvUsz+Igqlc/JG6YO9PaKuvqjM3iGvaLqFnJ7TFmcLyy2IDrY0bI0qCQug8E9K+elv5ZNfw62ZJzA==", "integrity": "sha512-QuwPsgVMsD6qaPD57GLZi9sqzAZCtiJT8kVBCDpLtxhL5MydQ4gS+DrejtZZPdIYyB1e95uCK9Luyds7ybHI3g==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"tunnel": "^0.0.6", "tunnel": "^0.0.6",
@@ -107,24 +163,34 @@
} }
}, },
"node_modules/@actions/io": { "node_modules/@actions/io": {
"version": "2.0.0", "version": "1.1.3",
"resolved": "https://registry.npmjs.org/@actions/io/-/io-2.0.0.tgz", "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz",
"integrity": "sha512-Jv33IN09XLO+0HS79aaODsvIRyduiF7NY/F6LYeK5oeUmrsz7aFdRphQjFoESF4jS7lMauDOttKALcpapVDIAg==", "integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/@actions/tool-cache": { "node_modules/@actions/tool-cache": {
"version": "3.0.1", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-3.0.1.tgz", "resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-2.0.2.tgz",
"integrity": "sha512-euK7sID37jMg1yWGkdXkLPI5Te7x/+2QMUPeHXogcpzUZ81mqlDZ+CgYhQo3LtB8LpVnnQyjs+hTTU0Ir4Y0RQ==", "integrity": "sha512-fBhNNOWxuoLxztQebpOaWu6WeVmuwa77Z+DxIZ1B+OYvGkGQon6kTVg6Z32Cb13WCuw0szqonK+hh03mJV7Z6w==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^2.0.1", "@actions/core": "^1.11.1",
"@actions/exec": "^2.0.0", "@actions/exec": "^1.0.0",
"@actions/http-client": "^3.0.2", "@actions/http-client": "^2.0.1",
"@actions/io": "^2.0.0", "@actions/io": "^1.1.1",
"semver": "^6.1.0" "semver": "^6.1.0"
} }
}, },
"node_modules/@actions/tool-cache/node_modules/@actions/http-client": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.3.tgz",
"integrity": "sha512-mx8hyJi/hjFvbPokCg4uRd4ZX78t+YyRPtnKWwIl+RzNaVuFpQHfmlGVfsKEJN8LwTCvL+DfVgAM04XaHkm6bA==",
"license": "MIT",
"dependencies": {
"tunnel": "^0.0.6",
"undici": "^5.25.4"
}
},
"node_modules/@actions/tool-cache/node_modules/semver": { "node_modules/@actions/tool-cache/node_modules/semver": {
"version": "6.3.1", "version": "6.3.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
@@ -134,6 +200,18 @@
"semver": "bin/semver.js" "semver": "bin/semver.js"
} }
}, },
"node_modules/@actions/tool-cache/node_modules/undici": {
"version": "5.29.0",
"resolved": "https://registry.npmjs.org/undici/-/undici-5.29.0.tgz",
"integrity": "sha512-raqeBD6NQK4SkWhQzeYKd1KmIG6dllBOTt55Rmkt4HtI9mwdWtJljnrXjAFUBLTSN67HWrOIZ3EPF4kjUw80Bg==",
"license": "MIT",
"dependencies": {
"@fastify/busboy": "^2.0.0"
},
"engines": {
"node": ">=14.0"
}
},
"node_modules/@azure/abort-controller": { "node_modules/@azure/abort-controller": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-1.1.0.tgz", "resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-1.1.0.tgz",
@@ -1019,6 +1097,15 @@
"node": "^12.22.0 || ^14.17.0 || >=16.0.0" "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
} }
}, },
"node_modules/@fastify/busboy": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz",
"integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==",
"license": "MIT",
"engines": {
"node": ">=14"
}
},
"node_modules/@humanwhocodes/config-array": { "node_modules/@humanwhocodes/config-array": {
"version": "0.13.0", "version": "0.13.0",
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.13.0.tgz", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.13.0.tgz",
@@ -1909,9 +1996,9 @@
} }
}, },
"node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": { "node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": {
"version": "2.0.3", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.3.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz",
"integrity": "sha512-MCV/fYJEbqx68aE58kv2cA/kiky1G8vux3OR6/jbS+jIMe/6fJWa0DTzJU7dqijOWYwHi1t29FlfYI9uytqlpA==", "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@@ -2298,9 +2385,9 @@
} }
}, },
"node_modules/brace-expansion": { "node_modules/brace-expansion": {
"version": "1.1.13", "version": "1.1.12",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.13.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz",
"integrity": "sha512-9ZLprWS6EENmhEOpjCYW2c8VkmOvckIJZfkr7rBW6dObmfgJ/L1GpSYW5Hpo9lDz4D1+n0Ckz8rU7FwHDQiG/w==", "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
@@ -3315,24 +3402,21 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/fast-xml-builder": { "node_modules/fast-xml-builder": {
"version": "1.1.4", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/fast-xml-builder/-/fast-xml-builder-1.1.4.tgz", "resolved": "https://registry.npmjs.org/fast-xml-builder/-/fast-xml-builder-1.0.0.tgz",
"integrity": "sha512-f2jhpN4Eccy0/Uz9csxh3Nu6q4ErKxf0XIsasomfOihuSUa3/xw6w8dnOtCDgEItQFJG8KyXPzQXzcODDrrbOg==", "integrity": "sha512-fpZuDogrAgnyt9oDDz+5DBz0zgPdPZz6D4IR7iESxRXElrlGTRkHJ9eEt+SACRJwT0FNFrt71DFQIUFBJfX/uQ==",
"funding": [ "funding": [
{ {
"type": "github", "type": "github",
"url": "https://github.com/sponsors/NaturalIntelligence" "url": "https://github.com/sponsors/NaturalIntelligence"
} }
], ],
"license": "MIT", "license": "MIT"
"dependencies": {
"path-expression-matcher": "^1.1.3"
}
}, },
"node_modules/fast-xml-parser": { "node_modules/fast-xml-parser": {
"version": "5.5.11", "version": "5.4.1",
"resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-5.5.11.tgz", "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-5.4.1.tgz",
"integrity": "sha512-QL0eb0YbSTVWF6tTf1+LEMSgtCEjBYPpnAjoLC8SscESlAjXEIRJ7cHtLG0pLeDFaZLa4VKZLArtA/60ZS7vyA==", "integrity": "sha512-BQ30U1mKkvXQXXkAGcuyUA/GA26oEB7NzOtsxCDtyu62sjGw5QraKFhx2Em3WQNjPw9PG6MQ9yuIIgkSDfGu5A==",
"funding": [ "funding": [
{ {
"type": "github", "type": "github",
@@ -3341,9 +3425,8 @@
], ],
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"fast-xml-builder": "^1.1.4", "fast-xml-builder": "^1.0.0",
"path-expression-matcher": "^1.4.0", "strnum": "^2.1.2"
"strnum": "^2.2.3"
}, },
"bin": { "bin": {
"fxparser": "src/cli/cli.js" "fxparser": "src/cli/cli.js"
@@ -3428,9 +3511,9 @@
} }
}, },
"node_modules/flatted": { "node_modules/flatted": {
"version": "3.4.2", "version": "3.3.3",
"resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.2.tgz", "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.3.tgz",
"integrity": "sha512-PjDse7RzhcPkIJwy5t7KPWQSZ9cAbzQXcafsetQoD7sOJRQlGikNbx7yZp2OotDnJyrDcbyRq3Ttb18iYOqkxA==", "integrity": "sha512-GX+ysw4PBCz0PzosHDepZGANEuFCMLrnRTiEy9McGjmkCQYwRq4A/X786G/fjM/+OjsWSU1ZrY5qyARZmO/uwg==",
"dev": true, "dev": true,
"license": "ISC" "license": "ISC"
}, },
@@ -3647,9 +3730,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/handlebars": { "node_modules/handlebars": {
"version": "4.7.9", "version": "4.7.8",
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.9.tgz", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.8.tgz",
"integrity": "sha512-4E71E0rpOaQuJR2A3xDZ+GM1HyWYv1clR58tC8emQNeQe3RH7MAzSbat+V0wG78LQBo6m6bzSG/L4pBuCsgnUQ==", "integrity": "sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@@ -4814,9 +4897,9 @@
} }
}, },
"node_modules/lodash": { "node_modules/lodash": {
"version": "4.18.1", "version": "4.17.23",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.23.tgz",
"integrity": "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==", "integrity": "sha512-LgVTMpQtIopCi79SJeDiP0TfWi5CNEc/L/aRdTh3yIvmZXTnheWpKjSZhnvMl8iXbC1tFg9gdHHDMLoV7CnG+w==",
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
@@ -5219,21 +5302,6 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/path-expression-matcher": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/path-expression-matcher/-/path-expression-matcher-1.4.0.tgz",
"integrity": "sha512-s4DQMxIdhj3jLFWd9LxHOplj4p9yQ4ffMGowFf3cpEgrrJjEhN0V5nxw4Ye1EViAGDoL4/1AeO6qHpqYPOzE4Q==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/NaturalIntelligence"
}
],
"license": "MIT",
"engines": {
"node": ">=14.0.0"
}
},
"node_modules/path-is-absolute": { "node_modules/path-is-absolute": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
@@ -5279,9 +5347,9 @@
"license": "ISC" "license": "ISC"
}, },
"node_modules/picomatch": { "node_modules/picomatch": {
"version": "2.3.2", "version": "2.3.1",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
"integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
@@ -5975,9 +6043,9 @@
} }
}, },
"node_modules/strnum": { "node_modules/strnum": {
"version": "2.2.3", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/strnum/-/strnum-2.2.3.tgz", "resolved": "https://registry.npmjs.org/strnum/-/strnum-2.1.2.tgz",
"integrity": "sha512-oKx6RUCuHfT3oyVjtnrmn19H1SiCqgJSg+54XqURKp5aCMbrXrhLjRN9TjuwMjiYstZ0MzDrHqkGZ5dFTKd+zg==", "integrity": "sha512-l63NF9y/cLROq/yqKXSLtcMeeyOfnSQlfMSlzFt/K73oIaD8DGaQWd7Z34X9GPiKqP5rbSh84Hl4bOlLcjiSrQ==",
"funding": [ "funding": [
{ {
"type": "github", "type": "github",
@@ -6070,9 +6138,9 @@
} }
}, },
"node_modules/tinyglobby/node_modules/picomatch": { "node_modules/tinyglobby/node_modules/picomatch": {
"version": "4.0.4", "version": "4.0.3",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.4.tgz", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz",
"integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==", "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
@@ -6261,9 +6329,9 @@
} }
}, },
"node_modules/undici": { "node_modules/undici": {
"version": "6.24.1", "version": "6.23.0",
"resolved": "https://registry.npmjs.org/undici/-/undici-6.24.1.tgz", "resolved": "https://registry.npmjs.org/undici/-/undici-6.23.0.tgz",
"integrity": "sha512-sC+b0tB1whOCzbtlx20fx3WgCXwkW627p4EA9uM+/tNNPkSS+eSEld6pAs9nDv7WbY1UUljBMYPtu9BCOrCWKA==", "integrity": "sha512-VfQPToRA5FZs/qJxLIinmU59u0r7LXqoJkCzinq3ckNJp3vKEh7jTWN589YQ5+aoAC/TGRLyJLCPKcLQbM8r9g==",
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": ">=18.17" "node": ">=18.17"

View File

@@ -28,13 +28,13 @@
"author": "GitHub", "author": "GitHub",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/cache": "^5.0.5", "@actions/cache": "^5.0.1",
"@actions/core": "^2.0.3", "@actions/core": "^1.11.1",
"@actions/exec": "^2.0.0", "@actions/exec": "^1.1.1",
"@actions/glob": "^0.5.1", "@actions/glob": "^0.5.0",
"@actions/http-client": "^3.0.2", "@actions/http-client": "^4.0.0",
"@actions/io": "^2.0.0", "@actions/io": "^1.0.2",
"@actions/tool-cache": "^3.0.1", "@actions/tool-cache": "^2.0.2",
"semver": "^7.7.3" "semver": "^7.7.3"
}, },
"devDependencies": { "devDependencies": {

View File

@@ -4,8 +4,6 @@ import * as path from 'path';
import * as semver from 'semver'; import * as semver from 'semver';
import * as httpm from '@actions/http-client'; import * as httpm from '@actions/http-client';
import * as sys from './system'; import * as sys from './system';
import crypto from 'crypto';
import cp from 'child_process';
import fs from 'fs'; import fs from 'fs';
import os from 'os'; import os from 'os';
import {StableReleaseAlias, isSelfHosted} from './utils'; import {StableReleaseAlias, isSelfHosted} from './utils';
@@ -17,17 +15,11 @@ const MANIFEST_REPO_OWNER = 'actions';
const MANIFEST_REPO_NAME = 'go-versions'; const MANIFEST_REPO_NAME = 'go-versions';
const MANIFEST_REPO_BRANCH = 'main'; const MANIFEST_REPO_BRANCH = 'main';
const MANIFEST_URL = `https://raw.githubusercontent.com/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`; const MANIFEST_URL = `https://raw.githubusercontent.com/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`;
const DEFAULT_GO_DOWNLOAD_BASE_URL = 'https://go.dev/dl';
type InstallationType = 'dist' | 'manifest'; type InstallationType = 'dist' | 'manifest';
const GOLANG_DOWNLOAD_URL = 'https://go.dev/dl/?mode=json&include=all'; const GOLANG_DOWNLOAD_URL = 'https://go.dev/dl/?mode=json&include=all';
// Base URLs known to not serve a version listing JSON endpoint.
// For these URLs we skip the getInfoFromDist() call entirely and construct
// the download URL directly, avoiding a guaranteed-404 HTTP request.
const NO_VERSION_LISTING_BASE_URLS = ['https://aka.ms/golang/release/latest'];
export interface IGoVersionFile { export interface IGoVersionFile {
filename: string; filename: string;
// darwin, linux, windows // darwin, linux, windows
@@ -52,23 +44,15 @@ export async function getGo(
versionSpec: string, versionSpec: string,
checkLatest: boolean, checkLatest: boolean,
auth: string | undefined, auth: string | undefined,
arch: Architecture = os.arch() as Architecture, arch: Architecture = os.arch() as Architecture
goDownloadBaseUrl?: string
) { ) {
let manifest: tc.IToolRelease[] | undefined; let manifest: tc.IToolRelease[] | undefined;
const osPlat: string = os.platform(); const osPlat: string = os.platform();
const customBaseUrl = goDownloadBaseUrl?.replace(/\/+$/, '');
if ( if (
versionSpec === StableReleaseAlias.Stable || versionSpec === StableReleaseAlias.Stable ||
versionSpec === StableReleaseAlias.OldStable versionSpec === StableReleaseAlias.OldStable
) { ) {
if (customBaseUrl) {
throw new Error(
`Version aliases '${versionSpec}' are not supported with a custom download base URL. Please specify an exact Go version.`
);
}
manifest = await getManifest(auth); manifest = await getManifest(auth);
let stableVersion = await resolveStableVersionInput( let stableVersion = await resolveStableVersionInput(
versionSpec, versionSpec,
@@ -92,38 +76,24 @@ export async function getGo(
} }
if (checkLatest) { if (checkLatest) {
if (customBaseUrl) { core.info('Attempting to resolve the latest version from the manifest...');
core.info( const resolvedVersion = await resolveVersionFromManifest(
'check-latest is not supported with a custom download base URL. Using the provided version spec directly.' versionSpec,
); true,
auth,
arch,
manifest
);
if (resolvedVersion) {
versionSpec = resolvedVersion;
core.info(`Resolved as '${versionSpec}'`);
} else { } else {
core.info( core.info(`Failed to resolve version ${versionSpec} from manifest`);
'Attempting to resolve the latest version from the manifest...'
);
const resolvedVersion = await resolveVersionFromManifest(
versionSpec,
true,
auth,
arch,
manifest
);
if (resolvedVersion) {
versionSpec = resolvedVersion;
core.info(`Resolved as '${versionSpec}'`);
} else {
core.info(`Failed to resolve version ${versionSpec} from manifest`);
}
} }
} }
// Use a distinct tool cache name for custom downloads to avoid
// colliding with the runner's pre-installed Go
const toolCacheName = customBaseUrl
? customToolCacheName(customBaseUrl)
: 'go';
// check cache // check cache
const toolPath = tc.find(toolCacheName, versionSpec, arch); const toolPath = tc.find('go', versionSpec, arch);
// If not found in cache, download // If not found in cache, download
if (toolPath) { if (toolPath) {
core.info(`Found in cache @ ${toolPath}`); core.info(`Found in cache @ ${toolPath}`);
@@ -133,93 +103,49 @@ export async function getGo(
let downloadPath = ''; let downloadPath = '';
let info: IGoVersionInfo | null = null; let info: IGoVersionInfo | null = null;
if (customBaseUrl) { //
// // Try download from internal distribution (popular versions only)
// Download from custom base URL //
// try {
const skipVersionListing = NO_VERSION_LISTING_BASE_URLS.some( info = await getInfoFromManifest(versionSpec, true, auth, arch, manifest);
url => customBaseUrl.toLowerCase() === url.toLowerCase() if (info) {
); downloadPath = await installGoVersion(info, auth, arch);
if (skipVersionListing) {
core.info(
'Skipping version listing for known direct-download URL. Constructing download URL directly.'
);
info = getInfoFromDirectDownload(versionSpec, arch, customBaseUrl);
} else { } else {
try { core.info(
info = await getInfoFromDist(versionSpec, arch, customBaseUrl); 'Not found in manifest. Falling back to download directly from Go'
} catch {
core.info(
'Version listing not available from custom URL. Constructing download URL directly.'
);
}
if (!info) {
info = getInfoFromDirectDownload(versionSpec, arch, customBaseUrl);
}
}
try {
core.info('Install from custom download URL');
downloadPath = await installGoVersion(info, auth, arch, toolCacheName);
} catch (err) {
const downloadUrl = info?.downloadUrl || customBaseUrl;
if (err instanceof tc.HTTPError && err.httpStatusCode === 404) {
throw new Error(
`The requested Go version ${versionSpec} is not available for platform ${osPlat}/${arch}. ` +
`Download URL returned HTTP 404: ${downloadUrl}`
);
}
throw new Error(
`Failed to download Go ${versionSpec} for platform ${osPlat}/${arch} ` +
`from ${downloadUrl}: ${err}`
); );
} }
} else { } catch (err) {
// if (
// Try download from internal distribution (popular versions only) err instanceof tc.HTTPError &&
// (err.httpStatusCode === 403 || err.httpStatusCode === 429)
try { ) {
info = await getInfoFromManifest(versionSpec, true, auth, arch, manifest); core.info(
if (info) { `Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
downloadPath = await installGoVersion(info, auth, arch); );
} else { } else {
core.info( core.info((err as Error).message);
'Not found in manifest. Falling back to download directly from Go' }
); core.debug((err as Error).stack ?? '');
} core.info('Falling back to download directly from Go');
} catch (err) { }
if (
err instanceof tc.HTTPError && //
(err.httpStatusCode === 403 || err.httpStatusCode === 429) // Download from storage.googleapis.com
) { //
core.info( if (!downloadPath) {
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded` info = await getInfoFromDist(versionSpec, arch);
); if (!info) {
} else { throw new Error(
core.info((err as Error).message); `Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`
} );
core.debug((err as Error).stack ?? '');
core.info('Falling back to download directly from Go');
} }
// try {
// Download from storage.googleapis.com core.info('Install from dist');
// downloadPath = await installGoVersion(info, undefined, arch);
if (!downloadPath) { } catch (err) {
info = await getInfoFromDist(versionSpec, arch); throw new Error(`Failed to download version ${versionSpec}: ${err}`);
if (!info) {
throw new Error(
`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`
);
}
try {
core.info('Install from dist');
downloadPath = await installGoVersion(info, undefined, arch);
} catch (err) {
throw new Error(`Failed to download version ${versionSpec}: ${err}`);
}
} }
} }
@@ -303,26 +229,20 @@ async function cacheWindowsDir(
async function addExecutablesToToolCache( async function addExecutablesToToolCache(
extPath: string, extPath: string,
info: IGoVersionInfo, info: IGoVersionInfo,
arch: string, arch: string
toolName: string = 'go'
): Promise<string> { ): Promise<string> {
const tool = 'go';
const version = makeSemver(info.resolvedVersion); const version = makeSemver(info.resolvedVersion);
return ( return (
(await cacheWindowsDir(extPath, toolName, version, arch)) || (await cacheWindowsDir(extPath, tool, version, arch)) ||
(await tc.cacheDir(extPath, toolName, version, arch)) (await tc.cacheDir(extPath, tool, version, arch))
); );
} }
export function customToolCacheName(baseUrl: string): string {
const hash = crypto.createHash('sha256').update(baseUrl).digest('hex');
return `go-${hash.substring(0, 8)}`;
}
async function installGoVersion( async function installGoVersion(
info: IGoVersionInfo, info: IGoVersionInfo,
auth: string | undefined, auth: string | undefined,
arch: string, arch: string
toolName: string = 'go'
): Promise<string> { ): Promise<string> {
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
@@ -340,48 +260,13 @@ async function installGoVersion(
extPath = path.join(extPath, 'go'); extPath = path.join(extPath, 'go');
} }
// For custom downloads, detect the actual installed version so the cache
// key reflects the real patch level (e.g. input "1.20" may install 1.20.14).
if (toolName !== 'go') {
const actualVersion = detectInstalledGoVersion(extPath);
if (actualVersion && actualVersion !== info.resolvedVersion) {
core.info(
`Requested version '${info.resolvedVersion}' resolved to installed version '${actualVersion}'`
);
info.resolvedVersion = actualVersion;
}
}
core.info('Adding to the cache ...'); core.info('Adding to the cache ...');
const toolCacheDir = await addExecutablesToToolCache( const toolCacheDir = await addExecutablesToToolCache(extPath, info, arch);
extPath,
info,
arch,
toolName
);
core.info(`Successfully cached go to ${toolCacheDir}`); core.info(`Successfully cached go to ${toolCacheDir}`);
return toolCacheDir; return toolCacheDir;
} }
function detectInstalledGoVersion(goDir: string): string | null {
try {
const goBin = path.join(
goDir,
'bin',
os.platform() === 'win32' ? 'go.exe' : 'go'
);
const output = cp.execFileSync(goBin, ['version'], {encoding: 'utf8'});
const match = output.match(/go version go(\S+)/);
return match ? match[1] : null;
} catch (err) {
core.debug(
`Failed to detect installed Go version: ${(err as Error).message}`
);
return null;
}
}
export async function extractGoArchive(archivePath: string): Promise<string> { export async function extractGoArchive(archivePath: string): Promise<string> {
const platform = os.platform(); const platform = os.platform();
let extPath: string; let extPath: string;
@@ -499,23 +384,14 @@ export async function getInfoFromManifest(
async function getInfoFromDist( async function getInfoFromDist(
versionSpec: string, versionSpec: string,
arch: Architecture, arch: Architecture
goDownloadBaseUrl?: string
): Promise<IGoVersionInfo | null> { ): Promise<IGoVersionInfo | null> {
const dlUrl = goDownloadBaseUrl const version: IGoVersion | undefined = await findMatch(versionSpec, arch);
? `${goDownloadBaseUrl}/?mode=json&include=all`
: GOLANG_DOWNLOAD_URL;
const version: IGoVersion | undefined = await findMatch(
versionSpec,
arch,
dlUrl
);
if (!version) { if (!version) {
return null; return null;
} }
const baseUrl = goDownloadBaseUrl || DEFAULT_GO_DOWNLOAD_BASE_URL; const downloadUrl = `https://go.dev/dl/${version.files[0].filename}`;
const downloadUrl = `${baseUrl}/${version.files[0].filename}`;
return <IGoVersionInfo>{ return <IGoVersionInfo>{
type: 'dist', type: 'dist',
@@ -525,43 +401,9 @@ async function getInfoFromDist(
}; };
} }
export function getInfoFromDirectDownload(
versionSpec: string,
arch: Architecture,
goDownloadBaseUrl: string
): IGoVersionInfo {
// Reject version specs that can't map to an artifact filename
if (/[~^>=<|*x]/.test(versionSpec)) {
throw new Error(
`Version range '${versionSpec}' is not supported with a custom download base URL ` +
`when version listing is unavailable. Please specify an exact version (e.g., '1.25.0').`
);
}
const archStr = sys.getArch(arch);
const platStr = sys.getPlatform();
const extension = platStr === 'windows' ? 'zip' : 'tar.gz';
// Ensure version has the 'go' prefix for the filename
const goVersion = versionSpec.startsWith('go')
? versionSpec
: `go${versionSpec}`;
const fileName = `${goVersion}.${platStr}-${archStr}.${extension}`;
const downloadUrl = `${goDownloadBaseUrl}/${fileName}`;
core.info(`Constructed direct download URL: ${downloadUrl}`);
return <IGoVersionInfo>{
type: 'dist',
downloadUrl: downloadUrl,
resolvedVersion: versionSpec.replace(/^go/, ''),
fileName: fileName
};
}
export async function findMatch( export async function findMatch(
versionSpec: string, versionSpec: string,
arch: Architecture = os.arch() as Architecture, arch: Architecture = os.arch() as Architecture
dlUrl: string = GOLANG_DOWNLOAD_URL
): Promise<IGoVersion | undefined> { ): Promise<IGoVersion | undefined> {
const archFilter = sys.getArch(arch); const archFilter = sys.getArch(arch);
const platFilter = sys.getPlatform(); const platFilter = sys.getPlatform();
@@ -570,7 +412,7 @@ export async function findMatch(
let match: IGoVersion | undefined; let match: IGoVersion | undefined;
const candidates: IGoVersion[] | null = await module.exports.getVersionsDist( const candidates: IGoVersion[] | null = await module.exports.getVersionsDist(
dlUrl GOLANG_DOWNLOAD_URL
); );
if (!candidates) { if (!candidates) {
throw new Error(`golang download url did not return results`); throw new Error(`golang download url did not return results`);

View File

@@ -34,21 +34,11 @@ export async function run() {
const checkLatest = core.getBooleanInput('check-latest'); const checkLatest = core.getBooleanInput('check-latest');
const goDownloadBaseUrl =
core.getInput('go-download-base-url') ||
process.env['GO_DOWNLOAD_BASE_URL'] ||
undefined;
if (goDownloadBaseUrl) {
core.info(`Using custom Go download base URL: ${goDownloadBaseUrl}`);
}
const installDir = await installer.getGo( const installDir = await installer.getGo(
versionSpec, versionSpec,
checkLatest, checkLatest,
auth, auth,
arch, arch
goDownloadBaseUrl
); );
const installDirVersion = path.basename(path.dirname(installDir)); const installDirVersion = path.basename(path.dirname(installDir));