Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: download grype on windows runners #315

Merged
merged 17 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions .github/workflows/demo.yml

This file was deleted.

49 changes: 0 additions & 49 deletions .github/workflows/sarifdemo.yml

This file was deleted.

28 changes: 27 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- run: npm run audit
- run: npm test

test-as-action: # run actions to test some scenarios
test-download-action:
runs-on: ubuntu-latest

steps:
Expand All @@ -69,3 +69,29 @@ jobs:

- name: "Check Grype version after scan-action"
run: grype version | egrep "^Version:.*0.54.0$"

test-all:
kzantow marked this conversation as resolved.
Show resolved Hide resolved
strategy:
matrix:
config: [
{image: 'alpine:latest'},
{path: 'tests/fixtures/npm-project'},
{sbom: 'tests/fixtures/test_sbom.spdx.json'},
]
os: [ubuntu-latest, windows-latest, macos-latest]
output-format: [sarif, json, table]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: ./
id: scan
with:
image: ${{ matrix.config.image }}
path: ${{ matrix.config.path }}
sbom: ${{ matrix.config.sbom }}
output-format: ${{ matrix.output-format }}
fail-build: false

- name: Validate file exists
if: ${{ matrix.output-format != 'table' }}
run: test -f '${{ steps.scan.outputs[matrix.output-format] }}'
11 changes: 5 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const fs = __nccwpck_require__(7147);
const stream = __nccwpck_require__(2781);
const { GRYPE_VERSION } = __nccwpck_require__(6244);

const grypeBinary = "grype";
const exeSuffix = process.platform == "win32" ? ".exe" : "";
const grypeBinary = "grype" + exeSuffix;
const grypeVersion = core.getInput("grype-version") || GRYPE_VERSION;

async function downloadGrype(version) {
Expand All @@ -30,15 +31,13 @@ async function downloadGrype(version) {
// TODO: when grype starts supporting unreleased versions, support it here
// Download the installer, and run
const installPath = await cache.downloadTool(url);
// Make sure the tool's executable bit is set
await exec.exec(`chmod +x ${installPath}`);

let cmd = `${installPath} -b ${installPath}_grype ${version}`;
let cmd = `sh ${installPath} -d -b ${installPath}_grype ${version}`;
await exec.exec(cmd);
let grypePath = `${installPath}_grype/grype`;
let grypePath = `${installPath}_grype/${grypeBinary}`;

// Cache the downloaded file
return cache.cacheFile(grypePath, `grype`, `grype`, version);
return cache.cacheFile(grypePath, grypeBinary, grypeBinary, version);
}

async function installGrype(version) {
Expand Down
11 changes: 5 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const fs = require("fs");
const stream = require("stream");
const { GRYPE_VERSION } = require("./GrypeVersion");

const grypeBinary = "grype";
const exeSuffix = process.platform == "win32" ? ".exe" : "";
const grypeBinary = "grype" + exeSuffix;
const grypeVersion = core.getInput("grype-version") || GRYPE_VERSION;

async function downloadGrype(version) {
Expand All @@ -16,15 +17,13 @@ async function downloadGrype(version) {
// TODO: when grype starts supporting unreleased versions, support it here
// Download the installer, and run
const installPath = await cache.downloadTool(url);
// Make sure the tool's executable bit is set
await exec.exec(`chmod +x ${installPath}`);

let cmd = `${installPath} -b ${installPath}_grype ${version}`;
let cmd = `sh ${installPath} -d -b ${installPath}_grype ${version}`;
willmurphyscode marked this conversation as resolved.
Show resolved Hide resolved
await exec.exec(cmd);
let grypePath = `${installPath}_grype/grype`;
let grypePath = `${installPath}_grype/${grypeBinary}`;

// Cache the downloaded file
return cache.cacheFile(grypePath, `grype`, `grype`, version);
return cache.cacheFile(grypePath, grypeBinary, grypeBinary, version);
}

async function installGrype(version) {
Expand Down
Loading