Skip to content

Commit

Permalink
Add config input (#430)
Browse files Browse the repository at this point in the history
* Add config input

Allow a Syft configuration file to be passed to the action.

Signed-off-by: Eugene Yakubovich <[email protected]>

* rename config_file to configFile

Signed-off-by: Will Murphy <[email protected]>

---------

Signed-off-by: Eugene Yakubovich <[email protected]>
Signed-off-by: Will Murphy <[email protected]>
Co-authored-by: Will Murphy <[email protected]>
  • Loading branch information
eyakubovich and willmurphyscode authored Nov 27, 2023
1 parent 9d0277c commit a4126e6
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ and uploading them as workflow artifacts and release assets.
| `upload-release-assets` | Upload release assets | `true` |
| `syft-version` | The version of Syft to use | |
| `github-token` | Authorized secret GitHub Personal Access Token. | `github.token` |
| `config ` | Syft configuration file to use. | |

### anchore/sbom-action/publish-sbom

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ inputs:
description: "Upload release assets"
default: "true"

config:
required: false
description: "Configuration file to use"

runs:
using: "node16"
main: "dist/runSyftAction/index.js"
4 changes: 4 additions & 0 deletions dist/attachReleaseAssets/index.js

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

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

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

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

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

1 change: 1 addition & 0 deletions src/Syft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ export interface SyftOptions {
| "text"
| "json";
uploadToDependencySnapshotAPI: boolean;
configFile: string;
}
5 changes: 5 additions & 0 deletions src/github/SyftGithubAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ async function executeSyft({
args = [...args, "-o", `github=${githubDependencySnapshotFile}`];
}

if (opts.configFile) {
args = [...args, "-c", opts.configFile];
}

// Execute in a group so the syft output is collapsed in the GitHub log
core.info(`[command]${cmd} ${args.join(" ")}`);

Expand Down Expand Up @@ -367,6 +371,7 @@ export async function runSyftAction(): Promise<void> {
},
format: getSbomFormat(),
uploadToDependencySnapshotAPI: uploadToSnapshotAPI(),
configFile: core.getInput("config"),
});

core.info(`SBOM scan completed in: ${(Date.now() - start) / 1000}s`);
Expand Down
15 changes: 15 additions & 0 deletions tests/SyftGithubAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,19 @@ describe("Action", () => {
expect(mapToWSLPath("D:\\Some\\Path")).toBe("/mnt/d/Some/Path");
expect(mapToWSLPath("C:\\Some\\Path")).toBe("/mnt/c/Some/Path");
});

it("calls with config", async () => {
setData({
inputs: {
image: "some-image:latest",
config: "syft-config.yaml",
}
});

await action.runSyftAction();
const { cmd, args, env } = data.execArgs;

expect(args).toContain("-c");
expect(args).toContain("syft-config.yaml");
});
});

0 comments on commit a4126e6

Please sign in to comment.