Skip to content

Merge main into releases/v3 #2226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 45 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7cdd972
Update changelog and version after v3.24.9
github-actions[bot] Mar 22, 2024
ca4079b
Update checked-in dependencies
github-actions[bot] Mar 22, 2024
3d81734
Merge pull request #2209 from github/mergeback/v3.24.9-to-main-1b1aada4
aibaars Mar 22, 2024
a12b868
Create feature flag for merging SARIF files using the CLI
koesie10 Mar 15, 2024
ccc609b
Use github merge-results command when feature flag is enabled
koesie10 Mar 15, 2024
7e30c62
Use subdirectory for combined SARIF file
koesie10 Mar 18, 2024
2bbafcd
Upload debug artifacts for upload-sarif
koesie10 Mar 18, 2024
e20c273
Use supportsFeature check for merging SARIF files
koesie10 Mar 22, 2024
6ac5753
Use options object instead of boolean for mergeResults
koesie10 Mar 25, 2024
70aa50b
Use runTool for mergeResults
koesie10 Mar 25, 2024
3bd271c
Introduce areAllRunsProducedByCodeQL function
koesie10 Mar 25, 2024
a0a63a2
Do not try merging a single SARIF file
koesie10 Mar 25, 2024
3c4b8bc
Change log levels
koesie10 Mar 25, 2024
82b82e5
Only upload combined SARIF files when env var is set
koesie10 Mar 25, 2024
155888c
Bump the npm group with 3 updates
dependabot[bot] Mar 25, 2024
a99c623
Update checked-in dependencies
github-actions[bot] Mar 25, 2024
956f09c
Merge pull request #2211 from github/dependabot/npm_and_yarn/npm-2d63…
angelapwen Mar 25, 2024
58194bf
Do not require debug mode for debugging uploads
koesie10 Mar 26, 2024
f835435
Rename run to uploadArtifacts
koesie10 Mar 26, 2024
016720d
Refactor areAllRunsProducedByCodeQL to use Array.every
koesie10 Mar 26, 2024
84ba7fb
Merge pull request #2199 from github/koesie10/cli-sarif-merge
koesie10 Mar 27, 2024
048b508
Bump the npm group with 2 updates
dependabot[bot] Apr 1, 2024
d7c4cc3
Update checked-in dependencies
github-actions[bot] Apr 1, 2024
99c9897
Merge pull request #2217 from github/dependabot/npm_and_yarn/npm-eb3e…
angelapwen Apr 1, 2024
f4936c4
Update default bundle to codeql-bundle-v2.17.0
github-actions[bot] Apr 2, 2024
ec214df
Add changelog note
github-actions[bot] Apr 2, 2024
eeaea14
Update supported GitHub Enterprise Server versions
github-actions[bot] Apr 3, 2024
eda4878
Only pass `--new-analysis-summary` if it is not default behavior
henrymercer Apr 3, 2024
f06c933
Update soon to be deprecated CodeQL version
henrymercer Apr 3, 2024
6514cbb
improve logging coverage when uploaing sarif files
nickfyson Apr 3, 2024
f8dd543
Add changelog note
henrymercer Apr 3, 2024
dcf00b3
Account for varying major version number in error message
henrymercer Apr 3, 2024
3bd9c3e
Merge pull request #2220 from github/update-supported-enterprise-serv…
henrymercer Apr 3, 2024
2cc8bbd
Apply suggestions from code review
nickfyson Apr 3, 2024
978bdd6
fix test that runs flakily locally
nickfyson Apr 3, 2024
d325762
fix linting error
nickfyson Apr 3, 2024
2654062
Merge branch 'main' into nickfyson/upload-logging
nickfyson Apr 3, 2024
d3c32a8
fix test to respect updated logging behaviour
nickfyson Apr 3, 2024
c037115
clarify logging in response to pr review comments
nickfyson Apr 3, 2024
65e69c8
Merge branch 'main' into update-bundle/codeql-bundle-v2.17.0
cklin Apr 4, 2024
278465c
Merge pull request #2219 from github/update-bundle/codeql-bundle-v2.17.0
cklin Apr 4, 2024
5f535de
Merge pull request #2221 from github/nickfyson/upload-logging
nickfyson Apr 4, 2024
f421cda
Run integration test PR checks nightly (#2222)
angelapwen Apr 4, 2024
7df281f
Gracefully continue if `createStatusReportBase` throws (#2225)
angelapwen Apr 4, 2024
3f041c5
Update changelog for v3.24.10
github-actions[bot] Apr 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use github merge-results command when feature flag is enabled
  • Loading branch information
koesie10 committed Mar 22, 2024
commit ccc609bf1a583fd71da1677ea527a8e8a8ed4fd3
17 changes: 17 additions & 0 deletions lib/codeql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codeql.js.map

Large diffs are not rendered by default.

59 changes: 58 additions & 1 deletion lib/upload-lib.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/upload-lib.js.map

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ interface ExtraOptions {
extractor?: Options;
queries?: Options;
};
github?: {
"*"?: Options;
"merge-results"?: Options;
};
}

export interface CodeQL {
Expand Down Expand Up @@ -191,6 +195,14 @@ export interface CodeQL {
): Promise<void>;
/** Get the location of an extractor for the specified language. */
resolveExtractor(language: Language): Promise<string>;
/**
* Run 'codeql github merge-results'.
*/
mergeResults(
sarifFiles: string[],
outputFile: string,
mergeRunsFromEqualCategory?: boolean,
): Promise<void>;
}

export interface VersionInfo {
Expand Down Expand Up @@ -489,6 +501,7 @@ export function setCodeQL(partialCodeql: Partial<CodeQL>): CodeQL {
),
diagnosticsExport: resolveFunction(partialCodeql, "diagnosticsExport"),
resolveExtractor: resolveFunction(partialCodeql, "resolveExtractor"),
mergeResults: resolveFunction(partialCodeql, "mergeResults"),
};
return cachedCodeQL;
}
Expand Down Expand Up @@ -1077,6 +1090,29 @@ export async function getCodeQLForCmd(
).exec();
return JSON.parse(extractorPath);
},
async mergeResults(
sarifFiles: string[],
outputFile: string,
mergeRunsFromEqualCategory = false,
): Promise<void> {
const args = [
"github",
"merge-results",
"--output",
outputFile,
...getExtraOptionsFromEnv(["github", "merge-results"]),
];

for (const sarifFile of sarifFiles) {
args.push("--sarif", sarifFile);
}

if (mergeRunsFromEqualCategory) {
args.push("--sarif-merge-runs-from-equal-category");
}

await new toolrunner.ToolRunner(cmd, args).exec();
},
};
// To ensure that status reports include the CodeQL CLI version wherever
// possible, we want to call getVersion(), which populates the version value
Expand Down
117 changes: 115 additions & 2 deletions src/upload-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,29 @@ import fileUrl from "file-url";
import * as jsonschema from "jsonschema";

