mirror of
https://github.com/actions/setup-go.git
synced 2025-04-23 17:40:50 +00:00
use rest client for getting available versions
This commit is contained in:
parent
ab2744dd0f
commit
79642a476b
2 changed files with 25 additions and 24 deletions
|
@ -23,7 +23,7 @@ const os = __importStar(require("os"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
const util = __importStar(require("util"));
|
const util = __importStar(require("util"));
|
||||||
const semver = __importStar(require("semver"));
|
const semver = __importStar(require("semver"));
|
||||||
const httpm = __importStar(require("typed-rest-client/HttpClient"));
|
const restm = __importStar(require("typed-rest-client/RestClient"));
|
||||||
let osPlat = os.platform();
|
let osPlat = os.platform();
|
||||||
let osArch = os.arch();
|
let osArch = os.arch();
|
||||||
if (!tempDirectory) {
|
if (!tempDirectory) {
|
||||||
|
@ -155,24 +155,22 @@ function getLatestVersion(version) {
|
||||||
// clean .x syntax: 1.10.x -> 1.10
|
// clean .x syntax: 1.10.x -> 1.10
|
||||||
const trimmedVersion = version.slice(0, version.length - 2);
|
const trimmedVersion = version.slice(0, version.length - 2);
|
||||||
const versions = yield getPossibleVersions(trimmedVersion);
|
const versions = yield getPossibleVersions(trimmedVersion);
|
||||||
|
core.debug(`evaluating ${versions.length} versions`);
|
||||||
if (version.length === 0) {
|
if (version.length === 0) {
|
||||||
|
core.debug('match not found');
|
||||||
return trimmedVersion;
|
return trimmedVersion;
|
||||||
}
|
}
|
||||||
|
core.debug(`matched: ${versions[0]}`);
|
||||||
return versions[0];
|
return versions[0];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function unique(value, index, self) {
|
|
||||||
return self.indexOf(value) === index;
|
|
||||||
}
|
|
||||||
function getAvailableVersions() {
|
function getAvailableVersions() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let http = new httpm.HttpClient('setup-go');
|
let rest = new restm.RestClient('setup-go');
|
||||||
let contents = yield (yield http.get('https://api.github.com/repos/golang/go/git/refs/tags')).readBody();
|
let tags = (yield rest.get('https://api.github.com/repos/golang/go/git/refs/tags')).result || [];
|
||||||
const matches = contents.match(/go\d+\.[\w\.]+/g) || [];
|
return tags
|
||||||
const versions = matches
|
.filter(tag => tag.ref.match(/go\d+\.[\w\.]+/g))
|
||||||
.map(version => version.replace('go', ''))
|
.map(tag => tag.ref.replace('refs/tags/go', ''));
|
||||||
.filter(unique);
|
|
||||||
return versions;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getPossibleVersions(version) {
|
function getPossibleVersions(version) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import * as os from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as util from 'util';
|
import * as util from 'util';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import * as httpm from 'typed-rest-client/HttpClient';
|
import * as restm from 'typed-rest-client/RestClient';
|
||||||
|
|
||||||
let osPlat: string = os.platform();
|
let osPlat: string = os.platform();
|
||||||
let osArch: string = os.arch();
|
let osArch: string = os.arch();
|
||||||
|
@ -155,29 +155,32 @@ async function getLatestVersion(version: string): Promise<string> {
|
||||||
|
|
||||||
const versions = await getPossibleVersions(trimmedVersion);
|
const versions = await getPossibleVersions(trimmedVersion);
|
||||||
|
|
||||||
|
core.debug(`evaluating ${versions.length} versions`);
|
||||||
|
|
||||||
if (version.length === 0) {
|
if (version.length === 0) {
|
||||||
|
core.debug('match not found');
|
||||||
return trimmedVersion;
|
return trimmedVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.debug(`matched: ${versions[0]}`);
|
||||||
|
|
||||||
return versions[0];
|
return versions[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
function unique(value: string, index: number, self: string[]) {
|
interface IGoRef {
|
||||||
return self.indexOf(value) === index;
|
ref: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAvailableVersions(): Promise<string[]> {
|
async function getAvailableVersions(): Promise<string[]> {
|
||||||
let http: httpm.HttpClient = new httpm.HttpClient('setup-go');
|
let rest: restm.RestClient = new restm.RestClient('setup-go');
|
||||||
let contents = await (await http.get(
|
let tags: IGoRef[] =
|
||||||
'https://api.github.com/repos/golang/go/git/refs/tags'
|
(await rest.get<IGoRef[]>(
|
||||||
)).readBody();
|
'https://api.github.com/repos/golang/go/git/refs/tags'
|
||||||
|
)).result || [];
|
||||||
|
|
||||||
const matches = contents.match(/go\d+\.[\w\.]+/g) || [];
|
return tags
|
||||||
const versions = matches
|
.filter(tag => tag.ref.match(/go\d+\.[\w\.]+/g))
|
||||||
.map(version => version.replace('go', ''))
|
.map(tag => tag.ref.replace('refs/tags/go', ''));
|
||||||
.filter(unique);
|
|
||||||
|
|
||||||
return versions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getPossibleVersions(version: string): Promise<string[]> {
|
async function getPossibleVersions(version: string): Promise<string[]> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue