diff --git a/CHANGELOG.md b/CHANGELOG.md index d88c371b49..c304506308 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - The `init` step of the Action now supports `ram` and `threads` inputs to limit resource use of CodeQL extractors. These inputs also serve as defaults to the subsequent `analyze` step, which finalizes the database and executes queries. [#738](https://github.com/github/codeql-action/pull/738) - When used with CodeQL 2.7.1 or above, the Action now includes custom query help in the analysis results uploaded to GitHub code scanning, if available. To add help text for a custom query, create a Markdown file next to the `.ql` file containing the query, using the same base name but the file extension `.md`. [#804](https://github.com/github/codeql-action/pull/804) +- The `upload-sarif` action now allows multiple uploads in a single job, as long as they have different categories. [#801](https://github.com/github/codeql-action/pull/801) ## 1.0.21 - 28 Oct 2021 diff --git a/lib/upload-lib.js b/lib/upload-lib.js index 1c88a190ea..ba39dedbe8 100644 --- a/lib/upload-lib.js +++ b/lib/upload-lib.js @@ -274,13 +274,26 @@ async function uploadFiles(sarifFiles, repositoryNwo, commitOid, ref, analysisKe function validateUniqueCategory(category) { if (util.isActions()) { // This check only works on actions as env vars don't persist between calls to the runner - const sentinelEnvVar = `CODEQL_UPLOAD_SARIF + ${category ? `_${category}` : ""}`; + const sentinelEnvVar = `CODEQL_UPLOAD_SARIF + ${category ? `_${sanitize(category)}` : ""}`; if (process.env[sentinelEnvVar]) { throw new Error("Aborting upload: only one run of the codeql/analyze or codeql/upload-sarif actions is allowed per job per category. " + - "Please specify a unique `category` to call this action multiple times."); + "Please specify a unique `category` to call this action multiple times. " + + `Category: ${category ? category : "(none)"}`); } core.exportVariable(sentinelEnvVar, sentinelEnvVar); } } exports.validateUniqueCategory = validateUniqueCategory; +/** + * Santizes a string to be used as an environment variable name. + * This will replace all non-alphanumeric characters with underscores. + * There could still be some false category clashes if two uploads + * occur that differ only in their non-alphanumeric characters. This is + * unlikely. + * + * @param str the initial value to sanitize + */ +function sanitize(str) { + return str.replace(/[^a-zA-Z0-9_]/g, "_"); +} //# sourceMappingURL=upload-lib.js.map \ No newline at end of file