Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
pre-release version and test
  • Loading branch information
Bryan MacFarlane committed Feb 11, 2020
1 parent 4388031 commit 768458b
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 20 deletions.
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -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
Expand All @@ -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)
Expand Down
69 changes: 51 additions & 18 deletions __tests__/setup-go.test.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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 changes: 20 additions & 1 deletion dist/index.js
Expand Up @@ -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('.');
Expand Down Expand Up @@ -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;


/***/ }),
Expand Down
24 changes: 23 additions & 1 deletion src/installer.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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}`;
}

0 comments on commit 768458b

Please sign in to comment.