mirror of
https://github.com/github/codeql-action.git
synced 2026-01-06 22:50:17 +08:00
Upload debug artifacts for upload-sarif
This commit is contained in:
49
src/upload-sarif-action-post-helper.ts
Normal file
49
src/upload-sarif-action-post-helper.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import * as actionsUtil from "./actions-util";
|
||||
|
||||
export async function run(
|
||||
uploadDebugArtifacts: (
|
||||
toUpload: string[],
|
||||
rootDir: string,
|
||||
artifactName: string,
|
||||
) => Promise<void>,
|
||||
) {
|
||||
const tempDir = actionsUtil.getTemporaryDirectory();
|
||||
|
||||
// Upload Actions SARIF artifacts for debugging
|
||||
if (core.isDebug()) {
|
||||
core.info(
|
||||
"Debug mode is on. Uploading available combined SARIF files as Actions debugging artifact...",
|
||||
);
|
||||
|
||||
const baseTempDir = path.resolve(tempDir, "combined-sarif");
|
||||
|
||||
const toUpload: string[] = [];
|
||||
|
||||
if (fs.existsSync(baseTempDir)) {
|
||||
const outputDirs = fs.readdirSync(baseTempDir);
|
||||
|
||||
for (const outputDir of outputDirs) {
|
||||
const sarifFiles = fs
|
||||
.readdirSync(path.resolve(baseTempDir, outputDir))
|
||||
.filter((f) => f.endsWith(".sarif"));
|
||||
|
||||
for (const sarifFile of sarifFiles) {
|
||||
toUpload.push(path.resolve(baseTempDir, outputDir, sarifFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (toUpload.length > 0) {
|
||||
await uploadDebugArtifacts(
|
||||
toUpload,
|
||||
baseTempDir,
|
||||
"upload-debug-artifacts",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/upload-sarif-action-post.ts
Normal file
22
src/upload-sarif-action-post.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* This file is the entry point for the `post:` hook of `upload-sarif-action.yml`.
|
||||
* It will run after the all steps in this job, in reverse order in relation to
|
||||
* other `post:` hooks.
|
||||
*/
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import * as debugArtifacts from "./debug-artifacts";
|
||||
import * as uploadSarifActionPostHelper from "./upload-sarif-action-post-helper";
|
||||
import { wrapError } from "./util";
|
||||
|
||||
async function runWrapper() {
|
||||
try {
|
||||
await uploadSarifActionPostHelper.run(debugArtifacts.uploadDebugArtifacts);
|
||||
} catch (error) {
|
||||
core.setFailed(
|
||||
`upload-sarif post-action step failed: ${wrapError(error).message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void runWrapper();
|
||||
Reference in New Issue
Block a user