-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upload debug artifacts for upload-sarif
- Loading branch information
Koen Vlaswinkel
committed
Mar 22, 2024
1 parent
7e30c62
commit 2bbafcd
Showing
7 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,4 @@ outputs: | |
runs: | ||
using: node20 | ||
main: '../lib/upload-sarif-action.js' | ||
post: '../lib/upload-sarif-action-post.js' |