From 03a285ea4c204cc43703bed59b0c7ce7ddc4dd9e Mon Sep 17 00:00:00 2001 From: Swarit Pandey Date: Mon, 9 Sep 2024 06:05:17 +0000 Subject: [PATCH 1/2] fix: output --- src/common/common.ts | 4 +--- src/main/index.ts | 2 -- src/post/index.ts | 14 ++++++++++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/common/common.ts b/src/common/common.ts index 14c1c4e..ebb97bb 100644 --- a/src/common/common.ts +++ b/src/common/common.ts @@ -36,9 +36,7 @@ export function getPidFilePath(): string { } export function getOutputDir(): string { - return WORKSPACE - ? path.join(WORKSPACE, RESULTS_DIR_NAME) - : path.join(__dirname, "..", "..", RESULTS_DIR_NAME); + return WORKSPACE || process.cwd(); } export function mockCoreForLocalTesting(): void { diff --git a/src/main/index.ts b/src/main/index.ts index 09b8aa8..6ba12ed 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -169,8 +169,6 @@ async function runKnoxctlScan(): Promise { const scanCommand: string[] = ["knoxctl", "scan"]; const outputDir = path.join(getOutputDir(), "knoxctl-results"); - scanCommand.push("--output", outputDir); - for (const option of knoxctlOptions) { let value: boolean | string; diff --git a/src/post/index.ts b/src/post/index.ts index 9709a1d..4828082 100644 --- a/src/post/index.ts +++ b/src/post/index.ts @@ -149,6 +149,7 @@ function getLatestFile(directory: string, prefix: string): string | null { return matchingFiles.length > 0 ? matchingFiles[0].name : null; } + async function processResultFile( outputDir: string, prefix: string, @@ -211,11 +212,19 @@ async function run(): Promise { // Increase wait time and add file system sync await new Promise((resolve) => setTimeout(resolve, 15000)); - fs.readdirSync(getOutputDir()); // Force a file system sync + + const outputDir = getOutputDir(); + log(`Output directory: ${outputDir}`); + log("Contents of output directory:"); + const files = fs.readdirSync(outputDir); + for (const file of files) { + if (file.startsWith("knoxctl_scan_")) { + log(`- ${file}`); + } + } await processResults(); - const outputDir = getOutputDir(); await uploadArtifacts(outputDir); if (IS_GITHUB_ACTIONS) { @@ -241,6 +250,7 @@ async function uploadArtifacts(outputDir: string): Promise { const artifactName = "knoxctl-scan-results"; const files = fs .readdirSync(outputDir) + .filter((file) => file.startsWith("knoxctl_scan_")) .map((file) => path.join(outputDir, file)); log(`Uploading ${files.length} files as artifacts`); From 470ff21eb0b51bf5022a8c24b60ac66bff7a35f0 Mon Sep 17 00:00:00 2001 From: Swarit Pandey Date: Mon, 9 Sep 2024 06:05:54 +0000 Subject: [PATCH 2/2] fix: lint --- src/post/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/post/index.ts b/src/post/index.ts index 4828082..34fc6aa 100644 --- a/src/post/index.ts +++ b/src/post/index.ts @@ -149,7 +149,6 @@ function getLatestFile(directory: string, prefix: string): string | null { return matchingFiles.length > 0 ? matchingFiles[0].name : null; } - async function processResultFile( outputDir: string, prefix: string, @@ -212,7 +211,7 @@ async function run(): Promise { // Increase wait time and add file system sync await new Promise((resolve) => setTimeout(resolve, 15000)); - + const outputDir = getOutputDir(); log(`Output directory: ${outputDir}`); log("Contents of output directory:");