mirror of
https://github.com/actions/setup-go.git
synced 2025-04-23 17:40:50 +00:00
more .x handling
This commit is contained in:
parent
79642a476b
commit
1d577b5f50
3 changed files with 84 additions and 14 deletions
|
@ -30,8 +30,8 @@ describe('installer tests', () => {
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
||||||
it('Acquires version of go if no matching version is installed', async () => {
|
it('Acquires version of go if no matching version is installed', async () => {
|
||||||
await installer.getGo('1.10');
|
await installer.getGo('1.10.8');
|
||||||
const goDir = path.join(toolDir, 'go', '1.10.0', os.arch());
|
const goDir = path.join(toolDir, 'go', '1.10.8', os.arch());
|
||||||
|
|
||||||
expect(fs.existsSync(`${goDir}.complete`)).toBe(true);
|
expect(fs.existsSync(`${goDir}.complete`)).toBe(true);
|
||||||
if (IS_WINDOWS) {
|
if (IS_WINDOWS) {
|
||||||
|
@ -41,7 +41,23 @@ describe('installer tests', () => {
|
||||||
}
|
}
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
||||||
it('Acquires latest release version of go if using .x syntax and no matching version is installed', async () => {
|
it('Acquires latest release version of go 1.10 if using 1.10 and no matching version is installed', async () => {
|
||||||
|
nock('https://api.github.com')
|
||||||
|
.get('/repos/golang/go/git/refs/tags')
|
||||||
|
.replyWithFile(200, path.join(dataDir, 'golang-tags.json'));
|
||||||
|
|
||||||
|
await installer.getGo('1.10');
|
||||||
|
const goDir = path.join(toolDir, 'go', '1.10.8', os.arch());
|
||||||
|
|
||||||
|
expect(fs.existsSync(`${goDir}.complete`)).toBe(true);
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
expect(fs.existsSync(path.join(goDir, 'bin', 'go.exe'))).toBe(true);
|
||||||
|
} else {
|
||||||
|
expect(fs.existsSync(path.join(goDir, 'bin', 'go'))).toBe(true);
|
||||||
|
}
|
||||||
|
}, 100000);
|
||||||
|
|
||||||
|
it('Acquires latest release version of go 1.10 if using 1.10.x and no matching version is installed', async () => {
|
||||||
nock('https://api.github.com')
|
nock('https://api.github.com')
|
||||||
.get('/repos/golang/go/git/refs/tags')
|
.get('/repos/golang/go/git/refs/tags')
|
||||||
.replyWithFile(200, path.join(dataDir, 'golang-tags.json'));
|
.replyWithFile(200, path.join(dataDir, 'golang-tags.json'));
|
||||||
|
@ -57,6 +73,22 @@ describe('installer tests', () => {
|
||||||
}
|
}
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
||||||
|
it('Acquires latest release version of go if using 1.x and no matching version is installed', async () => {
|
||||||
|
nock('https://api.github.com')
|
||||||
|
.get('/repos/golang/go/git/refs/tags')
|
||||||
|
.replyWithFile(200, path.join(dataDir, 'golang-tags.json'));
|
||||||
|
|
||||||
|
await installer.getGo('1.x');
|
||||||
|
const goDir = path.join(toolDir, 'go', '1.13.0-beta1', os.arch());
|
||||||
|
|
||||||
|
expect(fs.existsSync(`${goDir}.complete`)).toBe(true);
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
expect(fs.existsSync(path.join(goDir, 'bin', 'go.exe'))).toBe(true);
|
||||||
|
} else {
|
||||||
|
expect(fs.existsSync(path.join(goDir, 'bin', 'go'))).toBe(true);
|
||||||
|
}
|
||||||
|
}, 100000);
|
||||||
|
|
||||||
it('Throws if no location contains correct go version', async () => {
|
it('Throws if no location contains correct go version', async () => {
|
||||||
let thrown = false;
|
let thrown = false;
|
||||||
try {
|
try {
|
||||||
|
@ -72,7 +104,7 @@ describe('installer tests', () => {
|
||||||
await io.mkdirP(goDir);
|
await io.mkdirP(goDir);
|
||||||
fs.writeFileSync(`${goDir}.complete`, 'hello');
|
fs.writeFileSync(`${goDir}.complete`, 'hello');
|
||||||
// This will throw if it doesn't find it in the cache (because no such version exists)
|
// This will throw if it doesn't find it in the cache (because no such version exists)
|
||||||
await installer.getGo('250.0');
|
await installer.getGo('250.0.0');
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,10 @@ if (!tempDirectory) {
|
||||||
}
|
}
|
||||||
function getGo(version) {
|
function getGo(version) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
version = yield determineVersion(version);
|
const selected = yield determineVersion(version);
|
||||||
|
if (selected) {
|
||||||
|
version = selected;
|
||||||
|
}
|
||||||
// check cache
|
// check cache
|
||||||
let toolPath;
|
let toolPath;
|
||||||
toolPath = tc.find('go', normalizeVersion(version));
|
toolPath = tc.find('go', normalizeVersion(version));
|
||||||
|
@ -129,7 +132,7 @@ function normalizeVersion(version) {
|
||||||
//append minor and patch version if not available
|
//append minor and patch version if not available
|
||||||
return version.concat('.0.0');
|
return version.concat('.0.0');
|
||||||
}
|
}
|
||||||
else if (versionPart[2] == null) {
|
else {
|
||||||
// handle beta and rc: 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
|
// handle beta and rc: 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
|
||||||
if (versionPart[1].includes('beta') || versionPart[1].includes('rc')) {
|
if (versionPart[1].includes('beta') || versionPart[1].includes('rc')) {
|
||||||
versionPart[1] = versionPart[1]
|
versionPart[1] = versionPart[1]
|
||||||
|
@ -137,15 +140,32 @@ function normalizeVersion(version) {
|
||||||
.replace('rc', '.0-rc');
|
.replace('rc', '.0-rc');
|
||||||
return versionPart.join('.');
|
return versionPart.join('.');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (versionPart[2] == null) {
|
||||||
//append patch version if not available
|
//append patch version if not available
|
||||||
return version.concat('.0');
|
return version.concat('.0');
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// handle beta and rc: 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1
|
||||||
|
if (versionPart[2].includes('beta') || versionPart[2].includes('rc')) {
|
||||||
|
versionPart[2] = versionPart[2]
|
||||||
|
.replace('beta', '-beta')
|
||||||
|
.replace('rc', '-rc');
|
||||||
|
return versionPart.join('.');
|
||||||
|
}
|
||||||
|
}
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
function determineVersion(version) {
|
function determineVersion(version) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
if (!version.endsWith('.x')) {
|
if (!version.endsWith('.x')) {
|
||||||
return version;
|
const versionPart = version.split('.');
|
||||||
|
if (versionPart[1] == null || versionPart[2] == null) {
|
||||||
|
return yield getLatestVersion(version.concat('.x'));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return yield getLatestVersion(version);
|
return yield getLatestVersion(version);
|
||||||
});
|
});
|
||||||
|
@ -157,8 +177,7 @@ function getLatestVersion(version) {
|
||||||
const versions = yield getPossibleVersions(trimmedVersion);
|
const versions = yield getPossibleVersions(trimmedVersion);
|
||||||
core.debug(`evaluating ${versions.length} versions`);
|
core.debug(`evaluating ${versions.length} versions`);
|
||||||
if (version.length === 0) {
|
if (version.length === 0) {
|
||||||
core.debug('match not found');
|
throw new Error('unable to get latest version');
|
||||||
return trimmedVersion;
|
|
||||||
}
|
}
|
||||||
core.debug(`matched: ${versions[0]}`);
|
core.debug(`matched: ${versions[0]}`);
|
||||||
return versions[0];
|
return versions[0];
|
||||||
|
|
|
@ -27,7 +27,10 @@ if (!tempDirectory) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGo(version: string) {
|
export async function getGo(version: string) {
|
||||||
version = await determineVersion(version);
|
const selected = await determineVersion(version);
|
||||||
|
if (selected) {
|
||||||
|
version = selected;
|
||||||
|
}
|
||||||
|
|
||||||
// check cache
|
// check cache
|
||||||
let toolPath: string;
|
let toolPath: string;
|
||||||
|
@ -126,7 +129,7 @@ function normalizeVersion(version: string): string {
|
||||||
if (versionPart[1] == null) {
|
if (versionPart[1] == null) {
|
||||||
//append minor and patch version if not available
|
//append minor and patch version if not available
|
||||||
return version.concat('.0.0');
|
return version.concat('.0.0');
|
||||||
} else if (versionPart[2] == null) {
|
} else {
|
||||||
// handle beta and rc: 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
|
// handle beta and rc: 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
|
||||||
if (versionPart[1].includes('beta') || versionPart[1].includes('rc')) {
|
if (versionPart[1].includes('beta') || versionPart[1].includes('rc')) {
|
||||||
versionPart[1] = versionPart[1]
|
versionPart[1] = versionPart[1]
|
||||||
|
@ -134,16 +137,33 @@ function normalizeVersion(version: string): string {
|
||||||
.replace('rc', '.0-rc');
|
.replace('rc', '.0-rc');
|
||||||
return versionPart.join('.');
|
return versionPart.join('.');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (versionPart[2] == null) {
|
||||||
//append patch version if not available
|
//append patch version if not available
|
||||||
return version.concat('.0');
|
return version.concat('.0');
|
||||||
|
} else {
|
||||||
|
// handle beta and rc: 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1
|
||||||
|
if (versionPart[2].includes('beta') || versionPart[2].includes('rc')) {
|
||||||
|
versionPart[2] = versionPart[2]
|
||||||
|
.replace('beta', '-beta')
|
||||||
|
.replace('rc', '-rc');
|
||||||
|
return versionPart.join('.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function determineVersion(version: string): Promise<string> {
|
async function determineVersion(version: string): Promise<string> {
|
||||||
if (!version.endsWith('.x')) {
|
if (!version.endsWith('.x')) {
|
||||||
return version;
|
const versionPart = version.split('.');
|
||||||
|
|
||||||
|
if (versionPart[1] == null || versionPart[2] == null) {
|
||||||
|
return await getLatestVersion(version.concat('.x'));
|
||||||
|
} else {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return await getLatestVersion(version);
|
return await getLatestVersion(version);
|
||||||
|
@ -158,8 +178,7 @@ async function getLatestVersion(version: string): Promise<string> {
|
||||||
core.debug(`evaluating ${versions.length} versions`);
|
core.debug(`evaluating ${versions.length} versions`);
|
||||||
|
|
||||||
if (version.length === 0) {
|
if (version.length === 0) {
|
||||||
core.debug('match not found');
|
throw new Error('unable to get latest version');
|
||||||
return trimmedVersion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(`matched: ${versions[0]}`);
|
core.debug(`matched: ${versions[0]}`);
|
||||||
|
|
Loading…
Add table
Reference in a new issue