mirror of
https://code.forgejo.org/actions/setup-go.git
synced 2024-11-23 11:21:02 -05:00
Merge branch 'actions:main' into main
This commit is contained in:
commit
339692abda
20 changed files with 2739 additions and 1495 deletions
1
.github/workflows/check-dist.yml
vendored
1
.github/workflows/check-dist.yml
vendored
|
@ -27,6 +27,7 @@ jobs:
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 16.x
|
node-version: 16.x
|
||||||
|
cache: npm
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
|
|
|
@ -21,7 +21,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Update the ${{ env.TAG_NAME }} tag
|
- name: Update the ${{ env.TAG_NAME }} tag
|
||||||
uses: actions/publish-action@v0.1.0
|
uses: actions/publish-action@v0.2.1
|
||||||
with:
|
with:
|
||||||
source-tag: ${{ env.TAG_NAME }}
|
source-tag: ${{ env.TAG_NAME }}
|
||||||
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
||||||
|
|
86
.github/workflows/versions.yml
vendored
86
.github/workflows/versions.yml
vendored
|
@ -12,6 +12,57 @@ on:
|
||||||
- cron: 0 0 * * *
|
- cron: 0 0 * * *
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
stable:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Setup Go Stable
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
go-version: stable
|
||||||
|
- name: Verify Go
|
||||||
|
run: go version
|
||||||
|
|
||||||
|
oldstable:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Setup Go oldStable
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
go-version: oldstable
|
||||||
|
- name: Verify Go
|
||||||
|
run: go version
|
||||||
|
|
||||||
|
aliases-arch:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
version: [stable, oldstable]
|
||||||
|
architecture: [x64, x32]
|
||||||
|
exclude:
|
||||||
|
- os: macos-latest
|
||||||
|
architecture: x32
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Setup Go ${{ matrix.version }} ${{ matrix.architecture }}
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.version }}
|
||||||
|
architecture: ${{ matrix.architecture }}
|
||||||
|
- name: Verify Go
|
||||||
|
run: go version
|
||||||
|
|
||||||
local-cache:
|
local-cache:
|
||||||
name: Setup local-cache version
|
name: Setup local-cache version
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
@ -19,7 +70,7 @@ jobs:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||||
go: [1.12, 1.13, 1.14]
|
go: [1.17, 1.18, 1.19]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
@ -66,6 +117,22 @@ jobs:
|
||||||
run: __tests__/verify-go.sh 1.14
|
run: __tests__/verify-go.sh 1.14
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
|
go-version-file-with-gowork:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Setup Go and check latest
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
go-version-file: __tests__/data/go.work
|
||||||
|
- name: verify go
|
||||||
|
run: __tests__/verify-go.sh 1.19
|
||||||
|
shell: bash
|
||||||
|
|
||||||
setup-versions-from-manifest:
|
setup-versions-from-manifest:
|
||||||
name: Setup ${{ matrix.go }} ${{ matrix.os }}
|
name: Setup ${{ matrix.go }} ${{ matrix.os }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
@ -107,3 +174,20 @@ jobs:
|
||||||
- name: verify go
|
- name: verify go
|
||||||
run: __tests__/verify-go.sh ${{ matrix.go }}
|
run: __tests__/verify-go.sh ${{ matrix.go }}
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
|
architecture:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
go-version: [1.16, 1.17]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Setup Go and check latest
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.go-version }}
|
||||||
|
architecture: x64
|
||||||
|
- name: Verify Go
|
||||||
|
run: go version
|
||||||
|
|
BIN
.licenses/npm/@actions/core.dep.yml
generated
BIN
.licenses/npm/@actions/core.dep.yml
generated
Binary file not shown.
47
README.md
47
README.md
|
@ -16,6 +16,7 @@ The V3 edition of the action offers:
|
||||||
- Proxy support
|
- Proxy support
|
||||||
- Check latest version
|
- Check latest version
|
||||||
- Caching packages dependencies
|
- Caching packages dependencies
|
||||||
|
- stable and oldstable aliases
|
||||||
- Bug Fixes (including issues around version matching and semver)
|
- Bug Fixes (including issues around version matching and semver)
|
||||||
|
|
||||||
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).
|
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).
|
||||||
|
@ -95,6 +96,33 @@ steps:
|
||||||
check-latest: true
|
check-latest: true
|
||||||
- run: go run hello.go
|
- run: go run hello.go
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Using stable/oldstable aliases
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
**Note:** using these aliases will result in same version as using corresponding minor release with `check-latest` input set to `true`
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: 'stable'
|
||||||
|
- run: go run hello.go
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: 'oldstable'
|
||||||
|
- run: go run hello.go
|
||||||
|
```
|
||||||
|
|
||||||
## Caching dependency files and build outputs:
|
## Caching dependency files and build outputs:
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
@ -127,7 +155,7 @@ steps:
|
||||||
```
|
```
|
||||||
## Getting go version from the go.mod file
|
## Getting go version from the go.mod file
|
||||||
|
|
||||||
The `go-version-file` input accepts a path to a `go.mod` file containing 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 [version-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json) file or at the go servers.
|
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 [version-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json) file or at the go servers.
|
||||||
|
|
||||||
If both the `go-version` and the `go-version-file` inputs are provided then the `go-version` input is used.
|
If both the `go-version` and the `go-version-file` inputs are provided then the `go-version` input is used.
|
||||||
> The action will search for the `go.mod` file relative to the repository root
|
> The action will search for the `go.mod` file relative to the repository root
|
||||||
|
@ -169,6 +197,21 @@ The `go-version` input supports the following syntax:
|
||||||
|
|
||||||
For more information about semantic versioning, please refer to [semver](https://github.com/npm/node-semver) documentation.
|
For more information about semantic versioning, please refer to [semver](https://github.com/npm/node-semver) documentation.
|
||||||
|
|
||||||
|
## Using `setup-go` on GHES
|
||||||
|
|
||||||
|
`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.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GH_DOTCOM_TOKEN }}
|
||||||
|
go-version: 1.18
|
||||||
|
```
|
||||||
|
|
||||||
|
If the runner is not able to access github.com, any Go versions requested during a workflow run must come from the runner's tool cache. See "[Setting up the tool cache on self-hosted runners without internet access](https://docs.github.com/en/enterprise-server@3.2/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)" for more information.
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
The scripts and documentation in this project are released under the [MIT License](LICENSE)
|
The scripts and documentation in this project are released under the [MIT License](LICENSE)
|
||||||
|
@ -179,4 +222,4 @@ Contributions are welcome! See [Contributor's Guide](docs/contributors.md)
|
||||||
|
|
||||||
## Code of Conduct
|
## Code of Conduct
|
||||||
|
|
||||||
:wave: Be nice. See [our code of conduct](CONDUCT)
|
:wave: Be nice. See [our code of conduct](CODE_OF_CONDUCT.md)
|
||||||
|
|
|
@ -17,6 +17,7 @@ describe('restoreCache', () => {
|
||||||
let infoSpy = jest.spyOn(core, 'info');
|
let infoSpy = jest.spyOn(core, 'info');
|
||||||
let setOutputSpy = jest.spyOn(core, 'setOutput');
|
let setOutputSpy = jest.spyOn(core, 'setOutput');
|
||||||
|
|
||||||
|
const versionSpec = '1.13.1';
|
||||||
const packageManager = 'default';
|
const packageManager = 'default';
|
||||||
const cacheDependencyPath = 'path';
|
const cacheDependencyPath = 'path';
|
||||||
|
|
||||||
|
@ -40,7 +41,11 @@ describe('restoreCache', () => {
|
||||||
|
|
||||||
//Act + Assert
|
//Act + Assert
|
||||||
expect(async () => {
|
expect(async () => {
|
||||||
await cacheRestore.restoreCache(packageManager, cacheDependencyPath);
|
await cacheRestore.restoreCache(
|
||||||
|
versionSpec,
|
||||||
|
packageManager,
|
||||||
|
cacheDependencyPath
|
||||||
|
);
|
||||||
}).rejects.toThrowError(
|
}).rejects.toThrowError(
|
||||||
'Some specified paths were not resolved, unable to cache dependencies.'
|
'Some specified paths were not resolved, unable to cache dependencies.'
|
||||||
);
|
);
|
||||||
|
@ -61,7 +66,11 @@ describe('restoreCache', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
//Act + Assert
|
//Act + Assert
|
||||||
await cacheRestore.restoreCache(packageManager, cacheDependencyPath);
|
await cacheRestore.restoreCache(
|
||||||
|
versionSpec,
|
||||||
|
packageManager,
|
||||||
|
cacheDependencyPath
|
||||||
|
);
|
||||||
expect(infoSpy).toBeCalledWith(`Cache is not found`);
|
expect(infoSpy).toBeCalledWith(`Cache is not found`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -80,7 +89,11 @@ describe('restoreCache', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
//Act + Assert
|
//Act + Assert
|
||||||
await cacheRestore.restoreCache(packageManager, cacheDependencyPath);
|
await cacheRestore.restoreCache(
|
||||||
|
versionSpec,
|
||||||
|
packageManager,
|
||||||
|
cacheDependencyPath
|
||||||
|
);
|
||||||
expect(setOutputSpy).toBeCalledWith('cache-hit', true);
|
expect(setOutputSpy).toBeCalledWith('cache-hit', true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
3
__tests__/data/go.work
Normal file
3
__tests__/data/go.work
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
go 1.19
|
||||||
|
|
||||||
|
use .
|
|
@ -13,6 +13,8 @@ let matchers = require('../matchers.json');
|
||||||
let goTestManifest = require('./data/versions-manifest.json');
|
let goTestManifest = require('./data/versions-manifest.json');
|
||||||
let matcherPattern = matchers.problemMatcher[0].pattern[0];
|
let matcherPattern = matchers.problemMatcher[0].pattern[0];
|
||||||
let matcherRegExp = new RegExp(matcherPattern.regexp);
|
let matcherRegExp = new RegExp(matcherPattern.regexp);
|
||||||
|
let win32Join = path.win32.join;
|
||||||
|
let posixJoin = path.posix.join;
|
||||||
|
|
||||||
describe('setup-go', () => {
|
describe('setup-go', () => {
|
||||||
let inputs = {} as any;
|
let inputs = {} as any;
|
||||||
|
@ -27,8 +29,10 @@ describe('setup-go', () => {
|
||||||
let getSpy: jest.SpyInstance;
|
let getSpy: jest.SpyInstance;
|
||||||
let platSpy: jest.SpyInstance;
|
let platSpy: jest.SpyInstance;
|
||||||
let archSpy: jest.SpyInstance;
|
let archSpy: jest.SpyInstance;
|
||||||
|
let joinSpy: jest.SpyInstance;
|
||||||
let dlSpy: jest.SpyInstance;
|
let dlSpy: jest.SpyInstance;
|
||||||
let extractTarSpy: jest.SpyInstance;
|
let extractTarSpy: jest.SpyInstance;
|
||||||
|
let extractZipSpy: jest.SpyInstance;
|
||||||
let cacheSpy: jest.SpyInstance;
|
let cacheSpy: jest.SpyInstance;
|
||||||
let dbgSpy: jest.SpyInstance;
|
let dbgSpy: jest.SpyInstance;
|
||||||
let whichSpy: jest.SpyInstance;
|
let whichSpy: jest.SpyInstance;
|
||||||
|
@ -37,6 +41,7 @@ describe('setup-go', () => {
|
||||||
let mkdirpSpy: jest.SpyInstance;
|
let mkdirpSpy: jest.SpyInstance;
|
||||||
let execSpy: jest.SpyInstance;
|
let execSpy: jest.SpyInstance;
|
||||||
let getManifestSpy: jest.SpyInstance;
|
let getManifestSpy: jest.SpyInstance;
|
||||||
|
let getAllVersionsSpy: jest.SpyInstance;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
process.env['GITHUB_ENV'] = ''; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible)
|
process.env['GITHUB_ENV'] = ''; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible)
|
||||||
|
@ -61,13 +66,25 @@ describe('setup-go', () => {
|
||||||
archSpy.mockImplementation(() => os['arch']);
|
archSpy.mockImplementation(() => os['arch']);
|
||||||
execSpy = jest.spyOn(cp, 'execSync');
|
execSpy = jest.spyOn(cp, 'execSync');
|
||||||
|
|
||||||
|
// switch path join behaviour based on set os.platform
|
||||||
|
joinSpy = jest.spyOn(path, 'join');
|
||||||
|
joinSpy.mockImplementation((...paths: string[]): string => {
|
||||||
|
if (os['platform'] == 'win32') {
|
||||||
|
return win32Join(...paths);
|
||||||
|
}
|
||||||
|
|
||||||
|
return posixJoin(...paths);
|
||||||
|
});
|
||||||
|
|
||||||
// @actions/tool-cache
|
// @actions/tool-cache
|
||||||
findSpy = jest.spyOn(tc, 'find');
|
findSpy = jest.spyOn(tc, 'find');
|
||||||
dlSpy = jest.spyOn(tc, 'downloadTool');
|
dlSpy = jest.spyOn(tc, 'downloadTool');
|
||||||
extractTarSpy = jest.spyOn(tc, 'extractTar');
|
extractTarSpy = jest.spyOn(tc, 'extractTar');
|
||||||
|
extractZipSpy = jest.spyOn(tc, 'extractZip');
|
||||||
cacheSpy = jest.spyOn(tc, 'cacheDir');
|
cacheSpy = jest.spyOn(tc, 'cacheDir');
|
||||||
getSpy = jest.spyOn(im, 'getVersionsDist');
|
getSpy = jest.spyOn(im, 'getVersionsDist');
|
||||||
getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
|
getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
|
||||||
|
getAllVersionsSpy = jest.spyOn(im, 'getManifest');
|
||||||
|
|
||||||
// io
|
// io
|
||||||
whichSpy = jest.spyOn(io, 'which');
|
whichSpy = jest.spyOn(io, 'which');
|
||||||
|
@ -280,7 +297,6 @@ describe('setup-go', () => {
|
||||||
findSpy.mockImplementation(() => toolPath);
|
findSpy.mockImplementation(() => toolPath);
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
let expPath = path.join(toolPath, 'bin');
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -325,6 +341,31 @@ describe('setup-go', () => {
|
||||||
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('downloads a version not in the cache (windows)', async () => {
|
||||||
|
os.platform = 'win32';
|
||||||
|
os.arch = 'x64';
|
||||||
|
|
||||||
|
inputs['go-version'] = '1.13.1';
|
||||||
|
process.env['RUNNER_TEMP'] = 'C:\\temp\\';
|
||||||
|
|
||||||
|
findSpy.mockImplementation(() => '');
|
||||||
|
dlSpy.mockImplementation(() => 'C:\\temp\\some\\path');
|
||||||
|
extractZipSpy.mockImplementation(() => 'C:\\temp\\some\\other\\path');
|
||||||
|
|
||||||
|
let toolPath = path.normalize('C:\\cache\\go\\1.13.0\\x64');
|
||||||
|
cacheSpy.mockImplementation(() => toolPath);
|
||||||
|
|
||||||
|
await main.run();
|
||||||
|
|
||||||
|
let expPath = path.win32.join(toolPath, 'bin');
|
||||||
|
expect(dlSpy).toHaveBeenCalledWith(
|
||||||
|
'https://storage.googleapis.com/golang/go1.13.1.windows-amd64.zip',
|
||||||
|
'C:\\temp\\go1.13.1.windows-amd64.zip',
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
||||||
|
});
|
||||||
|
|
||||||
it('does not find a version that does not exist', async () => {
|
it('does not find a version that does not exist', async () => {
|
||||||
os.platform = 'linux';
|
os.platform = 'linux';
|
||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
@ -413,7 +454,7 @@ describe('setup-go', () => {
|
||||||
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('falls back to a version from node dist', async () => {
|
it('falls back to a version from go dist', async () => {
|
||||||
os.platform = 'linux';
|
os.platform = 'linux';
|
||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
|
@ -422,9 +463,6 @@ describe('setup-go', () => {
|
||||||
inputs['go-version'] = versionSpec;
|
inputs['go-version'] = versionSpec;
|
||||||
inputs['token'] = 'faketoken';
|
inputs['token'] = 'faketoken';
|
||||||
|
|
||||||
let expectedUrl =
|
|
||||||
'https://github.com/actions/go-versions/releases/download/1.12.14-20200616.18/go-1.12.14-linux-x64.tar.gz';
|
|
||||||
|
|
||||||
// ... but not in the local cache
|
// ... but not in the local cache
|
||||||
findSpy.mockImplementation(() => '');
|
findSpy.mockImplementation(() => '');
|
||||||
|
|
||||||
|
@ -486,7 +524,7 @@ describe('setup-go', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
mkdirpSpy.mockImplementation(async () => {});
|
mkdirpSpy.mockImplementation(async () => {});
|
||||||
existsSpy.mockImplementation(path => {
|
existsSpy.mockImplementation(() => {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -664,11 +702,9 @@ describe('setup-go', () => {
|
||||||
|
|
||||||
findSpy.mockImplementation(() => '');
|
findSpy.mockImplementation(() => '');
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
const toolPath = path.normalize('/cache/go/1.17.5/x64');
|
const toolPath = path.normalize('/cache/go/1.17.6/x64');
|
||||||
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
const expectedUrl =
|
|
||||||
'https://github.com/actions/go-versions/releases/download/1.17.6-1668090892/go-1.17.6-darwin-x64.tar.gz';
|
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
|
@ -745,6 +781,7 @@ describe('setup-go', () => {
|
||||||
getManifestSpy.mockImplementation(() => {
|
getManifestSpy.mockImplementation(() => {
|
||||||
throw new Error('Unable to download manifest');
|
throw new Error('Unable to download manifest');
|
||||||
});
|
});
|
||||||
|
getAllVersionsSpy.mockImplementationOnce(() => undefined);
|
||||||
|
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
let toolPath = path.normalize('/cache/go/1.13.7/x64');
|
let toolPath = path.normalize('/cache/go/1.13.7/x64');
|
||||||
|
@ -790,11 +827,17 @@ require (
|
||||||
|
|
||||||
replace example.com/thatmodule => ../thatmodule
|
replace example.com/thatmodule => ../thatmodule
|
||||||
exclude example.com/thismodule v1.3.0
|
exclude example.com/thismodule v1.3.0
|
||||||
|
`;
|
||||||
|
|
||||||
|
const goWorkContents = `go 1.19
|
||||||
|
|
||||||
|
use .
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
it('reads version from go.mod', async () => {
|
it('reads version from go.mod', async () => {
|
||||||
inputs['go-version-file'] = 'go.mod';
|
inputs['go-version-file'] = 'go.mod';
|
||||||
existsSpy.mockImplementation(path => true);
|
existsSpy.mockImplementation(() => true);
|
||||||
readFileSpy.mockImplementation(() => Buffer.from(goModContents));
|
readFileSpy.mockImplementation(() => Buffer.from(goModContents));
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
@ -804,9 +847,21 @@ exclude example.com/thismodule v1.3.0
|
||||||
expect(logSpy).toHaveBeenCalledWith('matching 1.14...');
|
expect(logSpy).toHaveBeenCalledWith('matching 1.14...');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('reads version from go.work', async () => {
|
||||||
|
inputs['go-version-file'] = 'go.work';
|
||||||
|
existsSpy.mockImplementation(() => true);
|
||||||
|
readFileSpy.mockImplementation(() => Buffer.from(goWorkContents));
|
||||||
|
|
||||||
|
await main.run();
|
||||||
|
|
||||||
|
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.19');
|
||||||
|
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.19...');
|
||||||
|
expect(logSpy).toHaveBeenCalledWith('matching 1.19...');
|
||||||
|
});
|
||||||
|
|
||||||
it('reads version from .go-version', async () => {
|
it('reads version from .go-version', async () => {
|
||||||
inputs['go-version-file'] = '.go-version';
|
inputs['go-version-file'] = '.go-version';
|
||||||
existsSpy.mockImplementation(path => true);
|
existsSpy.mockImplementation(() => true);
|
||||||
readFileSpy.mockImplementation(() => Buffer.from(`1.13.0${osm.EOL}`));
|
readFileSpy.mockImplementation(() => Buffer.from(`1.13.0${osm.EOL}`));
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
@ -819,7 +874,7 @@ exclude example.com/thismodule v1.3.0
|
||||||
it('is overwritten by go-version', async () => {
|
it('is overwritten by go-version', async () => {
|
||||||
inputs['go-version'] = '1.13.1';
|
inputs['go-version'] = '1.13.1';
|
||||||
inputs['go-version-file'] = 'go.mod';
|
inputs['go-version-file'] = 'go.mod';
|
||||||
existsSpy.mockImplementation(path => true);
|
existsSpy.mockImplementation(() => true);
|
||||||
readFileSpy.mockImplementation(() => Buffer.from(goModContents));
|
readFileSpy.mockImplementation(() => Buffer.from(goModContents));
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
@ -831,7 +886,7 @@ exclude example.com/thismodule v1.3.0
|
||||||
|
|
||||||
it('reports a read failure', async () => {
|
it('reports a read failure', async () => {
|
||||||
inputs['go-version-file'] = 'go.mod';
|
inputs['go-version-file'] = 'go.mod';
|
||||||
existsSpy.mockImplementation(path => false);
|
existsSpy.mockImplementation(() => false);
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
|
@ -839,5 +894,67 @@ exclude example.com/thismodule v1.3.0
|
||||||
`::error::The specified go version file at: go.mod does not exist${osm.EOL}`
|
`::error::The specified go version file at: go.mod does not exist${osm.EOL}`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('acquires specified architecture of go', async () => {
|
||||||
|
for (const {arch, version, osSpec} of [
|
||||||
|
{arch: 'amd64', version: '1.13.7', osSpec: 'linux'},
|
||||||
|
{arch: 'armv6l', version: '1.12.2', osSpec: 'linux'}
|
||||||
|
]) {
|
||||||
|
os.platform = osSpec;
|
||||||
|
os.arch = arch;
|
||||||
|
|
||||||
|
const fileExtension = os.platform === 'win32' ? 'zip' : 'tar.gz';
|
||||||
|
|
||||||
|
const platform = os.platform === 'win32' ? 'win' : os.platform;
|
||||||
|
|
||||||
|
inputs['go-version'] = version;
|
||||||
|
inputs['architecture'] = arch;
|
||||||
|
|
||||||
|
let expectedUrl =
|
||||||
|
platform === 'win32'
|
||||||
|
? `https://github.com/actions/go-versions/releases/download/${version}/go-${version}-${platform}-${arch}.${fileExtension}`
|
||||||
|
: `https://storage.googleapis.com/golang/go${version}.${osSpec}-${arch}.${fileExtension}`;
|
||||||
|
|
||||||
|
// ... but not in the local cache
|
||||||
|
findSpy.mockImplementation(() => '');
|
||||||
|
|
||||||
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
|
let toolPath = path.normalize(`/cache/go/${version}/${arch}`);
|
||||||
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
|
|
||||||
|
await main.run();
|
||||||
|
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
`Acquiring go${version} from ${expectedUrl}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, 100000);
|
||||||
|
|
||||||
|
it.each(['stable', 'oldstable'])(
|
||||||
|
'acquires latest go version with %s go-version input',
|
||||||
|
async (alias: string) => {
|
||||||
|
const arch = 'x64';
|
||||||
|
os.platform = 'darwin';
|
||||||
|
os.arch = arch;
|
||||||
|
|
||||||
|
inputs['go-version'] = alias;
|
||||||
|
inputs['architecture'] = os.arch;
|
||||||
|
|
||||||
|
// ... but not in the local cache
|
||||||
|
findSpy.mockImplementation(() => '');
|
||||||
|
|
||||||
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
|
let toolPath = path.normalize(`/cache/go/${alias}/${arch}`);
|
||||||
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
|
|
||||||
|
await main.run();
|
||||||
|
|
||||||
|
const releaseIndex = alias === 'stable' ? 0 : 1;
|
||||||
|
|
||||||
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
|
`${alias} version resolved as ${goTestManifest[releaseIndex].version}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,18 +5,20 @@ inputs:
|
||||||
go-version:
|
go-version:
|
||||||
description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges.'
|
description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges.'
|
||||||
go-version-file:
|
go-version-file:
|
||||||
description: 'Path to the go.mod file.'
|
description: 'Path to the go.mod or go.work file.'
|
||||||
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'
|
||||||
default: false
|
default: false
|
||||||
token:
|
token:
|
||||||
description: Used to pull node distributions from go-versions. Since there's a default, this is typically not supplied by the user.
|
description: Used to pull node distributions from go-versions. Since there's a default, this is typically not supplied by the user. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.
|
||||||
default: ${{ github.token }}
|
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
|
||||||
cache:
|
cache:
|
||||||
description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
|
description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
|
||||||
default: false
|
default: false
|
||||||
cache-dependency-path:
|
cache-dependency-path:
|
||||||
description: 'Used to specify the path to a dependency file - go.sum'
|
description: 'Used to specify the path to a dependency file - go.sum'
|
||||||
|
architecture:
|
||||||
|
description: 'Target architecture for Go to use. Examples: x86, x64. Will use system architecture by default.'
|
||||||
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.'
|
||||||
|
|
1743
dist/cache-save/index.js
vendored
1743
dist/cache-save/index.js
vendored
File diff suppressed because it is too large
Load diff
1885
dist/setup/index.js
vendored
1885
dist/setup/index.js
vendored
File diff suppressed because it is too large
Load diff
|
@ -112,4 +112,4 @@ Another great way to contribute is pull request reviews. Please, be extra kind:
|
||||||
- Make sure you're familiar with the code or documentation is updated, unless it's a minor change (spellchecking, minor formatting, etc.)
|
- Make sure you're familiar with the code or documentation is updated, unless it's a minor change (spellchecking, minor formatting, etc.)
|
||||||
- Review changes using the GitHub functionality. You can ask a clarifying question, point out an error or suggest an alternative.
|
- Review changes using the GitHub functionality. You can ask a clarifying question, point out an error or suggest an alternative.
|
||||||
> Note: You may ask for minor changes - "nitpicks", but consider whether they are real blockers to merging or not
|
> Note: You may ask for minor changes - "nitpicks", but consider whether they are real blockers to merging or not
|
||||||
- Submit your review, which
|
- Submit your review, which may include comments, an approval, or a changes request
|
61
package-lock.json
generated
61
package-lock.json
generated
|
@ -1,16 +1,16 @@
|
||||||
{
|
{
|
||||||
"name": "setup-go",
|
"name": "setup-go",
|
||||||
"version": "1.0.0",
|
"version": "3.3.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "setup-go",
|
"name": "setup-go",
|
||||||
"version": "1.0.0",
|
"version": "3.3.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^3.0.0",
|
"@actions/cache": "^3.0.0",
|
||||||
"@actions/core": "^1.6.0",
|
"@actions/core": "^1.10.0",
|
||||||
"@actions/exec": "^1.1.0",
|
"@actions/exec": "^1.1.0",
|
||||||
"@actions/glob": "^0.2.0",
|
"@actions/glob": "^0.2.0",
|
||||||
"@actions/http-client": "^2.0.1",
|
"@actions/http-client": "^2.0.1",
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
"nock": "^10.0.6",
|
"nock": "^10.0.6",
|
||||||
"prettier": "^1.17.1",
|
"prettier": "^1.17.1",
|
||||||
"ts-jest": "^27.0.5",
|
"ts-jest": "^27.0.5",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^4.3.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/cache": {
|
"node_modules/@actions/cache": {
|
||||||
|
@ -57,19 +57,20 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/core": {
|
"node_modules/@actions/core": {
|
||||||
"version": "1.6.0",
|
"version": "1.10.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
|
||||||
"integrity": "sha512-NB1UAZomZlCV/LmJqkLhNTqtKfFXJZAUPcfl/zqG7EfsQdeUJtaWO98SGbuQ3pydJ3fHl2CvI/51OKYlCYYcaw==",
|
"integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/http-client": "^1.0.11"
|
"@actions/http-client": "^2.0.1",
|
||||||
|
"uuid": "^8.3.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/core/node_modules/@actions/http-client": {
|
"node_modules/@actions/core/node_modules/uuid": {
|
||||||
"version": "1.0.11",
|
"version": "8.3.2",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.11.tgz",
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||||
"integrity": "sha512-VRYHGQV1rqnROJqdMvGUbY/Kn8vriQe/F9HR2AlYHzmKuM/p3kjNuXhmdBfcVgsvRWTz5C5XW5xvndZrVBuAYg==",
|
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
|
||||||
"dependencies": {
|
"bin": {
|
||||||
"tunnel": "0.0.6"
|
"uuid": "dist/bin/uuid"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/exec": {
|
"node_modules/@actions/exec": {
|
||||||
|
@ -4693,9 +4694,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/typescript": {
|
"node_modules/typescript": {
|
||||||
"version": "3.9.10",
|
"version": "4.3.3",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.3.tgz",
|
||||||
"integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==",
|
"integrity": "sha512-rUvLW0WtF7PF2b9yenwWUi9Da9euvDRhmH7BLyBG4DCFfOJ850LGNknmRpp8Z8kXNUPObdZQEfKOiHtXuQHHKA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsc": "bin/tsc",
|
"tsc": "bin/tsc",
|
||||||
|
@ -4991,20 +4992,18 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@actions/core": {
|
"@actions/core": {
|
||||||
"version": "1.6.0",
|
"version": "1.10.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
|
||||||
"integrity": "sha512-NB1UAZomZlCV/LmJqkLhNTqtKfFXJZAUPcfl/zqG7EfsQdeUJtaWO98SGbuQ3pydJ3fHl2CvI/51OKYlCYYcaw==",
|
"integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@actions/http-client": "^1.0.11"
|
"@actions/http-client": "^2.0.1",
|
||||||
|
"uuid": "^8.3.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/http-client": {
|
"uuid": {
|
||||||
"version": "1.0.11",
|
"version": "8.3.2",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.11.tgz",
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||||
"integrity": "sha512-VRYHGQV1rqnROJqdMvGUbY/Kn8vriQe/F9HR2AlYHzmKuM/p3kjNuXhmdBfcVgsvRWTz5C5XW5xvndZrVBuAYg==",
|
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
|
||||||
"requires": {
|
|
||||||
"tunnel": "0.0.6"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -8566,9 +8565,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"typescript": {
|
"typescript": {
|
||||||
"version": "3.9.10",
|
"version": "4.3.3",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.3.tgz",
|
||||||
"integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==",
|
"integrity": "sha512-rUvLW0WtF7PF2b9yenwWUi9Da9euvDRhmH7BLyBG4DCFfOJ850LGNknmRpp8Z8kXNUPObdZQEfKOiHtXuQHHKA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"universalify": {
|
"universalify": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "setup-go",
|
"name": "setup-go",
|
||||||
"version": "1.0.0",
|
"version": "3.3.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "setup go action",
|
"description": "setup go action",
|
||||||
"main": "lib/setup-go.js",
|
"main": "lib/setup-go.js",
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^3.0.0",
|
"@actions/cache": "^3.0.0",
|
||||||
"@actions/core": "^1.6.0",
|
"@actions/core": "^1.10.0",
|
||||||
"@actions/exec": "^1.1.0",
|
"@actions/exec": "^1.1.0",
|
||||||
"@actions/glob": "^0.2.0",
|
"@actions/glob": "^0.2.0",
|
||||||
"@actions/http-client": "^2.0.1",
|
"@actions/http-client": "^2.0.1",
|
||||||
|
@ -42,6 +42,6 @@
|
||||||
"nock": "^10.0.6",
|
"nock": "^10.0.6",
|
||||||
"prettier": "^1.17.1",
|
"prettier": "^1.17.1",
|
||||||
"ts-jest": "^27.0.5",
|
"ts-jest": "^27.0.5",
|
||||||
"typescript": "^3.8.3"
|
"typescript": "^4.3.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,12 @@ import {PackageManagerInfo} from './package-managers';
|
||||||
import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils';
|
import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils';
|
||||||
|
|
||||||
export const restoreCache = async (
|
export const restoreCache = async (
|
||||||
|
versionSpec: string,
|
||||||
packageManager: string,
|
packageManager: string,
|
||||||
cacheDependencyPath?: string
|
cacheDependencyPath?: string
|
||||||
) => {
|
) => {
|
||||||
const packageManagerInfo = await getPackageManagerInfo(packageManager);
|
const packageManagerInfo = await getPackageManagerInfo(packageManager);
|
||||||
const platform = process.env.RUNNER_OS;
|
const platform = process.env.RUNNER_OS;
|
||||||
const versionSpec = core.getInput('go-version');
|
|
||||||
|
|
||||||
const cachePaths = await getCacheDirectoryPath(packageManagerInfo);
|
const cachePaths = await getCacheDirectoryPath(packageManagerInfo);
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,14 @@ export async function run() {
|
||||||
try {
|
try {
|
||||||
await cachePackages();
|
await cachePackages();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
let message = 'Unknown error!';
|
||||||
|
if (error instanceof Error) {
|
||||||
|
message = error.message;
|
||||||
|
}
|
||||||
|
if (typeof error === 'string') {
|
||||||
|
message = error;
|
||||||
|
}
|
||||||
|
core.setFailed(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +47,8 @@ const cachePackages = async () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (nonExistingPaths.length === cachePaths.length) {
|
if (nonExistingPaths.length === cachePaths.length) {
|
||||||
throw new Error(`There are no cache folders on the disk`);
|
core.warning('There are no cache folders on the disk');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nonExistingPaths.length) {
|
if (nonExistingPaths.length) {
|
||||||
|
@ -65,7 +73,7 @@ const cachePackages = async () => {
|
||||||
core.info(`Cache saved with the key: ${primaryKey}`);
|
core.info(`Cache saved with the key: ${primaryKey}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function logWarning(message: string): void {
|
function logWarning(message: string): void {
|
||||||
const warningPrefix = '[warning]';
|
const warningPrefix = '[warning]';
|
||||||
core.info(`${warningPrefix}${message}`);
|
core.info(`${warningPrefix}${message}`);
|
||||||
}
|
}
|
||||||
|
|
173
src/installer.ts
173
src/installer.ts
|
@ -6,6 +6,7 @@ import * as httpm from '@actions/http-client';
|
||||||
import * as sys from './system';
|
import * as sys from './system';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
import {StableReleaseAlias} from './utils';
|
||||||
|
|
||||||
type InstallationType = 'dist' | 'manifest';
|
type InstallationType = 'dist' | 'manifest';
|
||||||
|
|
||||||
|
@ -32,17 +33,46 @@ export interface IGoVersionInfo {
|
||||||
export async function getGo(
|
export async function getGo(
|
||||||
versionSpec: string,
|
versionSpec: string,
|
||||||
checkLatest: boolean,
|
checkLatest: boolean,
|
||||||
auth: string | undefined
|
auth: string | undefined,
|
||||||
|
arch = os.arch()
|
||||||
) {
|
) {
|
||||||
|
let manifest: tc.IToolRelease[] | undefined;
|
||||||
let osPlat: string = os.platform();
|
let osPlat: string = os.platform();
|
||||||
let osArch: string = os.arch();
|
|
||||||
|
if (
|
||||||
|
versionSpec === StableReleaseAlias.Stable ||
|
||||||
|
versionSpec === StableReleaseAlias.OldStable
|
||||||
|
) {
|
||||||
|
manifest = await getManifest(auth);
|
||||||
|
let stableVersion = await resolveStableVersionInput(
|
||||||
|
versionSpec,
|
||||||
|
arch,
|
||||||
|
osPlat,
|
||||||
|
manifest
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!stableVersion) {
|
||||||
|
stableVersion = await resolveStableVersionDist(versionSpec, arch);
|
||||||
|
if (!stableVersion) {
|
||||||
|
throw new Error(
|
||||||
|
`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
core.info(`${versionSpec} version resolved as ${stableVersion}`);
|
||||||
|
|
||||||
|
versionSpec = stableVersion;
|
||||||
|
}
|
||||||
|
|
||||||
if (checkLatest) {
|
if (checkLatest) {
|
||||||
core.info('Attempting to resolve the latest version from the manifest...');
|
core.info('Attempting to resolve the latest version from the manifest...');
|
||||||
const resolvedVersion = await resolveVersionFromManifest(
|
const resolvedVersion = await resolveVersionFromManifest(
|
||||||
versionSpec,
|
versionSpec,
|
||||||
true,
|
true,
|
||||||
auth
|
auth,
|
||||||
|
arch,
|
||||||
|
manifest
|
||||||
);
|
);
|
||||||
if (resolvedVersion) {
|
if (resolvedVersion) {
|
||||||
versionSpec = resolvedVersion;
|
versionSpec = resolvedVersion;
|
||||||
|
@ -54,7 +84,7 @@ export async function getGo(
|
||||||
|
|
||||||
// check cache
|
// check cache
|
||||||
let toolPath: string;
|
let toolPath: string;
|
||||||
toolPath = tc.find('go', versionSpec);
|
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}`);
|
||||||
|
@ -68,9 +98,9 @@ export async function getGo(
|
||||||
// Try download from internal distribution (popular versions only)
|
// Try download from internal distribution (popular versions only)
|
||||||
//
|
//
|
||||||
try {
|
try {
|
||||||
info = await getInfoFromManifest(versionSpec, true, auth);
|
info = await getInfoFromManifest(versionSpec, true, auth, arch, manifest);
|
||||||
if (info) {
|
if (info) {
|
||||||
downloadPath = await installGoVersion(info, auth);
|
downloadPath = await installGoVersion(info, auth, arch);
|
||||||
} else {
|
} else {
|
||||||
core.info(
|
core.info(
|
||||||
'Not found in manifest. Falling back to download directly from Go'
|
'Not found in manifest. Falling back to download directly from Go'
|
||||||
|
@ -95,16 +125,16 @@ export async function getGo(
|
||||||
// Download from storage.googleapis.com
|
// Download from storage.googleapis.com
|
||||||
//
|
//
|
||||||
if (!downloadPath) {
|
if (!downloadPath) {
|
||||||
info = await getInfoFromDist(versionSpec);
|
info = await getInfoFromDist(versionSpec, arch);
|
||||||
if (!info) {
|
if (!info) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
|
`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
core.info('Install from dist');
|
core.info('Install from dist');
|
||||||
downloadPath = await installGoVersion(info, undefined);
|
downloadPath = await installGoVersion(info, undefined, arch);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(`Failed to download version ${versionSpec}: ${err}`);
|
throw new Error(`Failed to download version ${versionSpec}: ${err}`);
|
||||||
}
|
}
|
||||||
|
@ -116,10 +146,18 @@ export async function getGo(
|
||||||
async function resolveVersionFromManifest(
|
async function resolveVersionFromManifest(
|
||||||
versionSpec: string,
|
versionSpec: string,
|
||||||
stable: boolean,
|
stable: boolean,
|
||||||
auth: string | undefined
|
auth: string | undefined,
|
||||||
|
arch: string,
|
||||||
|
manifest: tc.IToolRelease[] | undefined
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
try {
|
try {
|
||||||
const info = await getInfoFromManifest(versionSpec, stable, auth);
|
const info = await getInfoFromManifest(
|
||||||
|
versionSpec,
|
||||||
|
stable,
|
||||||
|
auth,
|
||||||
|
arch,
|
||||||
|
manifest
|
||||||
|
);
|
||||||
return info?.resolvedVersion;
|
return info?.resolvedVersion;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
core.info('Unable to resolve a version from the manifest...');
|
core.info('Unable to resolve a version from the manifest...');
|
||||||
|
@ -129,10 +167,17 @@ async function resolveVersionFromManifest(
|
||||||
|
|
||||||
async function installGoVersion(
|
async function installGoVersion(
|
||||||
info: IGoVersionInfo,
|
info: IGoVersionInfo,
|
||||||
auth: string | undefined
|
auth: string | undefined,
|
||||||
|
arch: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
|
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
|
||||||
const downloadPath = await tc.downloadTool(info.downloadUrl, undefined, auth);
|
|
||||||
|
// Windows requires that we keep the extension (.zip) for extraction
|
||||||
|
const isWindows = os.platform() === 'win32';
|
||||||
|
const tempDir = process.env.RUNNER_TEMP || '.';
|
||||||
|
const fileName = isWindows ? path.join(tempDir, info.fileName) : undefined;
|
||||||
|
|
||||||
|
const downloadPath = await tc.downloadTool(info.downloadUrl, fileName, auth);
|
||||||
|
|
||||||
core.info('Extracting Go...');
|
core.info('Extracting Go...');
|
||||||
let extPath = await extractGoArchive(downloadPath);
|
let extPath = await extractGoArchive(downloadPath);
|
||||||
|
@ -145,7 +190,8 @@ async function installGoVersion(
|
||||||
const cachedDir = await tc.cacheDir(
|
const cachedDir = await tc.cacheDir(
|
||||||
extPath,
|
extPath,
|
||||||
'go',
|
'go',
|
||||||
makeSemver(info.resolvedVersion)
|
makeSemver(info.resolvedVersion),
|
||||||
|
arch
|
||||||
);
|
);
|
||||||
core.info(`Successfully cached go to ${cachedDir}`);
|
core.info(`Successfully cached go to ${cachedDir}`);
|
||||||
return cachedDir;
|
return cachedDir;
|
||||||
|
@ -164,20 +210,26 @@ export async function extractGoArchive(archivePath: string): Promise<string> {
|
||||||
return extPath;
|
return extPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getManifest(auth: string | undefined) {
|
||||||
|
return tc.getManifestFromRepo('actions', 'go-versions', auth, 'main');
|
||||||
|
}
|
||||||
|
|
||||||
export async function getInfoFromManifest(
|
export async function getInfoFromManifest(
|
||||||
versionSpec: string,
|
versionSpec: string,
|
||||||
stable: boolean,
|
stable: boolean,
|
||||||
auth: string | undefined
|
auth: string | undefined,
|
||||||
|
arch = os.arch(),
|
||||||
|
manifest?: tc.IToolRelease[] | undefined
|
||||||
): Promise<IGoVersionInfo | null> {
|
): Promise<IGoVersionInfo | null> {
|
||||||
let info: IGoVersionInfo | null = null;
|
let info: IGoVersionInfo | null = null;
|
||||||
const releases = await tc.getManifestFromRepo(
|
if (!manifest) {
|
||||||
'actions',
|
core.debug('No manifest cached');
|
||||||
'go-versions',
|
manifest = await getManifest(auth);
|
||||||
auth,
|
}
|
||||||
'main'
|
|
||||||
);
|
|
||||||
core.info(`matching ${versionSpec}...`);
|
core.info(`matching ${versionSpec}...`);
|
||||||
const rel = await tc.findFromManifest(versionSpec, stable, releases);
|
|
||||||
|
const rel = await tc.findFromManifest(versionSpec, stable, manifest, arch);
|
||||||
|
|
||||||
if (rel && rel.files.length > 0) {
|
if (rel && rel.files.length > 0) {
|
||||||
info = <IGoVersionInfo>{};
|
info = <IGoVersionInfo>{};
|
||||||
|
@ -191,10 +243,11 @@ export async function getInfoFromManifest(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getInfoFromDist(
|
async function getInfoFromDist(
|
||||||
versionSpec: string
|
versionSpec: string,
|
||||||
|
arch: string
|
||||||
): Promise<IGoVersionInfo | null> {
|
): Promise<IGoVersionInfo | null> {
|
||||||
let version: IGoVersion | undefined;
|
let version: IGoVersion | undefined;
|
||||||
version = await findMatch(versionSpec);
|
version = await findMatch(versionSpec, arch);
|
||||||
if (!version) {
|
if (!version) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -210,9 +263,10 @@ async function getInfoFromDist(
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function findMatch(
|
export async function findMatch(
|
||||||
versionSpec: string
|
versionSpec: string,
|
||||||
|
arch = os.arch()
|
||||||
): Promise<IGoVersion | undefined> {
|
): Promise<IGoVersion | undefined> {
|
||||||
let archFilter = sys.getArch();
|
let archFilter = sys.getArch(arch);
|
||||||
let platFilter = sys.getPlatform();
|
let platFilter = sys.getPlatform();
|
||||||
|
|
||||||
let result: IGoVersion | undefined;
|
let result: IGoVersion | undefined;
|
||||||
|
@ -303,10 +357,75 @@ export function makeSemver(version: string): string {
|
||||||
export function parseGoVersionFile(versionFilePath: string): string {
|
export function parseGoVersionFile(versionFilePath: string): string {
|
||||||
const contents = fs.readFileSync(versionFilePath).toString();
|
const contents = fs.readFileSync(versionFilePath).toString();
|
||||||
|
|
||||||
if (path.basename(versionFilePath) === 'go.mod') {
|
if (
|
||||||
|
path.basename(versionFilePath) === 'go.mod' ||
|
||||||
|
path.basename(versionFilePath) === 'go.work'
|
||||||
|
) {
|
||||||
const match = contents.match(/^go (\d+(\.\d+)*)/m);
|
const match = contents.match(/^go (\d+(\.\d+)*)/m);
|
||||||
return match ? match[1] : '';
|
return match ? match[1] : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return contents.trim();
|
return contents.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function resolveStableVersionDist(versionSpec: string, arch: string) {
|
||||||
|
let archFilter = sys.getArch(arch);
|
||||||
|
let platFilter = sys.getPlatform();
|
||||||
|
const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all';
|
||||||
|
let candidates: IGoVersion[] | null = await module.exports.getVersionsDist(
|
||||||
|
dlUrl
|
||||||
|
);
|
||||||
|
if (!candidates) {
|
||||||
|
throw new Error(`golang download url did not return results`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const fixedCandidates = candidates.map(item => {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
version: makeSemver(item.version)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const stableVersion = await resolveStableVersionInput(
|
||||||
|
versionSpec,
|
||||||
|
archFilter,
|
||||||
|
platFilter,
|
||||||
|
fixedCandidates
|
||||||
|
);
|
||||||
|
|
||||||
|
return stableVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function resolveStableVersionInput(
|
||||||
|
versionSpec: string,
|
||||||
|
arch: string,
|
||||||
|
platform: string,
|
||||||
|
manifest: tc.IToolRelease[] | IGoVersion[]
|
||||||
|
) {
|
||||||
|
const releases = manifest
|
||||||
|
.map(item => {
|
||||||
|
const index = item.files.findIndex(
|
||||||
|
item => item.arch === arch && item.filename.includes(platform)
|
||||||
|
);
|
||||||
|
if (index === -1) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return item.version;
|
||||||
|
})
|
||||||
|
.filter(item => !!item && !semver.prerelease(item));
|
||||||
|
|
||||||
|
if (versionSpec === StableReleaseAlias.Stable) {
|
||||||
|
return releases[0];
|
||||||
|
} else {
|
||||||
|
const versions = releases.map(
|
||||||
|
release => `${semver.major(release)}.${semver.minor(release)}`
|
||||||
|
);
|
||||||
|
const uniqueVersions = Array.from(new Set(versions));
|
||||||
|
|
||||||
|
const oldstableVersion = releases.find(item =>
|
||||||
|
item.startsWith(uniqueVersions[1])
|
||||||
|
);
|
||||||
|
|
||||||
|
return oldstableVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
25
src/main.ts
25
src/main.ts
|
@ -4,9 +4,10 @@ import * as installer from './installer';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {restoreCache} from './cache-restore';
|
import {restoreCache} from './cache-restore';
|
||||||
import {isGhes, isCacheFeatureAvailable} from './cache-utils';
|
import {isCacheFeatureAvailable} from './cache-utils';
|
||||||
import cp from 'child_process';
|
import cp from 'child_process';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import os from 'os';
|
||||||
|
|
||||||
export async function run() {
|
export async function run() {
|
||||||
try {
|
try {
|
||||||
|
@ -19,17 +20,31 @@ export async function run() {
|
||||||
const cache = core.getBooleanInput('cache');
|
const cache = core.getBooleanInput('cache');
|
||||||
core.info(`Setup go version spec ${versionSpec}`);
|
core.info(`Setup go version spec ${versionSpec}`);
|
||||||
|
|
||||||
|
let arch = core.getInput('architecture');
|
||||||
|
|
||||||
|
if (!arch) {
|
||||||
|
arch = os.arch();
|
||||||
|
}
|
||||||
|
|
||||||
if (versionSpec) {
|
if (versionSpec) {
|
||||||
let token = core.getInput('token');
|
let token = core.getInput('token');
|
||||||
let auth = !token || isGhes() ? undefined : `token ${token}`;
|
let auth = !token ? undefined : `token ${token}`;
|
||||||
|
|
||||||
const checkLatest = core.getBooleanInput('check-latest');
|
const checkLatest = core.getBooleanInput('check-latest');
|
||||||
const installDir = await installer.getGo(versionSpec, checkLatest, auth);
|
|
||||||
|
const installDir = await installer.getGo(
|
||||||
|
versionSpec,
|
||||||
|
checkLatest,
|
||||||
|
auth,
|
||||||
|
arch
|
||||||
|
);
|
||||||
|
|
||||||
|
const installDirVersion = path.basename(path.dirname(installDir));
|
||||||
|
|
||||||
core.addPath(path.join(installDir, 'bin'));
|
core.addPath(path.join(installDir, 'bin'));
|
||||||
core.info('Added go to the path');
|
core.info('Added go to the path');
|
||||||
|
|
||||||
const version = installer.makeSemver(versionSpec);
|
const version = installer.makeSemver(installDirVersion);
|
||||||
// Go versions less than 1.9 require GOROOT to be set
|
// Go versions less than 1.9 require GOROOT to be set
|
||||||
if (semver.lt(version, '1.9.0')) {
|
if (semver.lt(version, '1.9.0')) {
|
||||||
core.info('Setting GOROOT for Go version < 1.9');
|
core.info('Setting GOROOT for Go version < 1.9');
|
||||||
|
@ -44,7 +59,7 @@ export async function run() {
|
||||||
if (cache && isCacheFeatureAvailable()) {
|
if (cache && isCacheFeatureAvailable()) {
|
||||||
const packageManager = 'default';
|
const packageManager = 'default';
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||||
await restoreCache(packageManager, cacheDependencyPath);
|
await restoreCache(versionSpec, packageManager, cacheDependencyPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add problem matchers
|
// add problem matchers
|
||||||
|
|
|
@ -15,9 +15,8 @@ export function getPlatform(): string {
|
||||||
return plat;
|
return plat;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getArch(): string {
|
export function getArch(arch: string): string {
|
||||||
// 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', and 'x64'.
|
// 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', and 'x64'.
|
||||||
let arch: string = os.arch();
|
|
||||||
|
|
||||||
// wants amd64, 386, arm64, armv61, ppc641e, s390x
|
// wants amd64, 386, arm64, armv61, ppc641e, s390x
|
||||||
// currently not supported by runner but future proofed mapping
|
// currently not supported by runner but future proofed mapping
|
||||||
|
@ -31,6 +30,9 @@ export function getArch(): string {
|
||||||
case 'x32':
|
case 'x32':
|
||||||
arch = '386';
|
arch = '386';
|
||||||
break;
|
break;
|
||||||
|
case 'arm':
|
||||||
|
arch = 'armv6l';
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return arch;
|
return arch;
|
||||||
|
|
4
src/utils.ts
Normal file
4
src/utils.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
export enum StableReleaseAlias {
|
||||||
|
Stable = 'stable',
|
||||||
|
OldStable = 'oldstable'
|
||||||
|
}
|
Loading…
Reference in a new issue