From f237316c5ae1ee5b7e8096ac149a339ab1006c6f Mon Sep 17 00:00:00 2001 From: Max Veytsman Date: Wed, 29 Apr 2020 15:25:48 -0400 Subject: [PATCH 1/2] Improve errors & warnings in autobuild --- lib/autobuild.js | 8 ++++++-- src/autobuild.ts | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/autobuild.js b/lib/autobuild.js index bce7f3a34..8f3dcecba 100644 --- a/lib/autobuild.js +++ b/lib/autobuild.js @@ -22,12 +22,16 @@ async function run() { // We want pick the dominant language in the repo from the ones we're able to build // The languages are sorted in order specified by user or by lines of code if we got // them from the GitHub API, so try to build the first language on the list. - const language = (_a = process.env[sharedEnv.CODEQL_ACTION_TRACED_LANGUAGES]) === null || _a === void 0 ? void 0 : _a.split(',')[0]; + const autobuildLanguages = ((_a = process.env[sharedEnv.CODEQL_ACTION_TRACED_LANGUAGES]) === null || _a === void 0 ? void 0 : _a.split(',')) || []; + const language = autobuildLanguages[0]; if (!language) { core.info("None of the languages in this project require extra build steps"); return; } core.debug(`Detected dominant traced language: ${language}`); + if (autobuildLanguages.length > 1) { + core.warning(`We will only automatically build ${language} code. If you wish to scan ${autobuildLanguages.slice(1).join(' and ')}, you must replace this block with custom build steps.`); + } core.startGroup(`Attempting to automatically build ${language} code`); // TODO: share config accross actions better via env variables const codeqlCmd = util.getRequiredEnvParam(sharedEnv.CODEQL_ACTION_CMD); @@ -51,6 +55,6 @@ async function run() { await util.reportActionSucceeded('autobuild'); } run().catch(e => { - core.setFailed("autobuild action failed: " + e); + core.setFailed("We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps. codeql/autobuild action failed. " + e); console.log(e); }); diff --git a/src/autobuild.ts b/src/autobuild.ts index bd7b37f25..519ebb190 100644 --- a/src/autobuild.ts +++ b/src/autobuild.ts @@ -15,7 +15,8 @@ async function run() { // We want pick the dominant language in the repo from the ones we're able to build // The languages are sorted in order specified by user or by lines of code if we got // them from the GitHub API, so try to build the first language on the list. - const language = process.env[sharedEnv.CODEQL_ACTION_TRACED_LANGUAGES]?.split(',')[0]; + const autobuildLanguages = process.env[sharedEnv.CODEQL_ACTION_TRACED_LANGUAGES]?.split(',') || []; + const language = autobuildLanguages[0]; if (!language) { core.info("None of the languages in this project require extra build steps"); @@ -24,6 +25,10 @@ async function run() { core.debug(`Detected dominant traced language: ${language}`); + if (autobuildLanguages.length > 1) { + core.warning(`We will only automatically build ${language} code. If you wish to scan ${autobuildLanguages.slice(1).join(' and ')}, you must replace this block with custom build steps.`); + } + core.startGroup(`Attempting to automatically build ${language} code`); // TODO: share config accross actions better via env variables const codeqlCmd = util.getRequiredEnvParam(sharedEnv.CODEQL_ACTION_CMD); @@ -53,6 +58,6 @@ async function run() { } run().catch(e => { - core.setFailed("autobuild action failed: " + e); + core.setFailed("We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps. codeql/autobuild action failed. " + e); console.log(e); }); From 7963db13d860f4ccdb4463e1ebf3e1b854516f5e Mon Sep 17 00:00:00 2001 From: Max Veytsman Date: Thu, 30 Apr 2020 09:11:50 -0400 Subject: [PATCH 2/2] Move error to correct catch block --- lib/autobuild.js | 4 ++-- src/autobuild.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/autobuild.js b/lib/autobuild.js index 8f3dcecba..6776b80ff 100644 --- a/lib/autobuild.js +++ b/lib/autobuild.js @@ -48,13 +48,13 @@ async function run() { core.endGroup(); } catch (error) { - core.setFailed(error.message); + core.setFailed("We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps. " + error.message); await util.reportActionFailed('autobuild', error.message, error.stack); return; } await util.reportActionSucceeded('autobuild'); } run().catch(e => { - core.setFailed("We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps. codeql/autobuild action failed. " + e); + core.setFailed("autobuild action failed. " + e); console.log(e); }); diff --git a/src/autobuild.ts b/src/autobuild.ts index 519ebb190..4dedb3343 100644 --- a/src/autobuild.ts +++ b/src/autobuild.ts @@ -49,7 +49,7 @@ async function run() { core.endGroup(); } catch (error) { - core.setFailed(error.message); + core.setFailed("We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps. " + error.message); await util.reportActionFailed('autobuild', error.message, error.stack); return; } @@ -58,6 +58,6 @@ async function run() { } run().catch(e => { - core.setFailed("We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps. codeql/autobuild action failed. " + e); + core.setFailed("autobuild action failed. " + e); console.log(e); });