Work on resolving comments (#3)

* fix comments

* formatting

Co-authored-by: Dmitry Shibanov <v-dmshib@microsoft.com>
This commit is contained in:
Dmitry Shibanov 2020-06-26 15:43:43 +03:00 committed by GitHub
parent 60dce67d9a
commit 85b6f5f43e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 41 deletions

View file

@ -67,7 +67,7 @@ describe('setup-go', () => {
// writes // writes
cnSpy = jest.spyOn(process.stdout, 'write'); cnSpy = jest.spyOn(process.stdout, 'write');
logSpy = jest.spyOn(console, 'log'); logSpy = jest.spyOn(core, 'info');
dbgSpy = jest.spyOn(core, 'debug'); dbgSpy = jest.spyOn(core, 'debug');
getSpy.mockImplementation(() => <im.IGoVersion[] | null>goJsonData); getSpy.mockImplementation(() => <im.IGoVersion[] | null>goJsonData);
cnSpy.mockImplementation(line => { cnSpy.mockImplementation(line => {

40
dist/index.js vendored
View file

@ -1436,28 +1436,27 @@ function run() {
// stable will be true unless false is the exact input // stable will be true unless false is the exact input
// since getting unstable versions should be explicit // since getting unstable versions should be explicit
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
console.log(`Setup go ${stable ? 'stable' : ''} version spec ${versionSpec}`); core.info(`Setup go ${stable ? 'stable' : ''} version spec ${versionSpec}`);
if (versionSpec) { if (versionSpec) {
let token = core.getInput('token'); let token = core.getInput('token');
let auth = !token || isGhes() ? undefined : `token ${token}`; let auth = !token || isGhes() ? undefined : `token ${token}`;
const installDir = yield installer.getGo(versionSpec, stable, auth); const installDir = yield installer.getGo(versionSpec, stable, auth);
core.exportVariable('GOROOT', installDir); core.exportVariable('GOROOT', installDir);
core.addPath(path_1.default.join(installDir, 'bin')); core.addPath(path_1.default.join(installDir, 'bin'));
console.log('Added go to the path'); core.info('Added go to the path');
let added = addBinToPath(); let added = addBinToPath();
core.debug(`add bin ${added}`); core.info(`Successfully setup go version ${versionSpec}`);
console.log('Done');
} }
// add problem matchers // add problem matchers
const matchersPath = path_1.default.join(__dirname, '..', 'matchers.json'); const matchersPath = path_1.default.join(__dirname, '..', 'matchers.json');
console.log(`##[add-matcher]${matchersPath}`); core.info(`##[add-matcher]${matchersPath}`);
// output the version actually being used // output the version actually being used
let goPath = yield io.which('go'); let goPath = yield io.which('go');
let goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString(); let goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString();
console.log(goVersion); core.info(goVersion);
core.startGroup('go env'); core.startGroup('go env');
let goEnv = (child_process_1.default.execSync(`${goPath} env`) || '').toString(); let goEnv = (child_process_1.default.execSync(`${goPath} env`) || '').toString();
console.log(goEnv); core.info(goEnv);
core.endGroup(); core.endGroup();
} }
catch (error) { catch (error) {
@ -4952,10 +4951,10 @@ function getGo(versionSpec, stable, auth) {
toolPath = tc.find('go', versionSpec); toolPath = tc.find('go', versionSpec);
// If not found in cache, download // If not found in cache, download
if (toolPath) { if (toolPath) {
console.log(`Found in cache @ ${toolPath}`); core.info(`Found in cache @ ${toolPath}`);
return toolPath; return toolPath;
} }
console.log(`Attempting to download ${versionSpec}...`); core.info(`Attempting to download ${versionSpec}...`);
let downloadPath = ''; let downloadPath = '';
let info = null; let info = null;
// //
@ -4967,19 +4966,19 @@ function getGo(versionSpec, stable, auth) {
downloadPath = yield installGoVersion(info, auth); downloadPath = yield installGoVersion(info, auth);
} }
else { else {
console.log('Not found in manifest. Falling back to download directly from Go'); core.info('Not found in manifest. Falling back to download directly from Go');
} }
} }
catch (err) { catch (err) {
if (err instanceof tc.HTTPError && if (err instanceof tc.HTTPError &&
(err.httpStatusCode === 403 || err.httpStatusCode === 429)) { (err.httpStatusCode === 403 || err.httpStatusCode === 429)) {
console.log(`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`); core.info(`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`);
} }
else { else {
console.log(err.message); core.info(err.message);
} }
core.debug(err.stack); core.debug(err.stack);
console.log('Falling back to download directly from Go'); core.info('Falling back to download directly from Go');
} }
// //
// Download from storage.googleapis.com // Download from storage.googleapis.com
@ -4990,7 +4989,7 @@ function getGo(versionSpec, stable, auth) {
throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`); throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`);
} }
try { try {
console.log("Install from dist"); core.info('Install from dist');
downloadPath = yield installGoVersion(info, undefined); downloadPath = yield installGoVersion(info, undefined);
} }
catch (err) { catch (err) {
@ -5003,15 +5002,18 @@ function getGo(versionSpec, stable, auth) {
exports.getGo = getGo; exports.getGo = getGo;
function installGoVersion(info, auth) { function installGoVersion(info, auth) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
console.log(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
const downloadPath = yield tc.downloadTool(info.downloadUrl, undefined, auth); const downloadPath = yield tc.downloadTool(info.downloadUrl, undefined, auth);
console.log('Extracting Go...'); core.info('Extracting Go...');
let extPath = yield extractGoArchive(downloadPath); let extPath = yield extractGoArchive(downloadPath);
core.info(`Successfully extracted go to ${extPath}`);
if (info.type === 'dist') { if (info.type === 'dist') {
extPath = path.join(extPath, 'go'); extPath = path.join(extPath, 'go');
} }
console.log('Adding to the cache ...'); core.info('Adding to the cache ...');
return yield tc.cacheDir(extPath, 'go', makeSemver(info.resolvedVersion)); const cachedDir = yield tc.cacheDir(extPath, 'go', makeSemver(info.resolvedVersion));
core.info(`Successfully cached go to ${cachedDir}`);
return cachedDir;
}); });
} }
function extractGoArchive(archivePath) { function extractGoArchive(archivePath) {
@ -5032,7 +5034,7 @@ function getInfoFromManifest(versionSpec, stable, auth) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let info = null; let info = null;
const releases = yield tc.getManifestFromRepo('actions', 'go-versions', auth); const releases = yield tc.getManifestFromRepo('actions', 'go-versions', auth);
console.log(`matching ${versionSpec}...`); core.info(`matching ${versionSpec}...`);
const rel = yield tc.findFromManifest(versionSpec, stable, releases); const rel = yield tc.findFromManifest(versionSpec, stable, releases);
if (rel && rel.files.length > 0) { if (rel && rel.files.length > 0) {
info = {}; info = {};

View file

@ -41,10 +41,10 @@ export async function getGo(
toolPath = tc.find('go', versionSpec); toolPath = tc.find('go', versionSpec);
// If not found in cache, download // If not found in cache, download
if (toolPath) { if (toolPath) {
console.log(`Found in cache @ ${toolPath}`); core.info(`Found in cache @ ${toolPath}`);
return toolPath; return toolPath;
} }
console.log(`Attempting to download ${versionSpec}...`); core.info(`Attempting to download ${versionSpec}...`);
let downloadPath = ''; let downloadPath = '';
let info: IGoVersionInfo | null = null; let info: IGoVersionInfo | null = null;
@ -56,7 +56,7 @@ export async function getGo(
if (info) { if (info) {
downloadPath = await installGoVersion(info, auth); downloadPath = await installGoVersion(info, auth);
} else { } else {
console.log( core.info(
'Not found in manifest. Falling back to download directly from Go' 'Not found in manifest. Falling back to download directly from Go'
); );
} }
@ -65,14 +65,14 @@ export async function getGo(
err instanceof tc.HTTPError && err instanceof tc.HTTPError &&
(err.httpStatusCode === 403 || err.httpStatusCode === 429) (err.httpStatusCode === 403 || err.httpStatusCode === 429)
) { ) {
console.log( core.info(
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded` `Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
); );
} else { } else {
console.log(err.message); core.info(err.message);
} }
core.debug(err.stack); core.debug(err.stack);
console.log('Falling back to download directly from Go'); core.info('Falling back to download directly from Go');
} }
// //
@ -87,7 +87,7 @@ export async function getGo(
} }
try { try {
console.log('Install from dist'); core.info('Install from dist');
downloadPath = await installGoVersion(info, undefined); downloadPath = await installGoVersion(info, undefined);
} catch (err) { } catch (err) {
throw new Error(`Failed to download version ${versionSpec}: ${err}`); throw new Error(`Failed to download version ${versionSpec}: ${err}`);
@ -101,17 +101,24 @@ async function installGoVersion(
info: IGoVersionInfo, info: IGoVersionInfo,
auth: string | undefined auth: string | undefined
): Promise<string> { ): Promise<string> {
console.log(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
const downloadPath = await tc.downloadTool(info.downloadUrl, undefined, auth); const downloadPath = await tc.downloadTool(info.downloadUrl, undefined, auth);
console.log('Extracting Go...'); core.info('Extracting Go...');
let extPath = await extractGoArchive(downloadPath); let extPath = await extractGoArchive(downloadPath);
core.info(`Successfully extracted go to ${extPath}`);
if (info.type === 'dist') { if (info.type === 'dist') {
extPath = path.join(extPath, 'go'); extPath = path.join(extPath, 'go');
} }
console.log('Adding to the cache ...'); core.info('Adding to the cache ...');
return await tc.cacheDir(extPath, 'go', makeSemver(info.resolvedVersion)); const cachedDir = await tc.cacheDir(
extPath,
'go',
makeSemver(info.resolvedVersion)
);
core.info(`Successfully cached go to ${cachedDir}`);
return cachedDir;
} }
export async function extractGoArchive(archivePath: string): Promise<string> { export async function extractGoArchive(archivePath: string): Promise<string> {
@ -134,7 +141,7 @@ export async function getInfoFromManifest(
): Promise<IGoVersionInfo | null> { ): Promise<IGoVersionInfo | null> {
let info: IGoVersionInfo | null = null; let info: IGoVersionInfo | null = null;
const releases = await tc.getManifestFromRepo('actions', 'go-versions', auth); const releases = await tc.getManifestFromRepo('actions', 'go-versions', auth);
console.log(`matching ${versionSpec}...`); core.info(`matching ${versionSpec}...`);
const rel = await tc.findFromManifest(versionSpec, stable, releases); const rel = await tc.findFromManifest(versionSpec, stable, releases);
if (rel && rel.files.length > 0) { if (rel && rel.files.length > 0) {

View file

@ -18,9 +18,7 @@ export async function run() {
// since getting unstable versions should be explicit // since getting unstable versions should be explicit
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
console.log( core.info(`Setup go ${stable ? 'stable' : ''} version spec ${versionSpec}`);
`Setup go ${stable ? 'stable' : ''} version spec ${versionSpec}`
);
if (versionSpec) { if (versionSpec) {
let token = core.getInput('token'); let token = core.getInput('token');
@ -30,25 +28,24 @@ export async function run() {
core.exportVariable('GOROOT', installDir); core.exportVariable('GOROOT', installDir);
core.addPath(path.join(installDir, 'bin')); core.addPath(path.join(installDir, 'bin'));
console.log('Added go to the path'); core.info('Added go to the path');
let added = addBinToPath(); let added = addBinToPath();
core.debug(`add bin ${added}`); core.info(`Successfully setup go version ${versionSpec}`);
console.log('Done');
} }
// add problem matchers // add problem matchers
const matchersPath = path.join(__dirname, '..', 'matchers.json'); const matchersPath = path.join(__dirname, '..', 'matchers.json');
console.log(`##[add-matcher]${matchersPath}`); core.info(`##[add-matcher]${matchersPath}`);
// output the version actually being used // output the version actually being used
let goPath = await io.which('go'); let goPath = await io.which('go');
let goVersion = (cp.execSync(`${goPath} version`) || '').toString(); let goVersion = (cp.execSync(`${goPath} version`) || '').toString();
console.log(goVersion); core.info(goVersion);
core.startGroup('go env'); core.startGroup('go env');
let goEnv = (cp.execSync(`${goPath} env`) || '').toString(); let goEnv = (cp.execSync(`${goPath} env`) || '').toString();
console.log(goEnv); core.info(goEnv);
core.endGroup(); core.endGroup();
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);