Skip to content

Commit

Permalink
output to tmpdir
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Zantow <kzantow@gmail.com>
  • Loading branch information
kzantow committed Feb 17, 2022
1 parent 304ad09 commit d9653aa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
11 changes: 4 additions & 7 deletions dist/attachReleaseAssets/index.js

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

11 changes: 4 additions & 7 deletions dist/downloadSyft/index.js

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

11 changes: 4 additions & 7 deletions dist/runSyftAction/index.js

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

12 changes: 5 additions & 7 deletions src/github/SyftGithubAction.ts
Expand Up @@ -8,7 +8,6 @@ import {
ReleaseEvent,
} from "@octokit/webhooks-types";
import * as fs from "fs";
import * as os from "os";
import path from "path";
import stream from "stream";
import { SyftOptions } from "../Syft";
Expand All @@ -20,6 +19,8 @@ export const SYFT_VERSION = core.getInput("syft-version") || "v0.33.0";

const PRIOR_ARTIFACT_ENV_VAR = "ANCHORE_SBOM_ACTION_PRIOR_ARTIFACT";

const tempDir = fs.mkdtempSync("sbom-action-");

/**
* Tries to get a unique artifact name or otherwise as appropriate as possible
*/
Expand Down Expand Up @@ -149,7 +150,7 @@ async function executeSyft({ input, format }: SyftOptions): Promise<string> {
args = [...args, "-o", format];

// always generate github dependency format
args = [...args, "-o", "github=github.sbom.json"];
args = [...args, "-o", `github=${tempDir}/github.sbom.json`];

// Execute in a group so the syft output is collapsed in the GitHub log
core.info(`[command]${cmd} ${args.join(" ")}`);
Expand Down Expand Up @@ -256,8 +257,7 @@ export async function uploadSbomArtifact(contents: string): Promise<void> {

const fileName = getArtifactName();

const tempPath = fs.mkdtempSync(path.join(os.tmpdir(), "sbom-action-"));
const filePath = `${tempPath}/${fileName}`;
const filePath = `${tempDir}/${fileName}`;
fs.writeFileSync(filePath, contents);

const outputFile = core.getInput("output-file");
Expand Down Expand Up @@ -383,7 +383,7 @@ export async function runSyftAction(): Promise<void> {

if (doUpload) {
const snapshot = JSON.parse(
fs.readFileSync("github.sbom.json").toString("utf8")
fs.readFileSync(`${tempDir}/github.sbom.json`).toString("utf8")
) as DependencySnapshot;

snapshot.job = {
Expand All @@ -398,9 +398,7 @@ export async function runSyftAction(): Promise<void> {

const response = await postDependencySnapshot(snapshot);
core.info(`DS Response: ${JSON.stringify(response)}`);
}

if (doUpload) {
await uploadSbomArtifact(output);

core.exportVariable(PRIOR_ARTIFACT_ENV_VAR, getArtifactName());
Expand Down

0 comments on commit d9653aa

Please sign in to comment.