Merge pull request #2726 from github/aeisenberg/reenable-artifact-upload
Ensure artifacts are only uploaded in safe situations
This commit is contained in:
commit
b494190443
21 changed files with 300 additions and 60 deletions
|
|
@ -19,6 +19,14 @@ on:
|
||||||
workflow_dispatch: {}
|
workflow_dispatch: {}
|
||||||
jobs:
|
jobs:
|
||||||
upload-artifacts:
|
upload-artifacts:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
version:
|
||||||
|
- stable-v2.20.3
|
||||||
|
- default
|
||||||
|
- linked
|
||||||
|
- nightly-latest
|
||||||
name: Upload debug artifacts after failure in analyze
|
name: Upload debug artifacts after failure in analyze
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
env:
|
env:
|
||||||
|
|
@ -36,7 +44,7 @@ jobs:
|
||||||
id: prepare-test
|
id: prepare-test
|
||||||
uses: ./.github/actions/prepare-test
|
uses: ./.github/actions/prepare-test
|
||||||
with:
|
with:
|
||||||
version: linked
|
version: ${{ matrix.version }}
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: ^1.13.1
|
go-version: ^1.13.1
|
||||||
|
|
@ -70,22 +78,25 @@ jobs:
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
LANGUAGES="cpp csharp go java javascript python"
|
LANGUAGES="cpp csharp go java javascript python"
|
||||||
cd "./my-debug-artifacts"
|
for version in $VERSIONS; do
|
||||||
echo "Artifacts from run:"
|
echo "Artifacts from version $version:"
|
||||||
for language in $LANGUAGES; do
|
pushd "./my-debug-artifacts-${version//./}"
|
||||||
echo "- Checking $language"
|
for language in $LANGUAGES; do
|
||||||
if [[ ! -f "my-db-$language-partial.zip" ]] ; then
|
echo "- Checking $language"
|
||||||
echo "Missing a partial database bundle for $language"
|
if [[ ! -f "my-db-$language-partial.zip" ]] ; then
|
||||||
exit 1
|
echo "Missing a partial database bundle for $language"
|
||||||
fi
|
exit 1
|
||||||
if [[ ! -d "log" ]] ; then
|
fi
|
||||||
echo "Missing database initialization logs"
|
if [[ ! -d "log" ]] ; then
|
||||||
exit 1
|
echo "Missing database initialization logs"
|
||||||
fi
|
exit 1
|
||||||
if [[ ! "$language" == "go" ]] && [[ ! -d "$language/log" ]] ; then
|
fi
|
||||||
echo "Missing logs for $language"
|
if [[ ! "$language" == "go" ]] && [[ ! -d "$language/log" ]] ; then
|
||||||
exit 1
|
echo "Missing logs for $language"
|
||||||
fi
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
popd
|
||||||
done
|
done
|
||||||
env:
|
env:
|
||||||
GO111MODULE: auto
|
GO111MODULE: auto
|
||||||
|
|
@ -22,11 +22,7 @@ jobs:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
version:
|
version:
|
||||||
- stable-v2.15.5
|
- stable-v2.20.3
|
||||||
- stable-v2.16.6
|
|
||||||
- stable-v2.17.6
|
|
||||||
- stable-v2.18.4
|
|
||||||
- stable-v2.19.4
|
|
||||||
- default
|
- default
|
||||||
- linked
|
- linked
|
||||||
- nightly-latest
|
- nightly-latest
|
||||||
|
|
@ -75,7 +71,7 @@ jobs:
|
||||||
- name: Check expected artifacts exist
|
- name: Check expected artifacts exist
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
VERSIONS="stable-v2.15.5 stable-v2.16.6 stable-v2.17.6 stable-v2.18.4 stable-v2.19.4 default linked nightly-latest"
|
VERSIONS="stable-v2.20.3 default linked nightly-latest"
|
||||||
LANGUAGES="cpp csharp go java javascript python"
|
LANGUAGES="cpp csharp go java javascript python"
|
||||||
for version in $VERSIONS; do
|
for version in $VERSIONS; do
|
||||||
pushd "./my-debug-artifacts-${version//./}"
|
pushd "./my-debug-artifacts-${version//./}"
|
||||||
|
|
@ -4,7 +4,7 @@ See the [releases page](https://github.com/github/codeql-action/releases) for th
|
||||||
|
|
||||||
## [UNRELEASED]
|
## [UNRELEASED]
|
||||||
|
|
||||||
No user facing changes.
|
- Re-enable debug artifact upload for CLI versions 2.20.3 or greater. [#2726](https://github.com/github/codeql-action/pull/2726)
|
||||||
|
|
||||||
## 3.28.5 - 24 Jan 2025
|
## 3.28.5 - 24 Jan 2025
|
||||||
|
|
||||||
|
|
|
||||||
5
lib/analyze-action-post.js
generated
5
lib/analyze-action-post.js
generated
|
|
@ -41,6 +41,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const actionsUtil = __importStar(require("./actions-util"));
|
const actionsUtil = __importStar(require("./actions-util"));
|
||||||
const api_client_1 = require("./api-client");
|
const api_client_1 = require("./api-client");
|
||||||
|
const codeql_1 = require("./codeql");
|
||||||
const config_utils_1 = require("./config-utils");
|
const config_utils_1 = require("./config-utils");
|
||||||
const debugArtifacts = __importStar(require("./debug-artifacts"));
|
const debugArtifacts = __importStar(require("./debug-artifacts"));
|
||||||
const environment_1 = require("./environment");
|
const environment_1 = require("./environment");
|
||||||
|
|
@ -57,7 +58,9 @@ async function runWrapper() {
|
||||||
if (process.env[environment_1.EnvVar.INIT_ACTION_HAS_RUN] === "true") {
|
if (process.env[environment_1.EnvVar.INIT_ACTION_HAS_RUN] === "true") {
|
||||||
const config = await (0, config_utils_1.getConfig)(actionsUtil.getTemporaryDirectory(), logger);
|
const config = await (0, config_utils_1.getConfig)(actionsUtil.getTemporaryDirectory(), logger);
|
||||||
if (config !== undefined) {
|
if (config !== undefined) {
|
||||||
await (0, logging_1.withGroup)("Uploading combined SARIF debug artifact", () => debugArtifacts.uploadCombinedSarifArtifacts(logger, config.gitHubVersion.type));
|
const codeql = await (0, codeql_1.getCodeQL)(config.codeQLCmd);
|
||||||
|
const version = await codeql.getVersion();
|
||||||
|
await (0, logging_1.withGroup)("Uploading combined SARIF debug artifact", () => debugArtifacts.uploadCombinedSarifArtifacts(logger, config.gitHubVersion.type, version.version));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"analyze-action-post.js","sourceRoot":"","sources":["../src/analyze-action-post.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;GAIG;AACH,oDAAsC;AAEtC,4DAA8C;AAC9C,6CAAgD;AAChD,iDAA2C;AAC3C,kEAAoD;AACpD,+CAAuC;AACvC,uCAAwD;AACxD,iCAAoE;AAEpE,KAAK,UAAU,UAAU;IACvB,IAAI,CAAC;QACH,WAAW,CAAC,aAAa,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,IAAA,0BAAgB,GAAE,CAAC;QAClC,MAAM,aAAa,GAAG,MAAM,IAAA,6BAAgB,GAAE,CAAC;QAC/C,IAAA,gCAAyB,EAAC,aAAa,EAAE,MAAM,CAAC,CAAC;QAEjD,kFAAkF;QAClF,wFAAwF;QACxF,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAM,CAAC,mBAAmB,CAAC,KAAK,MAAM,EAAE,CAAC;YACvD,MAAM,MAAM,GAAG,MAAM,IAAA,wBAAS,EAC5B,WAAW,CAAC,qBAAqB,EAAE,EACnC,MAAM,CACP,CAAC;YACF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACzB,MAAM,IAAA,mBAAS,EAAC,yCAAyC,EAAE,GAAG,EAAE,CAC9D,cAAc,CAAC,4BAA4B,CACzC,MAAM,EACN,MAAM,CAAC,aAAa,CAAC,IAAI,CAC1B,CACF,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,SAAS,CACZ,oCAAoC,IAAA,sBAAe,EAAC,KAAK,CAAC,EAAE,CAC7D,CAAC;IACJ,CAAC;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC"}
|
{"version":3,"file":"analyze-action-post.js","sourceRoot":"","sources":["../src/analyze-action-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"}
|
||||||
24
lib/debug-artifacts.js
generated
24
lib/debug-artifacts.js
generated
|
|
@ -53,6 +53,7 @@ const analyze_1 = require("./analyze");
|
||||||
const codeql_1 = require("./codeql");
|
const codeql_1 = require("./codeql");
|
||||||
const environment_1 = require("./environment");
|
const environment_1 = require("./environment");
|
||||||
const logging_1 = require("./logging");
|
const logging_1 = require("./logging");
|
||||||
|
const tools_features_1 = require("./tools-features");
|
||||||
const util_1 = require("./util");
|
const util_1 = require("./util");
|
||||||
function sanitizeArtifactName(name) {
|
function sanitizeArtifactName(name) {
|
||||||
return name.replace(/[^a-zA-Z0-9_\\-]+/g, "");
|
return name.replace(/[^a-zA-Z0-9_\\-]+/g, "");
|
||||||
|
|
@ -61,7 +62,7 @@ function sanitizeArtifactName(name) {
|
||||||
* Upload Actions SARIF artifacts for debugging when CODEQL_ACTION_DEBUG_COMBINED_SARIF
|
* Upload Actions SARIF artifacts for debugging when CODEQL_ACTION_DEBUG_COMBINED_SARIF
|
||||||
* environment variable is set
|
* environment variable is set
|
||||||
*/
|
*/
|
||||||
async function uploadCombinedSarifArtifacts(logger, gitHubVariant) {
|
async function uploadCombinedSarifArtifacts(logger, gitHubVariant, codeQlVersion) {
|
||||||
const tempDir = (0, actions_util_1.getTemporaryDirectory)();
|
const tempDir = (0, actions_util_1.getTemporaryDirectory)();
|
||||||
// Upload Actions SARIF artifacts for debugging when environment variable is set
|
// Upload Actions SARIF artifacts for debugging when environment variable is set
|
||||||
if (process.env["CODEQL_ACTION_DEBUG_COMBINED_SARIF"] === "true") {
|
if (process.env["CODEQL_ACTION_DEBUG_COMBINED_SARIF"] === "true") {
|
||||||
|
|
@ -80,7 +81,7 @@ async function uploadCombinedSarifArtifacts(logger, gitHubVariant) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await uploadDebugArtifacts(logger, toUpload, baseTempDir, "combined-sarif-artifacts", gitHubVariant);
|
await uploadDebugArtifacts(logger, toUpload, baseTempDir, "combined-sarif-artifacts", gitHubVariant, codeQlVersion);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
logger.warning(`Failed to upload combined SARIF files as Actions debugging artifact. Reason: ${(0, util_1.getErrorMessage)(e)}`);
|
logger.warning(`Failed to upload combined SARIF files as Actions debugging artifact. Reason: ${(0, util_1.getErrorMessage)(e)}`);
|
||||||
|
|
@ -140,7 +141,7 @@ async function tryBundleDatabase(config, language, logger) {
|
||||||
*
|
*
|
||||||
* Logs and suppresses any errors that occur.
|
* Logs and suppresses any errors that occur.
|
||||||
*/
|
*/
|
||||||
async function tryUploadAllAvailableDebugArtifacts(config, logger) {
|
async function tryUploadAllAvailableDebugArtifacts(config, logger, codeQlVersion) {
|
||||||
const filesToUpload = [];
|
const filesToUpload = [];
|
||||||
try {
|
try {
|
||||||
for (const language of config.languages) {
|
for (const language of config.languages) {
|
||||||
|
|
@ -180,20 +181,23 @@ async function tryUploadAllAvailableDebugArtifacts(config, logger) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await (0, logging_1.withGroup)("Uploading debug artifacts", async () => uploadDebugArtifacts(logger, filesToUpload, config.dbLocation, config.debugArtifactName, config.gitHubVersion.type));
|
await (0, logging_1.withGroup)("Uploading debug artifacts", async () => uploadDebugArtifacts(logger, filesToUpload, config.dbLocation, config.debugArtifactName, config.gitHubVersion.type, codeQlVersion));
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
logger.warning(`Failed to upload debug artifacts. Reason: ${(0, util_1.getErrorMessage)(e)}`);
|
logger.warning(`Failed to upload debug artifacts. Reason: ${(0, util_1.getErrorMessage)(e)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function uploadDebugArtifacts(logger, toUpload, rootDir, artifactName, ghVariant) {
|
async function uploadDebugArtifacts(logger, toUpload, rootDir, artifactName, ghVariant, codeQlVersion) {
|
||||||
if (toUpload.length === 0) {
|
if (toUpload.length === 0) {
|
||||||
return;
|
return "no-artifacts-to-upload";
|
||||||
|
}
|
||||||
|
const uploadSupported = (0, tools_features_1.isSafeArtifactUpload)(codeQlVersion);
|
||||||
|
if (!uploadSupported) {
|
||||||
|
core.info(`Skipping debug artifact upload because the current CLI does not support safe upload. Please upgrade to CLI v${tools_features_1.SafeArtifactUploadVersion} or later.`);
|
||||||
|
return "upload-not-supported";
|
||||||
}
|
}
|
||||||
logger.info("Uploading debug artifacts is temporarily disabled");
|
|
||||||
return;
|
|
||||||
let suffix = "";
|
let suffix = "";
|
||||||
const matrix = (0, actions_util_1.getRequiredInput)("matrix");
|
const matrix = (0, actions_util_1.getOptionalInput)("matrix");
|
||||||
if (matrix) {
|
if (matrix) {
|
||||||
try {
|
try {
|
||||||
for (const [, matrixVal] of Object.entries(JSON.parse(matrix)).sort())
|
for (const [, matrixVal] of Object.entries(JSON.parse(matrix)).sort())
|
||||||
|
|
@ -209,10 +213,12 @@ async function uploadDebugArtifacts(logger, toUpload, rootDir, artifactName, ghV
|
||||||
// ensure we don't keep the debug artifacts around for too long since they can be large.
|
// ensure we don't keep the debug artifacts around for too long since they can be large.
|
||||||
retentionDays: 7,
|
retentionDays: 7,
|
||||||
});
|
});
|
||||||
|
return "upload-successful";
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
// A failure to upload debug artifacts should not fail the entire action.
|
// A failure to upload debug artifacts should not fail the entire action.
|
||||||
core.warning(`Failed to upload debug artifacts: ${e}`);
|
core.warning(`Failed to upload debug artifacts: ${e}`);
|
||||||
|
return "upload-failed";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// `@actions/artifact@v2` is not yet supported on GHES so the legacy version of the client will be used on GHES
|
// `@actions/artifact@v2` is not yet supported on GHES so the legacy version of the client will be used on GHES
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
42
lib/debug-artifacts.test.js
generated
42
lib/debug-artifacts.test.js
generated
|
|
@ -46,9 +46,47 @@ const util_1 = require("./util");
|
||||||
t.deepEqual(debugArtifacts.sanitizeArtifactName("hello===123"), "hello123");
|
t.deepEqual(debugArtifacts.sanitizeArtifactName("hello===123"), "hello123");
|
||||||
t.deepEqual(debugArtifacts.sanitizeArtifactName("*m)a&n^y%i££n+v!a:l[i]d"), "manyinvalid");
|
t.deepEqual(debugArtifacts.sanitizeArtifactName("*m)a&n^y%i££n+v!a:l[i]d"), "manyinvalid");
|
||||||
});
|
});
|
||||||
(0, ava_1.default)("uploadDebugArtifacts", async (t) => {
|
// These next tests check the correctness of the logic to determine whether or not
|
||||||
|
// artifacts are uploaded in debug mode. Since it's not easy to mock the actual
|
||||||
|
// call to upload an artifact, we just check that we get an "upload-failed" result,
|
||||||
|
// instead of actually uploading the artifact.
|
||||||
|
//
|
||||||
|
// For tests where we expect artifact upload to be blocked, we check for a different
|
||||||
|
// response from the function.
|
||||||
|
(0, ava_1.default)("uploadDebugArtifacts when artifacts empty should emit 'no-artifacts-to-upload'", async (t) => {
|
||||||
// Test that no error is thrown if artifacts list is empty.
|
// Test that no error is thrown if artifacts list is empty.
|
||||||
const logger = (0, logging_1.getActionsLogger)();
|
const logger = (0, logging_1.getActionsLogger)();
|
||||||
await t.notThrowsAsync(debugArtifacts.uploadDebugArtifacts(logger, [], "rootDir", "artifactName", util_1.GitHubVariant.DOTCOM));
|
await t.notThrowsAsync(async () => {
|
||||||
|
const uploaded = await debugArtifacts.uploadDebugArtifacts(logger, [], "i-dont-exist", "artifactName", util_1.GitHubVariant.DOTCOM, undefined);
|
||||||
|
t.is(uploaded, "no-artifacts-to-upload", "Should not have uploaded any artifacts");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
(0, ava_1.default)("uploadDebugArtifacts when no codeql version is used should invoke artifact upload", async (t) => {
|
||||||
|
// Test that the artifact is uploaded.
|
||||||
|
const logger = (0, logging_1.getActionsLogger)();
|
||||||
|
await t.notThrowsAsync(async () => {
|
||||||
|
const uploaded = await debugArtifacts.uploadDebugArtifacts(logger, ["hucairz"], "i-dont-exist", "artifactName", util_1.GitHubVariant.DOTCOM, undefined);
|
||||||
|
t.is(uploaded,
|
||||||
|
// The failure is expected since we don't want to actually upload any artifacts in unit tests.
|
||||||
|
"upload-failed", "Expect failure to upload artifacts since root dir does not exist");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
(0, ava_1.default)("uploadDebugArtifacts when new codeql version is used should invoke artifact upload", async (t) => {
|
||||||
|
// Test that the artifact is uploaded.
|
||||||
|
const logger = (0, logging_1.getActionsLogger)();
|
||||||
|
await t.notThrowsAsync(async () => {
|
||||||
|
const uploaded = await debugArtifacts.uploadDebugArtifacts(logger, ["hucairz"], "i-dont-exist", "artifactName", util_1.GitHubVariant.DOTCOM, "2.20.3");
|
||||||
|
t.is(uploaded,
|
||||||
|
// The failure is expected since we don't want to actually upload any artifacts in unit tests.
|
||||||
|
"upload-failed", "Expect failure to upload artifacts since root dir does not exist");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
(0, ava_1.default)("uploadDebugArtifacts when old codeql is used should avoid trying to upload artifacts", async (t) => {
|
||||||
|
// Test that the artifact is not uploaded.
|
||||||
|
const logger = (0, logging_1.getActionsLogger)();
|
||||||
|
await t.notThrowsAsync(async () => {
|
||||||
|
const uploaded = await debugArtifacts.uploadDebugArtifacts(logger, ["hucairz"], "i-dont-exist", "artifactName", util_1.GitHubVariant.DOTCOM, "2.20.2");
|
||||||
|
t.is(uploaded, "upload-not-supported", "Expected artifact upload to be blocked because of old CodeQL version");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
//# sourceMappingURL=debug-artifacts.test.js.map
|
//# sourceMappingURL=debug-artifacts.test.js.map
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"debug-artifacts.test.js","sourceRoot":"","sources":["../src/debug-artifacts.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAuB;AAEvB,kEAAoD;AACpD,uCAA6C;AAC7C,iCAAuC;AAEvC,IAAA,aAAI,E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E,EAAE;IACrG,sCAAsC;IACtC,MAAM,MAAM,GAAG,IAAA,0BAAgB,GAAE,CAAC;IAClC,MAAM,CAAC,CAAC,cAAc,CAAC,KAAK,IAAI,EAAE;QAChC,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,oBAAoB,CACxD,MAAM,EACN,CAAC,SAAS,CAAC,EACX,cAAc,EACd,cAAc,EACd,oBAAa,CAAC,MAAM,EACpB,QAAQ,CACT,CAAC;QACF,CAAC,CAAC,EAAE,CACF,QAAQ;QACR,8FAA8F;QAC9F,eAAe,EACf,kEAAkE,CACnE,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAA,aAAI,EAAC,sFAAsF,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IACvG,0CAA0C;IAC1C,MAAM,MAAM,GAAG,IAAA,0BAAgB,GAAE,CAAC;IAClC,MAAM,CAAC,CAAC,cAAc,CAAC,KAAK,IAAI,EAAE;QAChC,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,oBAAoB,CACxD,MAAM,EACN,CAAC,SAAS,CAAC,EACX,cAAc,EACd,cAAc,EACd,oBAAa,CAAC,MAAM,EACpB,QAAQ,CACT,CAAC;QACF,CAAC,CAAC,EAAE,CACF,QAAQ,EACR,sBAAsB,EACtB,sEAAsE,CACvE,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
||||||
4
lib/init-action-post-helper.js
generated
4
lib/init-action-post-helper.js
generated
|
|
@ -142,7 +142,9 @@ async function run(uploadAllAvailableDebugArtifacts, printDebugLogs, config, rep
|
||||||
// Upload appropriate Actions artifacts for debugging
|
// Upload appropriate Actions artifacts for debugging
|
||||||
if (config.debugMode) {
|
if (config.debugMode) {
|
||||||
logger.info("Debug mode is on. Uploading available database bundles and logs as Actions debugging artifacts...");
|
logger.info("Debug mode is on. Uploading available database bundles and logs as Actions debugging artifacts...");
|
||||||
await uploadAllAvailableDebugArtifacts(config, logger, features);
|
const codeql = await (0, codeql_1.getCodeQL)(config.codeQLCmd);
|
||||||
|
const version = await codeql.getVersion();
|
||||||
|
await uploadAllAvailableDebugArtifacts(config, logger, version.version);
|
||||||
await printDebugLogs(config);
|
await printDebugLogs(config);
|
||||||
}
|
}
|
||||||
if (actionsUtil.isSelfHostedRunner()) {
|
if (actionsUtil.isSelfHostedRunner()) {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
53
lib/tools-features.js
generated
53
lib/tools-features.js
generated
|
|
@ -1,7 +1,42 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (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 () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.ToolsFeature = void 0;
|
exports.SafeArtifactUploadVersion = exports.ToolsFeature = void 0;
|
||||||
exports.isSupportedToolsFeature = isSupportedToolsFeature;
|
exports.isSupportedToolsFeature = isSupportedToolsFeature;
|
||||||
|
exports.isSafeArtifactUpload = isSafeArtifactUpload;
|
||||||
|
const semver = __importStar(require("semver"));
|
||||||
var ToolsFeature;
|
var ToolsFeature;
|
||||||
(function (ToolsFeature) {
|
(function (ToolsFeature) {
|
||||||
ToolsFeature["AnalysisSummaryV2IsDefault"] = "analysisSummaryV2Default";
|
ToolsFeature["AnalysisSummaryV2IsDefault"] = "analysisSummaryV2Default";
|
||||||
|
|
@ -25,4 +60,20 @@ var ToolsFeature;
|
||||||
function isSupportedToolsFeature(versionInfo, feature) {
|
function isSupportedToolsFeature(versionInfo, feature) {
|
||||||
return !!versionInfo.features && versionInfo.features[feature];
|
return !!versionInfo.features && versionInfo.features[feature];
|
||||||
}
|
}
|
||||||
|
exports.SafeArtifactUploadVersion = "2.20.3";
|
||||||
|
/**
|
||||||
|
* The first version of the CodeQL CLI where artifact upload is safe to use
|
||||||
|
* for failed runs. This is not really a feature flag, but it is easiest to
|
||||||
|
* model the behavior as a feature flag.
|
||||||
|
*
|
||||||
|
* This was not captured in a tools feature, so we need to use semver.
|
||||||
|
*
|
||||||
|
* @param codeQlVersion The version of the CodeQL CLI to check. If not provided, it is assumed to be safe.
|
||||||
|
* @returns True if artifact upload is safe to use for failed runs or false otherwise.
|
||||||
|
*/
|
||||||
|
function isSafeArtifactUpload(codeQlVersion) {
|
||||||
|
return !codeQlVersion
|
||||||
|
? true
|
||||||
|
: semver.gte(codeQlVersion, exports.SafeArtifactUploadVersion);
|
||||||
|
}
|
||||||
//# sourceMappingURL=tools-features.js.map
|
//# sourceMappingURL=tools-features.js.map
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"tools-features.js","sourceRoot":"","sources":["../src/tools-features.ts"],"names":[],"mappings":";;;AAsBA,0DAKC;AAzBD,IAAY,YAWX;AAXD,WAAY,YAAY;IACtB,uEAAuD,CAAA;IACvD,mDAAmC,CAAA;IACnC,qHAAqG,CAAA;IACrG,+FAA+E,CAAA;IAC/E,yFAAyE,CAAA;IACzE,iEAAiD,CAAA;IACjD,qEAAqD,CAAA;IACrD,mFAAmE,CAAA;IACnE,iDAAiC,CAAA;IACjC,uFAAuE,CAAA;AACzE,CAAC,EAXW,YAAY,4BAAZ,YAAY,QAWvB;AAED;;;;;;GAMG;AACH,SAAgB,uBAAuB,CACrC,WAAwB,EACxB,OAAqB;IAErB,OAAO,CAAC,CAAC,WAAW,CAAC,QAAQ,IAAI,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACjE,CAAC"}
|
{"version":3,"file":"tools-features.js","sourceRoot":"","sources":["../src/tools-features.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,0DAKC;AAcD,oDAIC;AA/CD,+CAAiC;AAIjC,IAAY,YAWX;AAXD,WAAY,YAAY;IACtB,uEAAuD,CAAA;IACvD,mDAAmC,CAAA;IACnC,qHAAqG,CAAA;IACrG,+FAA+E,CAAA;IAC/E,yFAAyE,CAAA;IACzE,iEAAiD,CAAA;IACjD,qEAAqD,CAAA;IACrD,mFAAmE,CAAA;IACnE,iDAAiC,CAAA;IACjC,uFAAuE,CAAA;AACzE,CAAC,EAXW,YAAY,4BAAZ,YAAY,QAWvB;AAED;;;;;;GAMG;AACH,SAAgB,uBAAuB,CACrC,WAAwB,EACxB,OAAqB;IAErB,OAAO,CAAC,CAAC,WAAW,CAAC,QAAQ,IAAI,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACjE,CAAC;AAEY,QAAA,yBAAyB,GAAG,QAAQ,CAAC;AAElD;;;;;;;;;GASG;AACH,SAAgB,oBAAoB,CAAC,aAAsB;IACzD,OAAO,CAAC,aAAa;QACnB,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,EAAE,iCAAyB,CAAC,CAAC;AAC3D,CAAC"}
|
||||||
5
lib/upload-sarif-action-post.js
generated
5
lib/upload-sarif-action-post.js
generated
|
|
@ -59,7 +59,10 @@ async function runWrapper() {
|
||||||
core.warning(`Did not upload debug artifacts because cannot determine the GitHub variant running.`);
|
core.warning(`Did not upload debug artifacts because cannot determine the GitHub variant running.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await (0, logging_1.withGroup)("Uploading combined SARIF debug artifact", () => debugArtifacts.uploadCombinedSarifArtifacts(logger, gitHubVersion.type));
|
await (0, logging_1.withGroup)("Uploading combined SARIF debug artifact", () => debugArtifacts.uploadCombinedSarifArtifacts(logger, gitHubVersion.type,
|
||||||
|
// The codeqlVersion is not applicable for uploading non-codeql sarif.
|
||||||
|
// We can assume all versions are safe to upload.
|
||||||
|
undefined));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"upload-sarif-action-post.js","sourceRoot":"","sources":["../src/upload-sarif-action-post.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;GAIG;AACH,oDAAsC;AAEtC,4DAA8C;AAC9C,6CAAgD;AAChD,kEAAoD;AACpD,+CAAuC;AACvC,uCAAwD;AACxD,iCAAoE;AAEpE,KAAK,UAAU,UAAU;IACvB,IAAI,CAAC;QACH,6CAA6C;QAC7C,WAAW,CAAC,aAAa,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,IAAA,0BAAgB,GAAE,CAAC;QAClC,MAAM,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,GAAG,CAAC,oBAAM,CAAC,mBAAmB,CAAC,KAAK,MAAM,EAAE,CAAC;YACvD,IAAI,aAAa,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBACrC,IAAI,CAAC,OAAO,CACV,qFAAqF,CACtF,CAAC;gBACF,OAAO;YACT,CAAC;YACD,MAAM,IAAA,mBAAS,EAAC,yCAAyC,EAAE,GAAG,EAAE,CAC9D,cAAc,CAAC,4BAA4B,CACzC,MAAM,EACN,aAAa,CAAC,IAAI;YAClB,sEAAsE;YACtE,iDAAiD;YACjD,SAAS,CACV,CACF,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,SAAS,CACZ,yCAAyC,IAAA,sBAAe,EAAC,KAAK,CAAC,EAAE,CAClE,CAAC;IACJ,CAAC;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC"}
|
||||||
|
|
@ -7,6 +7,7 @@ import * as core from "@actions/core";
|
||||||
|
|
||||||
import * as actionsUtil from "./actions-util";
|
import * as actionsUtil from "./actions-util";
|
||||||
import { getGitHubVersion } from "./api-client";
|
import { getGitHubVersion } from "./api-client";
|
||||||
|
import { getCodeQL } from "./codeql";
|
||||||
import { getConfig } from "./config-utils";
|
import { getConfig } from "./config-utils";
|
||||||
import * as debugArtifacts from "./debug-artifacts";
|
import * as debugArtifacts from "./debug-artifacts";
|
||||||
import { EnvVar } from "./environment";
|
import { EnvVar } from "./environment";
|
||||||
|
|
@ -28,10 +29,13 @@ async function runWrapper() {
|
||||||
logger,
|
logger,
|
||||||
);
|
);
|
||||||
if (config !== undefined) {
|
if (config !== undefined) {
|
||||||
|
const codeql = await getCodeQL(config.codeQLCmd);
|
||||||
|
const version = await codeql.getVersion();
|
||||||
await withGroup("Uploading combined SARIF debug artifact", () =>
|
await withGroup("Uploading combined SARIF debug artifact", () =>
|
||||||
debugArtifacts.uploadCombinedSarifArtifacts(
|
debugArtifacts.uploadCombinedSarifArtifacts(
|
||||||
logger,
|
logger,
|
||||||
config.gitHubVersion.type,
|
config.gitHubVersion.type,
|
||||||
|
version.version,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,16 +20,92 @@ test("sanitizeArtifactName", (t) => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("uploadDebugArtifacts", async (t) => {
|
// These next tests check the correctness of the logic to determine whether or not
|
||||||
|
// artifacts are uploaded in debug mode. Since it's not easy to mock the actual
|
||||||
|
// call to upload an artifact, we just check that we get an "upload-failed" result,
|
||||||
|
// instead of actually uploading the artifact.
|
||||||
|
//
|
||||||
|
// For tests where we expect artifact upload to be blocked, we check for a different
|
||||||
|
// response from the function.
|
||||||
|
|
||||||
|
test("uploadDebugArtifacts when artifacts empty should emit 'no-artifacts-to-upload'", async (t) => {
|
||||||
// Test that no error is thrown if artifacts list is empty.
|
// Test that no error is thrown if artifacts list is empty.
|
||||||
const logger = getActionsLogger();
|
const logger = getActionsLogger();
|
||||||
await t.notThrowsAsync(
|
await t.notThrowsAsync(async () => {
|
||||||
debugArtifacts.uploadDebugArtifacts(
|
const uploaded = await debugArtifacts.uploadDebugArtifacts(
|
||||||
logger,
|
logger,
|
||||||
[],
|
[],
|
||||||
"rootDir",
|
"i-dont-exist",
|
||||||
"artifactName",
|
"artifactName",
|
||||||
GitHubVariant.DOTCOM,
|
GitHubVariant.DOTCOM,
|
||||||
),
|
undefined,
|
||||||
);
|
);
|
||||||
|
t.is(
|
||||||
|
uploaded,
|
||||||
|
"no-artifacts-to-upload",
|
||||||
|
"Should not have uploaded any artifacts",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("uploadDebugArtifacts when no codeql version is used should invoke artifact upload", async (t) => {
|
||||||
|
// Test that the artifact is uploaded.
|
||||||
|
const logger = getActionsLogger();
|
||||||
|
await t.notThrowsAsync(async () => {
|
||||||
|
const uploaded = await debugArtifacts.uploadDebugArtifacts(
|
||||||
|
logger,
|
||||||
|
["hucairz"],
|
||||||
|
"i-dont-exist",
|
||||||
|
"artifactName",
|
||||||
|
GitHubVariant.DOTCOM,
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
t.is(
|
||||||
|
uploaded,
|
||||||
|
// The failure is expected since we don't want to actually upload any artifacts in unit tests.
|
||||||
|
"upload-failed",
|
||||||
|
"Expect failure to upload artifacts since root dir does not exist",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("uploadDebugArtifacts when new codeql version is used should invoke artifact upload", async (t) => {
|
||||||
|
// Test that the artifact is uploaded.
|
||||||
|
const logger = getActionsLogger();
|
||||||
|
await t.notThrowsAsync(async () => {
|
||||||
|
const uploaded = await debugArtifacts.uploadDebugArtifacts(
|
||||||
|
logger,
|
||||||
|
["hucairz"],
|
||||||
|
"i-dont-exist",
|
||||||
|
"artifactName",
|
||||||
|
GitHubVariant.DOTCOM,
|
||||||
|
"2.20.3",
|
||||||
|
);
|
||||||
|
t.is(
|
||||||
|
uploaded,
|
||||||
|
// The failure is expected since we don't want to actually upload any artifacts in unit tests.
|
||||||
|
"upload-failed",
|
||||||
|
"Expect failure to upload artifacts since root dir does not exist",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("uploadDebugArtifacts when old codeql is used should avoid trying to upload artifacts", async (t) => {
|
||||||
|
// Test that the artifact is not uploaded.
|
||||||
|
const logger = getActionsLogger();
|
||||||
|
await t.notThrowsAsync(async () => {
|
||||||
|
const uploaded = await debugArtifacts.uploadDebugArtifacts(
|
||||||
|
logger,
|
||||||
|
["hucairz"],
|
||||||
|
"i-dont-exist",
|
||||||
|
"artifactName",
|
||||||
|
GitHubVariant.DOTCOM,
|
||||||
|
"2.20.2",
|
||||||
|
);
|
||||||
|
t.is(
|
||||||
|
uploaded,
|
||||||
|
"upload-not-supported",
|
||||||
|
"Expected artifact upload to be blocked because of old CodeQL version",
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,17 @@ import * as core from "@actions/core";
|
||||||
import AdmZip from "adm-zip";
|
import AdmZip from "adm-zip";
|
||||||
import del from "del";
|
import del from "del";
|
||||||
|
|
||||||
import { getRequiredInput, getTemporaryDirectory } from "./actions-util";
|
import { getOptionalInput, getTemporaryDirectory } from "./actions-util";
|
||||||
import { dbIsFinalized } from "./analyze";
|
import { dbIsFinalized } from "./analyze";
|
||||||
import { getCodeQL } from "./codeql";
|
import { getCodeQL } from "./codeql";
|
||||||
import { Config } from "./config-utils";
|
import { Config } from "./config-utils";
|
||||||
import { EnvVar } from "./environment";
|
import { EnvVar } from "./environment";
|
||||||
import { Language } from "./languages";
|
import { Language } from "./languages";
|
||||||
import { Logger, withGroup } from "./logging";
|
import { Logger, withGroup } from "./logging";
|
||||||
|
import {
|
||||||
|
isSafeArtifactUpload,
|
||||||
|
SafeArtifactUploadVersion,
|
||||||
|
} from "./tools-features";
|
||||||
import {
|
import {
|
||||||
bundleDb,
|
bundleDb,
|
||||||
doesDirectoryExist,
|
doesDirectoryExist,
|
||||||
|
|
@ -34,6 +38,7 @@ export function sanitizeArtifactName(name: string): string {
|
||||||
export async function uploadCombinedSarifArtifacts(
|
export async function uploadCombinedSarifArtifacts(
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
gitHubVariant: GitHubVariant,
|
gitHubVariant: GitHubVariant,
|
||||||
|
codeQlVersion: string | undefined,
|
||||||
) {
|
) {
|
||||||
const tempDir = getTemporaryDirectory();
|
const tempDir = getTemporaryDirectory();
|
||||||
|
|
||||||
|
|
@ -68,6 +73,7 @@ export async function uploadCombinedSarifArtifacts(
|
||||||
baseTempDir,
|
baseTempDir,
|
||||||
"combined-sarif-artifacts",
|
"combined-sarif-artifacts",
|
||||||
gitHubVariant,
|
gitHubVariant,
|
||||||
|
codeQlVersion,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.warning(
|
logger.warning(
|
||||||
|
|
@ -160,6 +166,7 @@ async function tryBundleDatabase(
|
||||||
export async function tryUploadAllAvailableDebugArtifacts(
|
export async function tryUploadAllAvailableDebugArtifacts(
|
||||||
config: Config,
|
config: Config,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
|
codeQlVersion: string | undefined,
|
||||||
) {
|
) {
|
||||||
const filesToUpload: string[] = [];
|
const filesToUpload: string[] = [];
|
||||||
try {
|
try {
|
||||||
|
|
@ -223,6 +230,7 @@ export async function tryUploadAllAvailableDebugArtifacts(
|
||||||
config.dbLocation,
|
config.dbLocation,
|
||||||
config.debugArtifactName,
|
config.debugArtifactName,
|
||||||
config.gitHubVersion.type,
|
config.gitHubVersion.type,
|
||||||
|
codeQlVersion,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -238,15 +246,27 @@ export async function uploadDebugArtifacts(
|
||||||
rootDir: string,
|
rootDir: string,
|
||||||
artifactName: string,
|
artifactName: string,
|
||||||
ghVariant: GitHubVariant,
|
ghVariant: GitHubVariant,
|
||||||
) {
|
codeQlVersion: string | undefined,
|
||||||
|
): Promise<
|
||||||
|
| "no-artifacts-to-upload"
|
||||||
|
| "upload-successful"
|
||||||
|
| "upload-failed"
|
||||||
|
| "upload-not-supported"
|
||||||
|
> {
|
||||||
if (toUpload.length === 0) {
|
if (toUpload.length === 0) {
|
||||||
return;
|
return "no-artifacts-to-upload";
|
||||||
|
}
|
||||||
|
const uploadSupported = isSafeArtifactUpload(codeQlVersion);
|
||||||
|
|
||||||
|
if (!uploadSupported) {
|
||||||
|
core.info(
|
||||||
|
`Skipping debug artifact upload because the current CLI does not support safe upload. Please upgrade to CLI v${SafeArtifactUploadVersion} or later.`,
|
||||||
|
);
|
||||||
|
return "upload-not-supported";
|
||||||
}
|
}
|
||||||
logger.info("Uploading debug artifacts is temporarily disabled");
|
|
||||||
return;
|
|
||||||
|
|
||||||
let suffix = "";
|
let suffix = "";
|
||||||
const matrix = getRequiredInput("matrix");
|
const matrix = getOptionalInput("matrix");
|
||||||
if (matrix) {
|
if (matrix) {
|
||||||
try {
|
try {
|
||||||
for (const [, matrixVal] of Object.entries(
|
for (const [, matrixVal] of Object.entries(
|
||||||
|
|
@ -272,9 +292,11 @@ export async function uploadDebugArtifacts(
|
||||||
retentionDays: 7,
|
retentionDays: 7,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
return "upload-successful";
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// A failure to upload debug artifacts should not fail the entire action.
|
// A failure to upload debug artifacts should not fail the entire action.
|
||||||
core.warning(`Failed to upload debug artifacts: ${e}`);
|
core.warning(`Failed to upload debug artifacts: ${e}`);
|
||||||
|
return "upload-failed";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,7 @@ export async function run(
|
||||||
uploadAllAvailableDebugArtifacts: (
|
uploadAllAvailableDebugArtifacts: (
|
||||||
config: Config,
|
config: Config,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
features: FeatureEnablement,
|
codeQlVersion: string,
|
||||||
) => Promise<void>,
|
) => Promise<void>,
|
||||||
printDebugLogs: (config: Config) => Promise<void>,
|
printDebugLogs: (config: Config) => Promise<void>,
|
||||||
config: Config,
|
config: Config,
|
||||||
|
|
@ -211,7 +211,9 @@ export async function run(
|
||||||
logger.info(
|
logger.info(
|
||||||
"Debug mode is on. Uploading available database bundles and logs as Actions debugging artifacts...",
|
"Debug mode is on. Uploading available database bundles and logs as Actions debugging artifacts...",
|
||||||
);
|
);
|
||||||
await uploadAllAvailableDebugArtifacts(config, logger, features);
|
const codeql = await getCodeQL(config.codeQLCmd);
|
||||||
|
const version = await codeql.getVersion();
|
||||||
|
await uploadAllAvailableDebugArtifacts(config, logger, version.version);
|
||||||
await printDebugLogs(config);
|
await printDebugLogs(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import * as semver from "semver";
|
||||||
|
|
||||||
import type { VersionInfo } from "./codeql";
|
import type { VersionInfo } from "./codeql";
|
||||||
|
|
||||||
export enum ToolsFeature {
|
export enum ToolsFeature {
|
||||||
|
|
@ -26,3 +28,21 @@ export function isSupportedToolsFeature(
|
||||||
): boolean {
|
): boolean {
|
||||||
return !!versionInfo.features && versionInfo.features[feature];
|
return !!versionInfo.features && versionInfo.features[feature];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const SafeArtifactUploadVersion = "2.20.3";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The first version of the CodeQL CLI where artifact upload is safe to use
|
||||||
|
* for failed runs. This is not really a feature flag, but it is easiest to
|
||||||
|
* model the behavior as a feature flag.
|
||||||
|
*
|
||||||
|
* This was not captured in a tools feature, so we need to use semver.
|
||||||
|
*
|
||||||
|
* @param codeQlVersion The version of the CodeQL CLI to check. If not provided, it is assumed to be safe.
|
||||||
|
* @returns True if artifact upload is safe to use for failed runs or false otherwise.
|
||||||
|
*/
|
||||||
|
export function isSafeArtifactUpload(codeQlVersion?: string): boolean {
|
||||||
|
return !codeQlVersion
|
||||||
|
? true
|
||||||
|
: semver.gte(codeQlVersion, SafeArtifactUploadVersion);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,13 @@ async function runWrapper() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await withGroup("Uploading combined SARIF debug artifact", () =>
|
await withGroup("Uploading combined SARIF debug artifact", () =>
|
||||||
debugArtifacts.uploadCombinedSarifArtifacts(logger, gitHubVersion.type),
|
debugArtifacts.uploadCombinedSarifArtifacts(
|
||||||
|
logger,
|
||||||
|
gitHubVersion.type,
|
||||||
|
// The codeqlVersion is not applicable for uploading non-codeql sarif.
|
||||||
|
// We can assume all versions are safe to upload.
|
||||||
|
undefined,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue