Skip to content

Commit 768458b

Browse files
pre-release version and test
1 parent 4388031 commit 768458b

File tree

4 files changed

+106
-20
lines changed

4 files changed

+106
-20
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The V2 beta offers:
1818
- stable input
1919
- Bug Fixes (including issues around version matching and semver)
2020

21+
Matching by semver spec:
2122
```yaml
2223
steps:
2324
- uses: actions/checkout@v2
@@ -27,6 +28,17 @@ steps:
2728
- run: go version
2829
```
2930
31+
Matching an unstable pre-release:
32+
```yaml
33+
steps:
34+
- uses: actions/checkout@v2
35+
- uses: actions/setup-go@v2-beta
36+
with:
37+
stable: 'false'
38+
go-version: '1.14.0-rc1' # The Go version to download (if necessary) and use.
39+
- run: go version
40+
```
41+
3042
# Usage
3143
3244
See [action.yml](action.yml)

__tests__/setup-go.test.ts

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,29 @@ describe('setup-go', () => {
6767

6868
afterAll(async () => {}, 100000);
6969

70+
it('can query versions', async () => {
71+
let versions: im.IGoVersion[] | null = await im.getVersions(
72+
'https://non.existant.com/path'
73+
);
74+
expect(versions).toBeDefined();
75+
let l: number = versions ? versions.length : 0;
76+
expect(l).toBe(91);
77+
});
78+
79+
it('finds stable match for exact version', async () => {
80+
os.platform = 'win32';
81+
os.arch = 'x64';
82+
83+
// get request is already mocked
84+
// spec: 1.13.7 => 1.13.7 (exact)
85+
let match: im.IGoVersion | undefined = await im.findMatch('1.13.7', true);
86+
expect(match).toBeDefined();
87+
let version: string = match ? match.version : '';
88+
expect(version).toBe('go1.13.7');
89+
let fileName = match ? match.files[0].filename : '';
90+
expect(fileName).toBe('go1.13.7.windows-amd64.zip');
91+
});
92+
7093
it('finds stable match for exact dot zero version', async () => {
7194
os.platform = 'darwin';
7295
os.arch = 'x64';
@@ -119,6 +142,22 @@ describe('setup-go', () => {
119142
expect(fileName).toBe('go1.13.7.windows-386.zip');
120143
});
121144

145+
it('finds unstable pre-release version', async () => {
146+
os.platform = 'linux';
147+
os.arch = 'x64';
148+
149+
// spec: 1.14, stable=false => go1.14rc1
150+
let match: im.IGoVersion | undefined = await im.findMatch(
151+
'1.14.0-rc1',
152+
false
153+
);
154+
expect(match).toBeDefined();
155+
let version: string = match ? match.version : '';
156+
expect(version).toBe('go1.14rc1');
157+
let fileName = match ? match.files[0].filename : '';
158+
expect(fileName).toBe('go1.14rc1.linux-amd64.tar.gz');
159+
});
160+
122161
it('evaluates to stable with input as true', async () => {
123162
inputs['go-version'] = '1.13.0';
124163
inputs.stable = 'true';
@@ -241,26 +280,20 @@ describe('setup-go', () => {
241280
);
242281
});
243282

244-
it('can query versions', async () => {
245-
let versions: im.IGoVersion[] | null = await im.getVersions(
246-
'https://non.existant.com/path'
247-
);
248-
expect(versions).toBeDefined();
249-
let l: number = versions ? versions.length : 0;
250-
expect(l).toBe(91);
283+
// 1.13.1 => 1.13.1
284+
// 1.13 => 1.13.0
285+
// 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
286+
// 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1
287+
it('converts prerelease versions', async () => {
288+
expect(im.makeSemver('1.10beta1')).toBe('1.10.0-beta1');
289+
expect(im.makeSemver('1.10rc1')).toBe('1.10.0-rc1');
251290
});
252291

253-
it('finds stable match for exact version', async () => {
254-
os.platform = 'win32';
255-
os.arch = 'x64';
292+
it('converts dot zero versions', async () => {
293+
expect(im.makeSemver('1.13')).toBe('1.13.0');
294+
});
256295

257-
// get request is already mocked
258-
// spec: 1.13.7 => 1.13.7 (exact)
259-
let match: im.IGoVersion | undefined = await im.findMatch('1.13.7', true);
260-
expect(match).toBeDefined();
261-
let version: string = match ? match.version : '';
262-
expect(version).toBe('go1.13.7');
263-
let fileName = match ? match.files[0].filename : '';
264-
expect(fileName).toBe('go1.13.7.windows-amd64.zip');
296+
it('does not convert exact versions', async () => {
297+
expect(im.makeSemver('1.13.1')).toBe('1.13.1');
265298
});
266299
});

dist/index.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4625,7 +4625,7 @@ function findMatch(versionSpec, stable) {
46254625
let goFile;
46264626
for (let i = 0; i < candidates.length; i++) {
46274627
let candidate = candidates[i];
4628-
let version = candidate.version.replace('go', '');
4628+
let version = makeSemver(candidate.version);
46294629
// 1.13.0 is advertised as 1.13 preventing being able to match exactly 1.13.0
46304630
// since a semver of 1.13 would match latest 1.13
46314631
let parts = version.split('.');
@@ -4663,6 +4663,25 @@ function getVersions(dlUrl) {
46634663
});
46644664
}
46654665
exports.getVersions = getVersions;
4666+
//
4667+
// Convert the go version syntax into semver for semver matching
4668+
// 1.13.1 => 1.13.1
4669+
// 1.13 => 1.13.0
4670+
// 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
4671+
// 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1
4672+
function makeSemver(version) {
4673+
version = version.replace('go', '');
4674+
version = version.replace('beta', '-beta').replace('rc', '-rc');
4675+
let parts = version.split('-');
4676+
let verPart = parts[0];
4677+
let prereleasePart = parts.length > 1 ? `-${parts[1]}` : '';
4678+
let verParts = verPart.split('.');
4679+
if (verParts.length == 2) {
4680+
verPart += '.0';
4681+
}
4682+
return `${verPart}${prereleasePart}`;
4683+
}
4684+
exports.makeSemver = makeSemver;
46664685

46674686

46684687
/***/ }),

src/installer.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export async function findMatch(
7474
let goFile: IGoVersionFile | undefined;
7575
for (let i = 0; i < candidates.length; i++) {
7676
let candidate: IGoVersion = candidates[i];
77-
let version = candidate.version.replace('go', '');
77+
let version = makeSemver(candidate.version);
7878

7979
// 1.13.0 is advertised as 1.13 preventing being able to match exactly 1.13.0
8080
// since a semver of 1.13 would match latest 1.13
@@ -115,3 +115,25 @@ export async function getVersions(dlUrl: string): Promise<IGoVersion[] | null> {
115115
let http: httpm.HttpClient = new httpm.HttpClient('setup-go');
116116
return (await http.getJson<IGoVersion[]>(dlUrl)).result;
117117
}
118+
119+
//
120+
// Convert the go version syntax into semver for semver matching
121+
// 1.13.1 => 1.13.1
122+
// 1.13 => 1.13.0
123+
// 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
124+
// 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1
125+
export function makeSemver(version: string): string {
126+
version = version.replace('go', '');
127+
version = version.replace('beta', '-beta').replace('rc', '-rc');
128+
let parts = version.split('-');
129+
130+
let verPart: string = parts[0];
131+
let prereleasePart = parts.length > 1 ? `-${parts[1]}` : '';
132+
133+
let verParts: string[] = verPart.split('.');
134+
if (verParts.length == 2) {
135+
verPart += '.0';
136+
}
137+
138+
return `${verPart}${prereleasePart}`;
139+
}

0 commit comments

Comments
 (0)