2019-09-20 20:23:45 +00:00
|
|
|
import * as os from 'os';
|
|
|
|
import * as path from 'path';
|
|
|
|
import * as util from 'util';
|
2020-05-07 00:15:24 +00:00
|
|
|
import * as github from './github';
|
2021-05-27 03:25:31 +00:00
|
|
|
import * as pro from './pro';
|
2020-05-07 00:15:24 +00:00
|
|
|
import * as core from '@actions/core';
|
|
|
|
import * as tc from '@actions/tool-cache';
|
2019-09-20 20:23:45 +00:00
|
|
|
|
2020-05-07 00:15:24 +00:00
|
|
|
const osPlat: string = os.platform();
|
|
|
|
const osArch: string = os.arch();
|
2019-09-20 20:23:45 +00:00
|
|
|
|
2021-05-27 03:25:31 +00:00
|
|
|
export async function getGoReleaser(distribution: string, version: string): Promise<string> {
|
|
|
|
const release: github.GitHubRelease | null = await github.getRelease(distribution, version);
|
2020-05-07 00:15:24 +00:00
|
|
|
if (!release) {
|
|
|
|
throw new Error(`Cannot find GoReleaser ${version} release`);
|
2019-09-20 20:23:45 +00:00
|
|
|
}
|
|
|
|
|
2021-05-27 03:25:31 +00:00
|
|
|
const filename = getFilename(distribution);
|
2019-09-20 20:23:45 +00:00
|
|
|
const downloadUrl = util.format(
|
2021-05-27 03:25:31 +00:00
|
|
|
'https://github.com/goreleaser/%s/releases/download/%s/%s',
|
|
|
|
distribution,
|
2020-05-07 00:15:24 +00:00
|
|
|
release.tag_name,
|
|
|
|
filename
|
2019-09-20 20:23:45 +00:00
|
|
|
);
|
|
|
|
|
2021-06-10 01:02:52 +00:00
|
|
|
core.info(`Downloading ${downloadUrl}`);
|
2020-05-07 00:15:24 +00:00
|
|
|
const downloadPath: string = await tc.downloadTool(downloadUrl);
|
|
|
|
core.debug(`Downloaded to ${downloadPath}`);
|
2019-09-20 20:23:45 +00:00
|
|
|
|
2021-06-10 01:02:52 +00:00
|
|
|
core.info('Extracting GoReleaser');
|
2020-05-07 00:15:24 +00:00
|
|
|
let extPath: string;
|
2019-09-20 20:23:45 +00:00
|
|
|
if (osPlat == 'win32') {
|
2020-05-07 00:15:24 +00:00
|
|
|
extPath = await tc.extractZip(downloadPath);
|
2019-09-20 20:23:45 +00:00
|
|
|
} else {
|
2020-05-07 00:15:24 +00:00
|
|
|
extPath = await tc.extractTar(downloadPath);
|
2019-09-20 20:23:45 +00:00
|
|
|
}
|
2020-05-07 00:15:24 +00:00
|
|
|
core.debug(`Extracted to ${extPath}`);
|
2019-09-20 20:23:45 +00:00
|
|
|
|
2020-05-07 00:15:24 +00:00
|
|
|
const cachePath: string = await tc.cacheDir(extPath, 'goreleaser-action', release.tag_name.replace(/^v/, ''));
|
|
|
|
core.debug(`Cached to ${cachePath}`);
|
|
|
|
|
|
|
|
const exePath: string = path.join(cachePath, osPlat == 'win32' ? 'goreleaser.exe' : 'goreleaser');
|
|
|
|
core.debug(`Exe path is ${exePath}`);
|
|
|
|
|
|
|
|
return exePath;
|
2019-09-20 20:23:45 +00:00
|
|
|
}
|
|
|
|
|
2021-05-27 03:25:31 +00:00
|
|
|
const getFilename = (distribution: string): string => {
|
2019-11-11 23:05:29 +00:00
|
|
|
const platform: string = osPlat == 'win32' ? 'Windows' : osPlat == 'darwin' ? 'Darwin' : 'Linux';
|
2021-08-27 10:02:19 +00:00
|
|
|
const arch: string = osArch == 'x64' ? 'x86_64' : osArch == 'x32' ? 'i386' : osArch;
|
2019-09-20 20:23:45 +00:00
|
|
|
const ext: string = osPlat == 'win32' ? 'zip' : 'tar.gz';
|
2021-05-27 03:25:31 +00:00
|
|
|
const suffix: string = pro.suffix(distribution);
|
|
|
|
return util.format('goreleaser%s_%s_%s.%s', suffix, platform, arch, ext);
|
2020-05-07 00:15:24 +00:00
|
|
|
};
|