-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sub-action to download Grype (#152)
- Loading branch information
Showing
8 changed files
with
229 additions
and
161 deletions.
There are no files selected for viewing
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 @@ | ||
exports.GRYPE_VERSION = "v0.34.4"; |
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
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
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,20 @@ | ||
name: "Download Grype" | ||
author: "Anchore" | ||
description: "Downloads the Grype binary and provides a path to execute it" | ||
branding: | ||
color: blue | ||
icon: check-circle | ||
inputs: | ||
grype-version: | ||
description: "A specific version of Grype to install" | ||
required: false | ||
run: | ||
description: "Flag to indicate which sub-action to run" | ||
required: false | ||
default: "download-grype" | ||
outputs: | ||
cmd: | ||
description: "An absolute path to the Grype executable" | ||
runs: | ||
using: "node12" | ||
main: "../dist/index.js" |
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
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
module.exports = { | ||
setupFiles: ["<rootDir>/.jest/setEnvVars.js"], | ||
verbose: true, | ||
testPathIgnorePatterns: ["action.test.js"], | ||
}; |
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 |
---|---|---|
@@ -1,11 +1,39 @@ | ||
const child_process = require('child_process'); | ||
const path = require('path'); | ||
const process = require('process'); | ||
const child_process = require("child_process"); | ||
const os = require("os"); | ||
const path = require("path"); | ||
const process = require("process"); | ||
|
||
// shows how the runner will run a javascript action with env / stdout protocol | ||
test('test runs', () => { | ||
process.env['INPUT_DEBUG'] = 'true'; | ||
process.env['INPUT_IMAGE-REFERENCE'] = 'docker.io/alpine:latest'; | ||
const index_path = path.join(__dirname, '../index.js'); | ||
console.log(child_process.execSync(`node ${index_path}`, {env: process.env}).toString()); | ||
}); | ||
const actionPath = path.join(__dirname, "../index.js"); | ||
|
||
// Execute the action, and return any outputs | ||
function runAction(inputs) { | ||
// reverse core.js: const val = process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || ''; | ||
for (const k in inputs) { | ||
process.env[`INPUT_${k}`.toUpperCase()] = inputs[k]; | ||
} | ||
// capture stdout | ||
const stdout = child_process | ||
.execSync(`node ${actionPath}`, { | ||
env: process.env, | ||
}) | ||
.toString("utf8"); | ||
const outputs = {}; | ||
// reverse setOutput command calls like: | ||
// ::set-output name=cmd::/tmp/actions/cache/grype/0.34.4/x64/grype | ||
for (const line of stdout.split(os.EOL)) { | ||
const groups = line.match(/::set-output name=(\w+)::(.*)$/); | ||
if (groups && groups.length > 2) { | ||
outputs[groups[1]] = groups[2]; | ||
} | ||
} | ||
return outputs; | ||
} | ||
|
||
describe("sbom-action", () => { | ||
it("runs download-grype", () => { | ||
const outputs = runAction({ | ||
run: "download-grype", | ||
}); | ||
expect(outputs.cmd).toBeDefined(); | ||
}); | ||
}); |
Oops, something went wrong.