Skip to content

Commit

Permalink
fix: Windows runners (#315)
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Zantow <kzantow@gmail.com>
  • Loading branch information
kzantow committed May 23, 2024
1 parent 30b718a commit b4a7247
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 94 deletions.
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:
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}`;
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

0 comments on commit b4a7247

Please sign in to comment.