Skip to content

Commit 2bbafcd

Browse files
committed
Upload debug artifacts for upload-sarif
1 parent 7e30c62 commit 2bbafcd

7 files changed

+173
-0
lines changed

lib/upload-sarif-action-post-helper.js

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-sarif-action-post-helper.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-sarif-action-post.js

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-sarif-action-post.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as fs from "fs";
2+
import * as path from "path";
3+
4+
import * as core from "@actions/core";
5+
6+
import * as actionsUtil from "./actions-util";
7+
8+
export async function run(
9+
uploadDebugArtifacts: (
10+
toUpload: string[],
11+
rootDir: string,
12+
artifactName: string,
13+
) => Promise<void>,
14+
) {
15+
const tempDir = actionsUtil.getTemporaryDirectory();
16+
17+
// Upload Actions SARIF artifacts for debugging
18+
if (core.isDebug()) {
19+
core.info(
20+
"Debug mode is on. Uploading available combined SARIF files as Actions debugging artifact...",
21+
);
22+
23+
const baseTempDir = path.resolve(tempDir, "combined-sarif");
24+
25+
const toUpload: string[] = [];
26+
27+
if (fs.existsSync(baseTempDir)) {
28+
const outputDirs = fs.readdirSync(baseTempDir);
29+
30+
for (const outputDir of outputDirs) {
31+
const sarifFiles = fs
32+
.readdirSync(path.resolve(baseTempDir, outputDir))
33+
.filter((f) => f.endsWith(".sarif"));
34+
35+
for (const sarifFile of sarifFiles) {
36+
toUpload.push(path.resolve(baseTempDir, outputDir, sarifFile));
37+
}
38+
}
39+
}
40+
41+
if (toUpload.length > 0) {
42+
await uploadDebugArtifacts(
43+
toUpload,
44+
baseTempDir,
45+
"upload-debug-artifacts",
46+
);
47+
}
48+
}
49+
}

src/upload-sarif-action-post.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* This file is the entry point for the `post:` hook of `upload-sarif-action.yml`.
3+
* It will run after the all steps in this job, in reverse order in relation to
4+
* other `post:` hooks.
5+
*/
6+
import * as core from "@actions/core";
7+
8+
import * as debugArtifacts from "./debug-artifacts";
9+
import * as uploadSarifActionPostHelper from "./upload-sarif-action-post-helper";
10+
import { wrapError } from "./util";
11+
12+
async function runWrapper() {
13+
try {
14+
await uploadSarifActionPostHelper.run(debugArtifacts.uploadDebugArtifacts);
15+
} catch (error) {
16+
core.setFailed(
17+
`upload-sarif post-action step failed: ${wrapError(error).message}`,
18+
);
19+
}
20+
}
21+
22+
void runWrapper();

upload-sarif/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ outputs:
3838
runs:
3939
using: node20
4040
main: '../lib/upload-sarif-action.js'
41+
post: '../lib/upload-sarif-action-post.js'

0 commit comments

Comments
 (0)