Compare commits

...

15 Commits

Author SHA1 Message Date
Henry Mercer bb28e7e59e Merge pull request #1626 from github/henrymercer/diagnostics-ghes
Enable diagnostics functionality on GHES
2023-03-30 10:22:39 +01:00
Henry Mercer 69aec345f1 Pass negative SARIF include diagnostics flag when feature is disabled
In preparation for enabling this flag by default in the CLI
2023-03-29 18:56:19 +01:00
Henry Mercer 29a4713933 Enable diagnostics functionality on GHES 2023-03-29 18:45:27 +01:00
Robin Neatherway dc81ae3368 Merge pull request #1625 from github/rneatherway/rm-old-checks
Remove checks for triggering on specific paths
2023-03-29 13:28:57 +01:00
Robin Neatherway f6e4cff38a Remove checks for triggering on specific paths
These are no longer necessary with the new approach to selecting
alerts to show on pull requests.
2023-03-29 11:02:16 +02:00
Henry Mercer fff3a80b5b Merge pull request #1620 from github/henrymercer/disable-flaky-check
Disable flaky Swift autobuild checks
2023-03-28 21:01:11 +01:00
Henry Mercer ff39eb8d6a Disable flaky Swift autobuild checks 2023-03-28 20:40:23 +01:00
Andrew Eisenberg f9c159f4fd Merge pull request #1613 from github/aeisenberg/codeql-testing
Use new location for external queries
2023-03-27 17:35:01 -07:00
Andrew Eisenberg 0af0653ef4 Use new location for external queries
They have moved from `dsp-testing` to `codeql-testing`.
2023-03-27 16:11:45 -07:00
Henry Mercer bc0ed6a6c3 Merge pull request #1610 from github/henrymercer/diagnostics-workaround-improvements
Follow-up improvements to the diagnostics workaround
2023-03-27 17:12:07 +01:00
Henry Mercer b0e191ecbc Merge pull request #1609 from github/mergeback/v2.2.9-to-main-04df1262
Mergeback v2.2.9 refs/heads/releases/v2 into main
2023-03-27 16:42:07 +01:00
Henry Mercer 57eca7cbb2 Use Array.isArray 2023-03-27 15:59:29 +01:00
Henry Mercer 1e7a38893c Wrap reading and writing SARIF files 2023-03-27 15:44:47 +01:00
github-actions[bot] 2deae45400 Update checked-in dependencies 2023-03-27 14:03:17 +00:00
github-actions[bot] 32daed70e7 Update changelog and version after v2.2.9 2023-03-27 13:41:15 +00:00
22 changed files with 76 additions and 214 deletions
-72
View File
@@ -1,72 +0,0 @@
# Warning: This file is generated automatically, and should not be modified.
# Instead, please modify the template in the pr-checks directory and run:
# pip install ruamel.yaml && python3 sync.py
# to regenerate this file.
name: PR Check - Swift analysis using autobuild
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GO111MODULE: auto
CODEQL_EXTRACTOR_JAVA_AGENT_DISABLE_KOTLIN: 'true'
on:
push:
branches:
- main
- releases/v2
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
workflow_dispatch: {}
jobs:
swift-autobuild:
strategy:
matrix:
include:
- os: macos-latest
version: latest
- os: macos-latest
version: cached
- os: macos-latest
version: nightly-latest
name: Swift analysis using autobuild
timeout-minutes: 45
runs-on: ${{ matrix.os }}
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Prepare test
id: prepare-test
uses: ./.github/prepare-test
with:
version: ${{ matrix.version }}
- uses: ./../action/init
id: init
with:
languages: swift
tools: ${{ steps.prepare-test.outputs.tools-url }}
- uses: ./../action/.github/setup-swift
with:
codeql-path: ${{steps.init.outputs.codeql-path}}
- name: Check working directory
shell: bash
run: pwd
- uses: ./../action/autobuild
timeout-minutes: 10
- uses: ./../action/analyze
id: analysis
with:
upload-database: false
- name: Check database
shell: bash
run: |
SWIFT_DB="${{ fromJson(steps.analysis.outputs.db-locations).swift }}"
if [[ ! -d "$SWIFT_DB" ]]; then
echo "Did not create a database for Swift."
exit 1
fi
env:
CODEQL_ENABLE_EXPERIMENTAL_FEATURES_SWIFT: 'true' # Remove when Swift is GA.
CODEQL_ACTION_TEST_MODE: true
+4
View File
@@ -1,5 +1,9 @@
# CodeQL Action Changelog # CodeQL Action Changelog
## [UNRELEASED]
No user facing changes.
## 2.2.9 - 27 Mar 2023 ## 2.2.9 - 27 Mar 2023
- Customers post-processing the SARIF output of the `analyze` Action before uploading it to Code Scanning will benefit from an improved debugging experience. [#1598](https://github.com/github/codeql-action/pull/1598) - Customers post-processing the SARIF output of the `analyze` Action before uploading it to Code Scanning will benefit from an improved debugging experience. [#1598](https://github.com/github/codeql-action/pull/1598)
Generated
+5 -6
View File
@@ -537,6 +537,9 @@ async function getCodeQLForCmd(cmd, checkVersion) {
if (shouldExportDiagnostics) { if (shouldExportDiagnostics) {
codeqlArgs.push("--sarif-include-diagnostics"); codeqlArgs.push("--sarif-include-diagnostics");
} }
else if (await util.codeQlVersionAbove(this, "2.12.4")) {
codeqlArgs.push("--no-sarif-include-diagnostics");
}
codeqlArgs.push(databasePath); codeqlArgs.push(databasePath);
if (querySuitePaths) { if (querySuitePaths) {
codeqlArgs.push(...querySuitePaths); codeqlArgs.push(...querySuitePaths);
@@ -544,9 +547,7 @@ async function getCodeQLForCmd(cmd, checkVersion) {
// capture stdout, which contains analysis summaries // capture stdout, which contains analysis summaries
const returnState = await (0, toolrunner_error_catcher_1.toolrunnerErrorCatcher)(cmd, codeqlArgs, error_matcher_1.errorMatchers); const returnState = await (0, toolrunner_error_catcher_1.toolrunnerErrorCatcher)(cmd, codeqlArgs, error_matcher_1.errorMatchers);
if (shouldExportDiagnostics) { if (shouldExportDiagnostics) {
let sarif = JSON.parse(fs.readFileSync(codeqlOutputFile, "utf8")); util.fixInvalidNotificationsInFile(codeqlOutputFile, sarifFile, logger);
sarif = util.fixInvalidNotifications(sarif, logger);
fs.writeFileSync(sarifFile, JSON.stringify(sarif));
} }
return returnState.stdout; return returnState.stdout;
}, },
@@ -642,9 +643,7 @@ async function getCodeQLForCmd(cmd, checkVersion) {
} }
await new toolrunner.ToolRunner(cmd, args).exec(); await new toolrunner.ToolRunner(cmd, args).exec();
// Fix invalid notifications in the SARIF file output by CodeQL. // Fix invalid notifications in the SARIF file output by CodeQL.
let sarif = JSON.parse(fs.readFileSync(intermediateSarifFile, "utf8")); util.fixInvalidNotificationsInFile(intermediateSarifFile, sarifFile, logger);
sarif = util.fixInvalidNotifications(sarif, logger);
fs.writeFileSync(sarifFile, JSON.stringify(sarif));
}, },
async diagnosticsExport(sarifFile, automationDetailsId, config, features) { async diagnosticsExport(sarifFile, automationDetailsId, config, features) {
const args = [ const args = [
+1 -1
View File
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -55,12 +55,12 @@ exports.featureConfig = {
[Feature.ExportCodeScanningConfigEnabled]: { [Feature.ExportCodeScanningConfigEnabled]: {
envVar: "CODEQL_ACTION_EXPORT_CODE_SCANNING_CONFIG", envVar: "CODEQL_ACTION_EXPORT_CODE_SCANNING_CONFIG",
minimumVersion: "2.12.3", minimumVersion: "2.12.3",
defaultValue: false, defaultValue: true,
}, },
[Feature.ExportDiagnosticsEnabled]: { [Feature.ExportDiagnosticsEnabled]: {
envVar: "CODEQL_ACTION_EXPORT_DIAGNOSTICS", envVar: "CODEQL_ACTION_EXPORT_DIAGNOSTICS",
minimumVersion: "2.12.4", minimumVersion: "2.12.4",
defaultValue: false, defaultValue: true,
}, },
[Feature.MlPoweredQueriesEnabled]: { [Feature.MlPoweredQueriesEnabled]: {
envVar: "CODEQL_ML_POWERED_QUERIES", envVar: "CODEQL_ML_POWERED_QUERIES",
@@ -70,7 +70,7 @@ exports.featureConfig = {
[Feature.UploadFailedSarifEnabled]: { [Feature.UploadFailedSarifEnabled]: {
envVar: "CODEQL_ACTION_UPLOAD_FAILED_SARIF", envVar: "CODEQL_ACTION_UPLOAD_FAILED_SARIF",
minimumVersion: "2.11.3", minimumVersion: "2.11.3",
defaultValue: false, defaultValue: true,
}, },
}; };
exports.FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json"; exports.FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json";
File diff suppressed because one or more lines are too long
Generated
+11 -5
View File
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.fixInvalidNotifications = exports.parseMatrixInput = exports.isHostedRunner = exports.checkForTimeout = exports.withTimeout = exports.tryGetFolderBytes = exports.listFolder = exports.doesDirectoryExist = exports.logCodeScanningConfigInCli = exports.useCodeScanningConfigInCli = exports.isInTestMode = exports.getMlPoweredJsQueriesStatus = exports.getMlPoweredJsQueriesPack = exports.ML_POWERED_JS_QUERIES_PACK_NAME = exports.supportExpectDiscardedCache = exports.isGoodVersion = exports.delay = exports.bundleDb = exports.codeQlVersionAbove = exports.getCachedCodeQlVersion = exports.cacheCodeQlVersion = exports.isHTTPError = exports.UserError = exports.HTTPError = exports.getRequiredEnvParam = exports.initializeEnvironment = exports.assertNever = exports.apiVersionInRange = exports.DisallowedAPIVersionReason = exports.checkGitHubVersionInRange = exports.getGitHubVersion = exports.GitHubVariant = exports.parseGitHubUrl = exports.getCodeQLDatabasePath = exports.getThreadsFlag = exports.getThreadsFlagValue = exports.getAddSnippetsFlag = exports.getMemoryFlag = exports.getMemoryFlagValue = exports.withTmpDir = exports.getToolNames = exports.getExtraOptionsEnvParam = exports.DEFAULT_DEBUG_DATABASE_NAME = exports.DEFAULT_DEBUG_ARTIFACT_NAME = exports.GITHUB_DOTCOM_URL = void 0; exports.fixInvalidNotificationsInFile = exports.fixInvalidNotifications = exports.parseMatrixInput = exports.isHostedRunner = exports.checkForTimeout = exports.withTimeout = exports.tryGetFolderBytes = exports.listFolder = exports.doesDirectoryExist = exports.logCodeScanningConfigInCli = exports.useCodeScanningConfigInCli = exports.isInTestMode = exports.getMlPoweredJsQueriesStatus = exports.getMlPoweredJsQueriesPack = exports.ML_POWERED_JS_QUERIES_PACK_NAME = exports.supportExpectDiscardedCache = exports.isGoodVersion = exports.delay = exports.bundleDb = exports.codeQlVersionAbove = exports.getCachedCodeQlVersion = exports.cacheCodeQlVersion = exports.isHTTPError = exports.UserError = exports.HTTPError = exports.getRequiredEnvParam = exports.initializeEnvironment = exports.assertNever = exports.apiVersionInRange = exports.DisallowedAPIVersionReason = exports.checkGitHubVersionInRange = exports.getGitHubVersion = exports.GitHubVariant = exports.parseGitHubUrl = exports.getCodeQLDatabasePath = exports.getThreadsFlag = exports.getThreadsFlagValue = exports.getAddSnippetsFlag = exports.getMemoryFlag = exports.getMemoryFlagValue = exports.withTmpDir = exports.getToolNames = exports.getExtraOptionsEnvParam = exports.DEFAULT_DEBUG_DATABASE_NAME = exports.DEFAULT_DEBUG_ARTIFACT_NAME = exports.GITHUB_DOTCOM_URL = void 0;
const fs = __importStar(require("fs")); const fs = __importStar(require("fs"));
const os = __importStar(require("os")); const os = __importStar(require("os"));
const path = __importStar(require("path")); const path = __importStar(require("path"));
@@ -676,7 +676,7 @@ function fixInvalidNotifications(sarif, logger) {
`${shared_environment_1.CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX} environment variable.`); `${shared_environment_1.CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX} environment variable.`);
return sarif; return sarif;
} }
if (!(sarif.runs instanceof Array)) { if (!Array.isArray(sarif.runs)) {
return sarif; return sarif;
} }
// Ensure that the array of locations for each SARIF notification contains unique locations. // Ensure that the array of locations for each SARIF notification contains unique locations.
@@ -687,19 +687,19 @@ function fixInvalidNotifications(sarif, logger) {
...sarif, ...sarif,
runs: sarif.runs.map((run) => { runs: sarif.runs.map((run) => {
if (run.tool?.driver?.name !== "CodeQL" || if (run.tool?.driver?.name !== "CodeQL" ||
!(run.invocations instanceof Array)) { !Array.isArray(run.invocations)) {
return run; return run;
} }
return { return {
...run, ...run,
invocations: run.invocations.map((invocation) => { invocations: run.invocations.map((invocation) => {
if (!(invocation.toolExecutionNotifications instanceof Array)) { if (!Array.isArray(invocation.toolExecutionNotifications)) {
return invocation; return invocation;
} }
return { return {
...invocation, ...invocation,
toolExecutionNotifications: invocation.toolExecutionNotifications.map((notification) => { toolExecutionNotifications: invocation.toolExecutionNotifications.map((notification) => {
if (!(notification.locations instanceof Array)) { if (!Array.isArray(notification.locations)) {
return notification; return notification;
} }
const newLocations = removeDuplicateLocations(notification.locations); const newLocations = removeDuplicateLocations(notification.locations);
@@ -722,4 +722,10 @@ function fixInvalidNotifications(sarif, logger) {
return newSarif; return newSarif;
} }
exports.fixInvalidNotifications = fixInvalidNotifications; exports.fixInvalidNotifications = fixInvalidNotifications;
function fixInvalidNotificationsInFile(inputPath, outputPath, logger) {
let sarif = JSON.parse(fs.readFileSync(inputPath, "utf8"));
sarif = fixInvalidNotifications(sarif, logger);
fs.writeFileSync(outputPath, JSON.stringify(sarif));
}
exports.fixInvalidNotificationsInFile = fixInvalidNotificationsInFile;
//# sourceMappingURL=util.js.map //# sourceMappingURL=util.js.map
+1 -1
View File
File diff suppressed because one or more lines are too long
-15
View File
@@ -84,8 +84,6 @@ function toCodedErrors(errors) {
exports.WorkflowErrors = toCodedErrors({ exports.WorkflowErrors = toCodedErrors({
MismatchedBranches: `Please make sure that every branch in on.pull_request is also in on.push so that Code Scanning can compare pull requests against the state of the base branch.`, MismatchedBranches: `Please make sure that every branch in on.pull_request is also in on.push so that Code Scanning can compare pull requests against the state of the base branch.`,
MissingPushHook: `Please specify an on.push hook so that Code Scanning can compare pull requests against the state of the base branch.`, MissingPushHook: `Please specify an on.push hook so that Code Scanning can compare pull requests against the state of the base branch.`,
PathsSpecified: `Using on.push.paths can prevent Code Scanning annotating new alerts in your pull requests.`,
PathsIgnoreSpecified: `Using on.push.paths-ignore can prevent Code Scanning annotating new alerts in your pull requests.`,
CheckoutWrongHead: `git checkout HEAD^2 is no longer necessary. Please remove this step as Code Scanning recommends analyzing the merge commit for best results.`, CheckoutWrongHead: `git checkout HEAD^2 is no longer necessary. Please remove this step as Code Scanning recommends analyzing the merge commit for best results.`,
}); });
function getWorkflowErrors(doc) { function getWorkflowErrors(doc) {
@@ -130,19 +128,6 @@ function getWorkflowErrors(doc) {
if (!hasPush && hasPullRequest) { if (!hasPush && hasPullRequest) {
missingPush = true; missingPush = true;
} }
if (hasPush && hasPullRequest) {
const paths = doc.on.push?.paths;
// if you specify paths or paths-ignore you can end up with commits that have no baseline
// if they didn't change any files
// currently we cannot go back through the history and find the most recent baseline
if (Array.isArray(paths) && paths.length > 0) {
errors.push(exports.WorkflowErrors.PathsSpecified);
}
const pathsIgnore = doc.on.push?.["paths-ignore"];
if (Array.isArray(pathsIgnore) && pathsIgnore.length > 0) {
errors.push(exports.WorkflowErrors.PathsIgnoreSpecified);
}
}
// if doc.on.pull_request is null that means 'all branches' // if doc.on.pull_request is null that means 'all branches'
// if doc.on.pull_request is undefined that means 'off' // if doc.on.pull_request is undefined that means 'off'
// we only want to check for mismatched branches if pull_request is on. // we only want to check for mismatched branches if pull_request is on.
+1 -1
View File
File diff suppressed because one or more lines are too long
+3 -12
View File
@@ -58,15 +58,6 @@ function errorCodes(actual, expected) {
}); });
t.deepEqual(...errorCodes(errors, [])); t.deepEqual(...errorCodes(errors, []));
}); });
(0, ava_1.default)("getWorkflowErrors() when on.push should not have a path", (t) => {
const errors = (0, workflow_1.getWorkflowErrors)({
on: {
push: { branches: ["main"], paths: ["test/*"] },
pull_request: { branches: ["main"] },
},
});
t.deepEqual(...errorCodes(errors, [workflow_1.WorkflowErrors.PathsSpecified]));
});
(0, ava_1.default)("getWorkflowErrors() when on.push is a correct object", (t) => { (0, ava_1.default)("getWorkflowErrors() when on.push is a correct object", (t) => {
const errors = (0, workflow_1.getWorkflowErrors)({ const errors = (0, workflow_1.getWorkflowErrors)({
on: { push: { branches: ["main"] }, pull_request: { branches: ["main"] } }, on: { push: { branches: ["main"] }, pull_request: { branches: ["main"] } },
@@ -227,7 +218,7 @@ function errorCodes(actual, expected) {
(0, ava_1.default)("formatWorkflowErrors() when there are multiple errors", (t) => { (0, ava_1.default)("formatWorkflowErrors() when there are multiple errors", (t) => {
const message = (0, workflow_1.formatWorkflowErrors)([ const message = (0, workflow_1.formatWorkflowErrors)([
workflow_1.WorkflowErrors.CheckoutWrongHead, workflow_1.WorkflowErrors.CheckoutWrongHead,
workflow_1.WorkflowErrors.PathsSpecified, workflow_1.WorkflowErrors.MismatchedBranches,
]); ]);
t.true(message.startsWith("2 issues were detected with this workflow:")); t.true(message.startsWith("2 issues were detected with this workflow:"));
}); });
@@ -238,9 +229,9 @@ function errorCodes(actual, expected) {
(0, ava_1.default)("formatWorkflowCause()", (t) => { (0, ava_1.default)("formatWorkflowCause()", (t) => {
const message = (0, workflow_1.formatWorkflowCause)([ const message = (0, workflow_1.formatWorkflowCause)([
workflow_1.WorkflowErrors.CheckoutWrongHead, workflow_1.WorkflowErrors.CheckoutWrongHead,
workflow_1.WorkflowErrors.PathsSpecified, workflow_1.WorkflowErrors.MismatchedBranches,
]); ]);
t.deepEqual(message, "CheckoutWrongHead,PathsSpecified"); t.deepEqual(message, "CheckoutWrongHead,MismatchedBranches");
t.deepEqual((0, workflow_1.formatWorkflowCause)([]), undefined); t.deepEqual((0, workflow_1.formatWorkflowCause)([]), undefined);
}); });
(0, ava_1.default)("patternIsSuperset()", (t) => { (0, ava_1.default)("patternIsSuperset()", (t) => {
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "codeql", "name": "codeql",
"version": "2.2.9", "version": "2.2.10",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "codeql", "name": "codeql",
"version": "2.2.9", "version": "2.2.10",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "codeql", "name": "codeql",
"version": "2.2.9", "version": "2.2.10",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/artifact": "^1.1.0", "@actions/artifact": "^1.1.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "codeql", "name": "codeql",
"version": "2.2.9", "version": "2.2.10",
"private": true, "private": true,
"description": "CodeQL action", "description": "CodeQL action",
"scripts": { "scripts": {
-33
View File
@@ -1,33 +0,0 @@
name: "Swift analysis using autobuild"
description: "Tests creation of a Swift database using autobuild"
versions: ["latest", "cached", "nightly-latest"]
# Swift autobuilder is only supported on MacOS for private beta
operatingSystems: ["macos"]
env:
CODEQL_ENABLE_EXPERIMENTAL_FEATURES_SWIFT: "true" # Remove when Swift is GA.
steps:
- uses: ./../action/init
id: init
with:
languages: swift
tools: ${{ steps.prepare-test.outputs.tools-url }}
- uses: ./../action/.github/setup-swift
with:
codeql-path: ${{steps.init.outputs.codeql-path}}
- name: Check working directory
shell: bash
run: pwd
- uses: ./../action/autobuild
timeout-minutes: 10
- uses: ./../action/analyze
id: analysis
with:
upload-database: false
- name: Check database
shell: bash
run: |
SWIFT_DB="${{ fromJson(steps.analysis.outputs.db-locations).swift }}"
if [[ ! -d "$SWIFT_DB" ]]; then
echo "Did not create a database for Swift."
exit 1
fi
+8 -10
View File
@@ -910,6 +910,8 @@ export async function getCodeQLForCmd(
} }
if (shouldExportDiagnostics) { if (shouldExportDiagnostics) {
codeqlArgs.push("--sarif-include-diagnostics"); codeqlArgs.push("--sarif-include-diagnostics");
} else if (await util.codeQlVersionAbove(this, "2.12.4")) {
codeqlArgs.push("--no-sarif-include-diagnostics");
} }
codeqlArgs.push(databasePath); codeqlArgs.push(databasePath);
if (querySuitePaths) { if (querySuitePaths) {
@@ -923,11 +925,7 @@ export async function getCodeQLForCmd(
); );
if (shouldExportDiagnostics) { if (shouldExportDiagnostics) {
let sarif = JSON.parse( util.fixInvalidNotificationsInFile(codeqlOutputFile, sarifFile, logger);
fs.readFileSync(codeqlOutputFile, "utf8")
) as util.SarifFile;
sarif = util.fixInvalidNotifications(sarif, logger);
fs.writeFileSync(sarifFile, JSON.stringify(sarif));
} }
return returnState.stdout; return returnState.stdout;
@@ -1050,11 +1048,11 @@ export async function getCodeQLForCmd(
await new toolrunner.ToolRunner(cmd, args).exec(); await new toolrunner.ToolRunner(cmd, args).exec();
// Fix invalid notifications in the SARIF file output by CodeQL. // Fix invalid notifications in the SARIF file output by CodeQL.
let sarif = JSON.parse( util.fixInvalidNotificationsInFile(
fs.readFileSync(intermediateSarifFile, "utf8") intermediateSarifFile,
) as util.SarifFile; sarifFile,
sarif = util.fixInvalidNotifications(sarif, logger); logger
fs.writeFileSync(sarifFile, JSON.stringify(sarif)); );
}, },
async diagnosticsExport( async diagnosticsExport(
sarifFile: string, sarifFile: string,
+3 -3
View File
@@ -62,12 +62,12 @@ export const featureConfig: Record<
[Feature.ExportCodeScanningConfigEnabled]: { [Feature.ExportCodeScanningConfigEnabled]: {
envVar: "CODEQL_ACTION_EXPORT_CODE_SCANNING_CONFIG", envVar: "CODEQL_ACTION_EXPORT_CODE_SCANNING_CONFIG",
minimumVersion: "2.12.3", minimumVersion: "2.12.3",
defaultValue: false, defaultValue: true,
}, },
[Feature.ExportDiagnosticsEnabled]: { [Feature.ExportDiagnosticsEnabled]: {
envVar: "CODEQL_ACTION_EXPORT_DIAGNOSTICS", envVar: "CODEQL_ACTION_EXPORT_DIAGNOSTICS",
minimumVersion: "2.12.4", minimumVersion: "2.12.4",
defaultValue: false, defaultValue: true,
}, },
[Feature.MlPoweredQueriesEnabled]: { [Feature.MlPoweredQueriesEnabled]: {
@@ -78,7 +78,7 @@ export const featureConfig: Record<
[Feature.UploadFailedSarifEnabled]: { [Feature.UploadFailedSarifEnabled]: {
envVar: "CODEQL_ACTION_UPLOAD_FAILED_SARIF", envVar: "CODEQL_ACTION_UPLOAD_FAILED_SARIF",
minimumVersion: "2.11.3", minimumVersion: "2.11.3",
defaultValue: false, defaultValue: true,
}, },
}; };
+14 -4
View File
@@ -823,7 +823,7 @@ export function fixInvalidNotifications(
); );
return sarif; return sarif;
} }
if (!(sarif.runs instanceof Array)) { if (!Array.isArray(sarif.runs)) {
return sarif; return sarif;
} }
@@ -837,21 +837,21 @@ export function fixInvalidNotifications(
runs: sarif.runs.map((run) => { runs: sarif.runs.map((run) => {
if ( if (
run.tool?.driver?.name !== "CodeQL" || run.tool?.driver?.name !== "CodeQL" ||
!(run.invocations instanceof Array) !Array.isArray(run.invocations)
) { ) {
return run; return run;
} }
return { return {
...run, ...run,
invocations: run.invocations.map((invocation) => { invocations: run.invocations.map((invocation) => {
if (!(invocation.toolExecutionNotifications instanceof Array)) { if (!Array.isArray(invocation.toolExecutionNotifications)) {
return invocation; return invocation;
} }
return { return {
...invocation, ...invocation,
toolExecutionNotifications: toolExecutionNotifications:
invocation.toolExecutionNotifications.map((notification) => { invocation.toolExecutionNotifications.map((notification) => {
if (!(notification.locations instanceof Array)) { if (!Array.isArray(notification.locations)) {
return notification; return notification;
} }
const newLocations = removeDuplicateLocations( const newLocations = removeDuplicateLocations(
@@ -878,3 +878,13 @@ export function fixInvalidNotifications(
} }
return newSarif; return newSarif;
} }
export function fixInvalidNotificationsInFile(
inputPath: string,
outputPath: string,
logger: Logger
): void {
let sarif = JSON.parse(fs.readFileSync(inputPath, "utf8")) as SarifFile;
sarif = fixInvalidNotifications(sarif, logger);
fs.writeFileSync(outputPath, JSON.stringify(sarif));
}
+3 -14
View File
@@ -56,17 +56,6 @@ test("getWorkflowErrors() when on.push is a valid superset", (t) => {
t.deepEqual(...errorCodes(errors, [])); t.deepEqual(...errorCodes(errors, []));
}); });
test("getWorkflowErrors() when on.push should not have a path", (t) => {
const errors = getWorkflowErrors({
on: {
push: { branches: ["main"], paths: ["test/*"] },
pull_request: { branches: ["main"] },
},
});
t.deepEqual(...errorCodes(errors, [WorkflowErrors.PathsSpecified]));
});
test("getWorkflowErrors() when on.push is a correct object", (t) => { test("getWorkflowErrors() when on.push is a correct object", (t) => {
const errors = getWorkflowErrors({ const errors = getWorkflowErrors({
on: { push: { branches: ["main"] }, pull_request: { branches: ["main"] } }, on: { push: { branches: ["main"] }, pull_request: { branches: ["main"] } },
@@ -317,7 +306,7 @@ test("formatWorkflowErrors() when there is one error", (t) => {
test("formatWorkflowErrors() when there are multiple errors", (t) => { test("formatWorkflowErrors() when there are multiple errors", (t) => {
const message = formatWorkflowErrors([ const message = formatWorkflowErrors([
WorkflowErrors.CheckoutWrongHead, WorkflowErrors.CheckoutWrongHead,
WorkflowErrors.PathsSpecified, WorkflowErrors.MismatchedBranches,
]); ]);
t.true(message.startsWith("2 issues were detected with this workflow:")); t.true(message.startsWith("2 issues were detected with this workflow:"));
}); });
@@ -331,10 +320,10 @@ test("formatWorkflowCause() with no errors", (t) => {
test("formatWorkflowCause()", (t) => { test("formatWorkflowCause()", (t) => {
const message = formatWorkflowCause([ const message = formatWorkflowCause([
WorkflowErrors.CheckoutWrongHead, WorkflowErrors.CheckoutWrongHead,
WorkflowErrors.PathsSpecified, WorkflowErrors.MismatchedBranches,
]); ]);
t.deepEqual(message, "CheckoutWrongHead,PathsSpecified"); t.deepEqual(message, "CheckoutWrongHead,MismatchedBranches");
t.deepEqual(formatWorkflowCause([]), undefined); t.deepEqual(formatWorkflowCause([]), undefined);
}); });
-15
View File
@@ -108,8 +108,6 @@ function toCodedErrors(errors: {
export const WorkflowErrors = toCodedErrors({ export const WorkflowErrors = toCodedErrors({
MismatchedBranches: `Please make sure that every branch in on.pull_request is also in on.push so that Code Scanning can compare pull requests against the state of the base branch.`, MismatchedBranches: `Please make sure that every branch in on.pull_request is also in on.push so that Code Scanning can compare pull requests against the state of the base branch.`,
MissingPushHook: `Please specify an on.push hook so that Code Scanning can compare pull requests against the state of the base branch.`, MissingPushHook: `Please specify an on.push hook so that Code Scanning can compare pull requests against the state of the base branch.`,
PathsSpecified: `Using on.push.paths can prevent Code Scanning annotating new alerts in your pull requests.`,
PathsIgnoreSpecified: `Using on.push.paths-ignore can prevent Code Scanning annotating new alerts in your pull requests.`,
CheckoutWrongHead: `git checkout HEAD^2 is no longer necessary. Please remove this step as Code Scanning recommends analyzing the merge commit for best results.`, CheckoutWrongHead: `git checkout HEAD^2 is no longer necessary. Please remove this step as Code Scanning recommends analyzing the merge commit for best results.`,
}); });
@@ -162,19 +160,6 @@ export function getWorkflowErrors(doc: Workflow): CodedError[] {
if (!hasPush && hasPullRequest) { if (!hasPush && hasPullRequest) {
missingPush = true; missingPush = true;
} }
if (hasPush && hasPullRequest) {
const paths = doc.on.push?.paths;
// if you specify paths or paths-ignore you can end up with commits that have no baseline
// if they didn't change any files
// currently we cannot go back through the history and find the most recent baseline
if (Array.isArray(paths) && paths.length > 0) {
errors.push(WorkflowErrors.PathsSpecified);
}
const pathsIgnore = doc.on.push?.["paths-ignore"];
if (Array.isArray(pathsIgnore) && pathsIgnore.length > 0) {
errors.push(WorkflowErrors.PathsIgnoreSpecified);
}
}
// if doc.on.pull_request is null that means 'all branches' // if doc.on.pull_request is null that means 'all branches'
// if doc.on.pull_request is undefined that means 'off' // if doc.on.pull_request is undefined that means 'off'
+13 -13
View File
@@ -2,28 +2,28 @@ name: Use custom queries
disable-default-queries: true disable-default-queries: true
queries: queries:
# Query suites # Query suites
- name: Select a query suite - name: Select a query suite
uses: ./codeql-qlpacks/complex-python-qlpack/rootAndBar.qls uses: ./codeql-qlpacks/complex-python-qlpack/rootAndBar.qls
# QL pack subset # QL pack subset
- name: Select a ql file - name: Select a ql file
uses: ./codeql-qlpacks/complex-javascript-qlpack/show_ifs.ql uses: ./codeql-qlpacks/complex-javascript-qlpack/show_ifs.ql
- name: Select a subfolder - name: Select a subfolder
uses: ./codeql-qlpacks/complex-javascript-qlpack/foo uses: ./codeql-qlpacks/complex-javascript-qlpack/foo
- name: Select a folder with two subfolders - name: Select a folder with two subfolders
uses: ./codeql-qlpacks/complex-javascript-qlpack/foo2 uses: ./codeql-qlpacks/complex-javascript-qlpack/foo2
# Inrepo QL pack # Inrepo QL pack
- name: Select an inrepo ql pack - name: Select an inrepo ql pack
uses: ./codeql-qlpacks/csharp-qlpack uses: ./codeql-qlpacks/csharp-qlpack
- name: Java queries - name: Java queries
uses: ./codeql-qlpacks/java-qlpack uses: ./codeql-qlpacks/java-qlpack
# External QL packs # External QL packs
- name: Go queries - name: Go queries
uses: Anthophila/go-querypack@master uses: codeql-testing/go-querypack@master
- name: Cpp queries - name: Cpp queries
uses: Anthophila/cpp-querypack@second-branch uses: codeql-testing/cpp-querypack@second-branch
- name: JavaScript queries - name: JavaScript queries
uses: Anthophila/javascript-querypack/show_ifs2.ql@master uses: codeql-testing/javascript-querypack/show_ifs2.ql@master
- name: Python queries - name: Python queries
uses: Anthophila/python-querypack/show_ifs2.ql@second-branch uses: codeql-testing/python-querypack/show_ifs2.ql@second-branch