import * as actionsUtil from "./actions-util";
import {
getOptionalInput,
getRequiredInput,
getTemporaryDirectory,
} from "./actions-util";
import * as api from "./api-client";
import { getGitHubVersion } from "./api-client";
import { CodeQL, getCodeQL } from "./codeql";
import { getConfig } from "./config-utils";
import { EnvVar } from "./environment";
import { Feature, Features } from "./feature-flags";
import * as fingerprints from "./fingerprints";
import { initCodeQL } from "./init";
import { Logger } from "./logging";
import { parseRepositoryNwo, RepositoryNwo } from "./repository";
import * as util from "./util";
import { SarifFile, ConfigurationError, wrapError } from "./util";
import {
SarifFile,
ConfigurationError,
wrapError,
getRequiredEnvParam,
GitHubVersion,
} from "./util";

const GENERIC_403_MSG =
"The repo on which this action is running has not opted-in to CodeQL code scanning.";
Expand Down Expand Up @@ -48,6 +64,88 @@ function combineSarifFiles(sarifFiles: string[]): SarifFile {
return combinedSarif;
}

// Takes a list of paths to sarif files and combines them together using the
// CLI `github merge-results` command when all SARIF files are produced by
// CodeQL. Otherwise, it will fall back to combining the files in the action.
// Returns the contents of the combined sarif file.
async function combineSarifFilesUsingCLI(
sarifFiles: string[],
gitHubVersion: GitHubVersion,
features: Features,
logger: Logger,
): Promise<SarifFile> {
// First check if all files are produced by CodeQL.
let allCodeQL = true;

for (const sarifFile of sarifFiles) {
const sarifObject = JSON.parse(
fs.readFileSync(sarifFile, "utf8"),
) as SarifFile;

const allRunsCodeQL = sarifObject.runs?.every(
(run) => run.tool?.driver?.name === "CodeQL",
);

if (!allRunsCodeQL) {
allCodeQL = false;
break;
}
}

if (!allCodeQL) {
logger.warning(
"Not all SARIF files were produced by CodeQL. Merging files in the action.",
);

// If not, use the naive method of combining the files.
return combineSarifFiles(sarifFiles);
}

// Initialize CodeQL, either by using the config file from the 'init' step,
// or by initializing it here.
let codeQL: CodeQL;
let tempDir: string;

const config = await getConfig(actionsUtil.getTemporaryDirectory(), logger);
if (config !== undefined) {
codeQL = await getCodeQL(config.codeQLCmd);
tempDir = config.tempDir;
} else {
logger.warning(
"Initializing CodeQL since the 'init' Action was not called before this step.",
);

const apiDetails = {
auth: getRequiredInput("token"),
externalRepoAuth: getOptionalInput("external-repository-token"),
url: getRequiredEnvParam("GITHUB_SERVER_URL"),
apiURL: getRequiredEnvParam("GITHUB_API_URL"),
};

const codeQLDefaultVersionInfo = await features.getDefaultCliVersion(
gitHubVersion.type,
);

const initCodeQLResult = await initCodeQL(
undefined, // There is no tools input on the upload action
apiDetails,
getTemporaryDirectory(),
gitHubVersion.type,
codeQLDefaultVersionInfo,
logger,
);

codeQL = initCodeQLResult.codeql;
tempDir = getTemporaryDirectory();
}

const outputFile = path.resolve(tempDir, "combined-sarif.sarif");

await codeQL.mergeResults(sarifFiles, outputFile, true);

return JSON.parse(fs.readFileSync(outputFile, "utf8")) as SarifFile;
}

// Populates the run.automationDetails.id field using the analysis_key and environment
// and return an updated sarif file contents.
export function populateRunAutomationDetails(
Expand Down Expand Up @@ -363,12 +461,27 @@ async function uploadFiles(
logger.startGroup("Uploading results");
logger.info(`Processing sarif files: ${JSON.stringify(sarifFiles)}`);

const gitHubVersion = await getGitHubVersion();
const features = new Features(
gitHubVersion,
repositoryNwo,
actionsUtil.getTemporaryDirectory(),
logger,
);

// Validate that the files we were asked to upload are all valid SARIF files
for (const file of sarifFiles) {
validateSarifFileSchema(file, logger);
}

let sarif = combineSarifFiles(sarifFiles);
let sarif = (await features.getValue(Feature.CliSarifMerge))
? await combineSarifFilesUsingCLI(
sarifFiles,
gitHubVersion,
features,
logger,
)
: combineSarifFiles(sarifFiles);
sarif = await fingerprints.addFingerprints(sarif, sourceRoot, logger);

sarif = populateRunAutomationDetails(
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy