Skip to content

Commit

Permalink
Upload debug artifacts for upload-sarif
Browse files Browse the repository at this point in the history
  • Loading branch information
Koen Vlaswinkel committed Mar 22, 2024
1 parent 7e30c62 commit 2bbafcd
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 0 deletions.
55 changes: 55 additions & 0 deletions lib/upload-sarif-action-post-helper.js

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

1 change: 1 addition & 0 deletions lib/upload-sarif-action-post-helper.js.map

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

44 changes: 44 additions & 0 deletions lib/upload-sarif-action-post.js

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

1 change: 1 addition & 0 deletions lib/upload-sarif-action-post.js.map

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

49 changes: 49 additions & 0 deletions src/upload-sarif-action-post-helper.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions src/upload-sarif-action-post.ts
Original file line number Diff line number Diff line change
@@ -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();
1 change: 1 addition & 0 deletions upload-sarif/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ outputs:
runs:
using: node20
main: '../lib/upload-sarif-action.js'
post: '../lib/upload-sarif-action-post.js'

0 comments on commit 2bbafcd

Please sign in to comment.