2020-08-25 18:19:15 +03:00
|
|
|
"use strict";
|
2022-09-01 16:40:54 +03:00
|
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
|
|
}) : (function(o, m, k, k2) {
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
o[k2] = m[k];
|
|
|
|
}));
|
|
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
|
|
}) : function(o, v) {
|
|
|
|
o["default"] = v;
|
|
|
|
});
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
var result = {};
|
|
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
|
|
__setModuleDefault(result, mod);
|
|
|
|
return result;
|
|
|
|
};
|
2020-08-25 18:19:15 +03:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2022-09-12 19:18:39 +03:00
|
|
|
exports.runAutobuild = exports.determineAutobuildLanguages = void 0;
|
2020-08-25 18:19:15 +03:00
|
|
|
const codeql_1 = require("./codeql");
|
|
|
|
const languages_1 = require("./languages");
|
2022-09-01 16:40:54 +03:00
|
|
|
const util = __importStar(require("./util"));
|
2022-10-11 20:39:40 +03:00
|
|
|
async function determineAutobuildLanguages(config, featureEnablement, logger) {
|
|
|
|
const isGoExtractionReconciliationEnabled = await util.isGoExtractionReconciliationEnabled(featureEnablement);
|
2020-08-27 16:04:09 +03:00
|
|
|
// Attempt to find a language to autobuild
|
|
|
|
// 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.
|
2022-09-01 16:40:54 +03:00
|
|
|
const autobuildLanguages = config.languages.filter((l) => (0, languages_1.isTracedLanguage)(l, isGoExtractionReconciliationEnabled, logger));
|
2022-09-12 20:24:46 +03:00
|
|
|
if (!autobuildLanguages) {
|
2020-08-27 16:04:09 +03:00
|
|
|
logger.info("None of the languages in this project require extra build steps");
|
|
|
|
return undefined;
|
2020-08-25 18:19:15 +03:00
|
|
|
}
|
2022-09-12 20:24:46 +03:00
|
|
|
/**
|
|
|
|
* Additionally autobuild Go in the autobuild Action to ensure backwards
|
|
|
|
* compatibility for users performing a multi-language build within a single
|
|
|
|
* job.
|
|
|
|
*
|
|
|
|
* For example, consider a user with the following workflow file:
|
|
|
|
*
|
|
|
|
* ```yml
|
|
|
|
* - uses: github/codeql-action/init@v2
|
|
|
|
* with:
|
|
|
|
* languages: go, java
|
|
|
|
* - uses: github/codeql-action/autobuild@v2
|
|
|
|
* - uses: github/codeql-action/analyze@v2
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* - With Go extraction disabled, we will run the Java autobuilder in the
|
|
|
|
* autobuild Action, ensuring we extract both Java and Go code.
|
|
|
|
* - With Go extraction enabled, taking the previous behavior we'd run the Go
|
|
|
|
* autobuilder, since Go is first on the list of languages. We wouldn't run
|
|
|
|
* the Java autobuilder at all and so we'd only extract Go code.
|
|
|
|
*
|
|
|
|
* We therefore introduce a special case here such that we'll autobuild Go
|
|
|
|
* in addition to the primary non-Go traced language in the autobuild Action.
|
|
|
|
*
|
|
|
|
* This special case behavior should be removed as part of the next major
|
|
|
|
* version of the CodeQL Action.
|
|
|
|
*/
|
2022-09-13 18:50:41 +03:00
|
|
|
const autobuildLanguagesWithoutGo = autobuildLanguages.filter((l) => l !== languages_1.Language.go);
|
2022-09-12 20:24:46 +03:00
|
|
|
const languages = [];
|
|
|
|
// First run the autobuilder for the first non-Go traced language, if one
|
|
|
|
// exists.
|
2022-09-13 18:50:41 +03:00
|
|
|
if (autobuildLanguagesWithoutGo[0] !== undefined) {
|
|
|
|
languages.push(autobuildLanguagesWithoutGo[0]);
|
2022-09-12 20:24:46 +03:00
|
|
|
}
|
|
|
|
// If Go is requested, run the Go autobuilder last to ensure it doesn't
|
|
|
|
// interfere with the other autobuilder.
|
2022-09-13 18:50:41 +03:00
|
|
|
if (autobuildLanguages.length !== autobuildLanguagesWithoutGo.length) {
|
2022-09-12 20:24:46 +03:00
|
|
|
languages.push(languages_1.Language.go);
|
|
|
|
}
|
|
|
|
logger.debug(`Will autobuild ${languages.join(" and ")}.`);
|
2022-09-12 20:25:20 +03:00
|
|
|
// In general the autobuilders for other traced languages may conflict with
|
|
|
|
// each other. Therefore if a user has requested more than one non-Go traced
|
|
|
|
// language, we ask for manual build steps.
|
|
|
|
// Matrixing the build would also work, but that would change the SARIF
|
|
|
|
// categories, potentially leading to a "stale tips" situation where alerts
|
|
|
|
// that should be fixed remain on a repo since they are linked to SARIF
|
|
|
|
// categories that are no longer updated.
|
2022-09-13 18:50:41 +03:00
|
|
|
if (autobuildLanguagesWithoutGo.length > 1) {
|
|
|
|
logger.warning(`We will only automatically build ${languages.join(" and ")} code. If you wish to scan ${autobuildLanguagesWithoutGo
|
2020-09-14 12:44:43 +03:00
|
|
|
.slice(1)
|
2022-09-13 18:53:02 +03:00
|
|
|
.join(" and ")}, you must replace the autobuild step of your workflow with custom build steps. ` +
|
|
|
|
"For more information, see " +
|
|
|
|
"https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-the-codeql-workflow-for-compiled-languages#adding-build-steps-for-a-compiled-language");
|
2020-08-27 16:04:09 +03:00
|
|
|
}
|
2022-09-12 20:24:46 +03:00
|
|
|
return languages;
|
2020-08-27 16:04:09 +03:00
|
|
|
}
|
2022-09-12 19:18:39 +03:00
|
|
|
exports.determineAutobuildLanguages = determineAutobuildLanguages;
|
2020-08-27 16:04:09 +03:00
|
|
|
async function runAutobuild(language, config, logger) {
|
2020-08-25 18:19:15 +03:00
|
|
|
logger.startGroup(`Attempting to automatically build ${language} code`);
|
2021-09-10 23:53:13 +03:00
|
|
|
const codeQL = await (0, codeql_1.getCodeQL)(config.codeQLCmd);
|
2020-08-25 18:19:15 +03:00
|
|
|
await codeQL.runAutobuild(language);
|
|
|
|
logger.endGroup();
|
|
|
|
}
|
|
|
|
exports.runAutobuild = runAutobuild;
|
|
|
|
//# sourceMappingURL=autobuild.js.map
|