Compare commits

...

5 Commits

Author SHA1 Message Date
9fbc767707 Merge pull request #30 from hross/master
Change getFileName to do architecture lookups and add arm support
2019-11-25 07:17:19 -05:00
0cbaec8e4b Change getFileName to do architecture lookups and add arm support 2019-11-21 10:23:32 -05:00
75259a5ae0 Merge pull request #20 from subosito/golang-dl
Use golang-dl release data
2019-09-16 15:42:36 +01:00
bc6edb526d update test assertion 2019-09-05 13:27:28 +07:00
21620fff65 use golang-dl release data 2019-09-05 13:09:55 +07:00
5 changed files with 10228 additions and 2499 deletions

10196
__tests__/data/golang-dl.json Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -43,9 +43,10 @@ describe('installer tests', () => {
describe('the latest release of a go version', () => { describe('the latest release of a go version', () => {
beforeEach(() => { beforeEach(() => {
nock('https://api.github.com') nock('https://golang.org')
.get('/repos/golang/go/git/refs/tags') .get('/dl/')
.replyWithFile(200, path.join(dataDir, 'golang-tags.json')); .query({mode: 'json', include: 'all'})
.replyWithFile(200, path.join(dataDir, 'golang-dl.json'));
}); });
afterEach(() => { afterEach(() => {
@ -79,7 +80,7 @@ describe('installer tests', () => {
it('Acquires latest release version of go if using 1.x and no matching version is installed', async () => { it('Acquires latest release version of go if using 1.x and no matching version is installed', async () => {
await installer.getGo('1.x'); await installer.getGo('1.x');
const goDir = path.join(toolDir, 'go', '1.13.0-beta1', os.arch()); const goDir = path.join(toolDir, 'go', '1.13.0', os.arch());
expect(fs.existsSync(`${goDir}.complete`)).toBe(true); expect(fs.existsSync(`${goDir}.complete`)).toBe(true);
if (IS_WINDOWS) { if (IS_WINDOWS) {

View File

@ -72,6 +72,7 @@ function acquireGo(version) {
// //
let fileName = getFileName(version); let fileName = getFileName(version);
let downloadUrl = getDownloadUrl(fileName); let downloadUrl = getDownloadUrl(fileName);
core.debug('Downloading Go from: ' + downloadUrl);
let downloadPath = null; let downloadPath = null;
try { try {
downloadPath = yield tc.downloadTool(downloadUrl); downloadPath = yield tc.downloadTool(downloadUrl);
@ -102,8 +103,14 @@ function acquireGo(version) {
}); });
} }
function getFileName(version) { function getFileName(version) {
const arches = {
x64: 'amd64',
arm: 'armv6l',
arm64: 'arm64',
default: '386'
};
const platform = osPlat == 'win32' ? 'windows' : osPlat; const platform = osPlat == 'win32' ? 'windows' : osPlat;
const arch = osArch == 'x64' ? 'amd64' : '386'; const arch = arches[osArch] || arches['default'];
const ext = osPlat == 'win32' ? 'zip' : 'tar.gz'; const ext = osPlat == 'win32' ? 'zip' : 'tar.gz';
const filename = util.format('go%s.%s-%s.%s', version, platform, arch, ext); const filename = util.format('go%s.%s-%s.%s', version, platform, arch, ext);
return filename; return filename;
@ -186,10 +193,9 @@ function getLatestVersion(version) {
function getAvailableVersions() { function getAvailableVersions() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let rest = new restm.RestClient('setup-go'); let rest = new restm.RestClient('setup-go');
let tags = (yield rest.get('https://api.github.com/repos/golang/go/git/refs/tags')).result || []; let tags = (yield rest.get('https://golang.org/dl/?mode=json&include=all'))
return tags .result || [];
.filter(tag => tag.ref.match(/go\d+\.[\w\.]+/g)) return tags.map(tag => tag.version.replace('go', ''));
.map(tag => tag.ref.replace('refs/tags/go', ''));
}); });
} }
function getPossibleVersions(version) { function getPossibleVersions(version) {

View File

@ -57,6 +57,9 @@ async function acquireGo(version: string): Promise<string> {
// //
let fileName: string = getFileName(version); let fileName: string = getFileName(version);
let downloadUrl: string = getDownloadUrl(fileName); let downloadUrl: string = getDownloadUrl(fileName);
core.debug('Downloading Go from: ' + downloadUrl);
let downloadPath: string | null = null; let downloadPath: string | null = null;
try { try {
downloadPath = await tc.downloadTool(downloadUrl); downloadPath = await tc.downloadTool(downloadUrl);
@ -89,8 +92,15 @@ async function acquireGo(version: string): Promise<string> {
} }
function getFileName(version: string): string { function getFileName(version: string): string {
const arches: {[arch: string]: string} = {
x64: 'amd64',
arm: 'armv6l',
arm64: 'arm64',
default: '386'
};
const platform: string = osPlat == 'win32' ? 'windows' : osPlat; const platform: string = osPlat == 'win32' ? 'windows' : osPlat;
const arch: string = osArch == 'x64' ? 'amd64' : '386'; const arch: string = arches[osArch] || arches['default'];
const ext: string = osPlat == 'win32' ? 'zip' : 'tar.gz'; const ext: string = osPlat == 'win32' ? 'zip' : 'tar.gz';
const filename: string = util.format( const filename: string = util.format(
'go%s.%s-%s.%s', 'go%s.%s-%s.%s',
@ -99,6 +109,7 @@ function getFileName(version: string): string {
arch, arch,
ext ext
); );
return filename; return filename;
} }
@ -187,19 +198,16 @@ async function getLatestVersion(version: string): Promise<string> {
} }
interface IGoRef { interface IGoRef {
ref: string; version: string;
} }
async function getAvailableVersions(): Promise<string[]> { async function getAvailableVersions(): Promise<string[]> {
let rest: restm.RestClient = new restm.RestClient('setup-go'); let rest: restm.RestClient = new restm.RestClient('setup-go');
let tags: IGoRef[] = let tags: IGoRef[] =
(await rest.get<IGoRef[]>( (await rest.get<IGoRef[]>('https://golang.org/dl/?mode=json&include=all'))
'https://api.github.com/repos/golang/go/git/refs/tags' .result || [];
)).result || [];
return tags return tags.map(tag => tag.version.replace('go', ''));
.filter(tag => tag.ref.match(/go\d+\.[\w\.]+/g))
.map(tag => tag.ref.replace('refs/tags/go', ''));
} }
async function getPossibleVersions(version: string): Promise<string[]> { async function getPossibleVersions(version: string): Promise<string[]> {