mirror of
https://gitea.com/actions/setup-go.git
synced 2024-11-24 21:15:38 +01:00
pre-release version and test
This commit is contained in:
parent
43880314e9
commit
768458bd0b
12
README.md
12
README.md
@ -18,6 +18,7 @@ The V2 beta offers:
|
||||
- stable input
|
||||
- Bug Fixes (including issues around version matching and semver)
|
||||
|
||||
Matching by semver spec:
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
@ -27,6 +28,17 @@ steps:
|
||||
- run: go version
|
||||
```
|
||||
|
||||
Matching an unstable pre-release:
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v2-beta
|
||||
with:
|
||||
stable: 'false'
|
||||
go-version: '1.14.0-rc1' # The Go version to download (if necessary) and use.
|
||||
- run: go version
|
||||
```
|
||||
|
||||
# Usage
|
||||
|
||||
See [action.yml](action.yml)
|
||||
|
@ -67,6 +67,29 @@ describe('setup-go', () => {
|
||||
|
||||
afterAll(async () => {}, 100000);
|
||||
|
||||
it('can query versions', async () => {
|
||||
let versions: im.IGoVersion[] | null = await im.getVersions(
|
||||
'https://non.existant.com/path'
|
||||
);
|
||||
expect(versions).toBeDefined();
|
||||
let l: number = versions ? versions.length : 0;
|
||||
expect(l).toBe(91);
|
||||
});
|
||||
|
||||
it('finds stable match for exact version', async () => {
|
||||
os.platform = 'win32';
|
||||
os.arch = 'x64';
|
||||
|
||||
// get request is already mocked
|
||||
// spec: 1.13.7 => 1.13.7 (exact)
|
||||
let match: im.IGoVersion | undefined = await im.findMatch('1.13.7', true);
|
||||
expect(match).toBeDefined();
|
||||
let version: string = match ? match.version : '';
|
||||
expect(version).toBe('go1.13.7');
|
||||
let fileName = match ? match.files[0].filename : '';
|
||||
expect(fileName).toBe('go1.13.7.windows-amd64.zip');
|
||||
});
|
||||
|
||||
it('finds stable match for exact dot zero version', async () => {
|
||||
os.platform = 'darwin';
|
||||
os.arch = 'x64';
|
||||
@ -119,6 +142,22 @@ describe('setup-go', () => {
|
||||
expect(fileName).toBe('go1.13.7.windows-386.zip');
|
||||
});
|
||||
|
||||
it('finds unstable pre-release version', async () => {
|
||||
os.platform = 'linux';
|
||||
os.arch = 'x64';
|
||||
|
||||
// spec: 1.14, stable=false => go1.14rc1
|
||||
let match: im.IGoVersion | undefined = await im.findMatch(
|
||||
'1.14.0-rc1',
|
||||
false
|
||||
);
|
||||
expect(match).toBeDefined();
|
||||
let version: string = match ? match.version : '';
|
||||
expect(version).toBe('go1.14rc1');
|
||||
let fileName = match ? match.files[0].filename : '';
|
||||
expect(fileName).toBe('go1.14rc1.linux-amd64.tar.gz');
|
||||
});
|
||||
|
||||
it('evaluates to stable with input as true', async () => {
|
||||
inputs['go-version'] = '1.13.0';
|
||||
inputs.stable = 'true';
|
||||
@ -241,26 +280,20 @@ describe('setup-go', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('can query versions', async () => {
|
||||
let versions: im.IGoVersion[] | null = await im.getVersions(
|
||||
'https://non.existant.com/path'
|
||||
);
|
||||
expect(versions).toBeDefined();
|
||||
let l: number = versions ? versions.length : 0;
|
||||
expect(l).toBe(91);
|
||||
// 1.13.1 => 1.13.1
|
||||
// 1.13 => 1.13.0
|
||||
// 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
|
||||
// 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1
|
||||
it('converts prerelease versions', async () => {
|
||||
expect(im.makeSemver('1.10beta1')).toBe('1.10.0-beta1');
|
||||
expect(im.makeSemver('1.10rc1')).toBe('1.10.0-rc1');
|
||||
});
|
||||
|
||||
it('finds stable match for exact version', async () => {
|
||||
os.platform = 'win32';
|
||||
os.arch = 'x64';
|
||||
it('converts dot zero versions', async () => {
|
||||
expect(im.makeSemver('1.13')).toBe('1.13.0');
|
||||
});
|
||||
|
||||
// get request is already mocked
|
||||
// spec: 1.13.7 => 1.13.7 (exact)
|
||||
let match: im.IGoVersion | undefined = await im.findMatch('1.13.7', true);
|
||||
expect(match).toBeDefined();
|
||||
let version: string = match ? match.version : '';
|
||||
expect(version).toBe('go1.13.7');
|
||||
let fileName = match ? match.files[0].filename : '';
|
||||
expect(fileName).toBe('go1.13.7.windows-amd64.zip');
|
||||
it('does not convert exact versions', async () => {
|
||||
expect(im.makeSemver('1.13.1')).toBe('1.13.1');
|
||||
});
|
||||
});
|
||||
|
21
dist/index.js
vendored
21
dist/index.js
vendored
@ -4625,7 +4625,7 @@ function findMatch(versionSpec, stable) {
|
||||
let goFile;
|
||||
for (let i = 0; i < candidates.length; i++) {
|
||||
let candidate = candidates[i];
|
||||
let version = candidate.version.replace('go', '');
|
||||
let version = makeSemver(candidate.version);
|
||||
// 1.13.0 is advertised as 1.13 preventing being able to match exactly 1.13.0
|
||||
// since a semver of 1.13 would match latest 1.13
|
||||
let parts = version.split('.');
|
||||
@ -4663,6 +4663,25 @@ function getVersions(dlUrl) {
|
||||
});
|
||||
}
|
||||
exports.getVersions = getVersions;
|
||||
//
|
||||
// Convert the go version syntax into semver for semver matching
|
||||
// 1.13.1 => 1.13.1
|
||||
// 1.13 => 1.13.0
|
||||
// 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
|
||||
// 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1
|
||||
function makeSemver(version) {
|
||||
version = version.replace('go', '');
|
||||
version = version.replace('beta', '-beta').replace('rc', '-rc');
|
||||
let parts = version.split('-');
|
||||
let verPart = parts[0];
|
||||
let prereleasePart = parts.length > 1 ? `-${parts[1]}` : '';
|
||||
let verParts = verPart.split('.');
|
||||
if (verParts.length == 2) {
|
||||
verPart += '.0';
|
||||
}
|
||||
return `${verPart}${prereleasePart}`;
|
||||
}
|
||||
exports.makeSemver = makeSemver;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
@ -74,7 +74,7 @@ export async function findMatch(
|
||||
let goFile: IGoVersionFile | undefined;
|
||||
for (let i = 0; i < candidates.length; i++) {
|
||||
let candidate: IGoVersion = candidates[i];
|
||||
let version = candidate.version.replace('go', '');
|
||||
let version = makeSemver(candidate.version);
|
||||
|
||||
// 1.13.0 is advertised as 1.13 preventing being able to match exactly 1.13.0
|
||||
// since a semver of 1.13 would match latest 1.13
|
||||
@ -115,3 +115,25 @@ export async function getVersions(dlUrl: string): Promise<IGoVersion[] | null> {
|
||||
let http: httpm.HttpClient = new httpm.HttpClient('setup-go');
|
||||
return (await http.getJson<IGoVersion[]>(dlUrl)).result;
|
||||
}
|
||||
|
||||
//
|
||||
// Convert the go version syntax into semver for semver matching
|
||||
// 1.13.1 => 1.13.1
|
||||
// 1.13 => 1.13.0
|
||||
// 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
|
||||
// 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1
|
||||
export function makeSemver(version: string): string {
|
||||
version = version.replace('go', '');
|
||||
version = version.replace('beta', '-beta').replace('rc', '-rc');
|
||||
let parts = version.split('-');
|
||||
|
||||
let verPart: string = parts[0];
|
||||
let prereleasePart = parts.length > 1 ? `-${parts[1]}` : '';
|
||||
|
||||
let verParts: string[] = verPart.split('.');
|
||||
if (verParts.length == 2) {
|
||||
verPart += '.0';
|
||||
}
|
||||
|
||||
return `${verPart}${prereleasePart}`;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user