From 5854181545a30c36ccbeeccac899005d246c8396 Mon Sep 17 00:00:00 2001 From: Will Murphy Date: Tue, 7 Nov 2023 08:59:51 -0500 Subject: [PATCH 1/7] chore: test natively on Windows Previously, parts of the tooling didn't work on Windows, so WSL was used as a workaround for this use case. Things should work on Windows now, so test running directly instead of via WSL. Signed-off-by: Will Murphy --- .github/workflows/test.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 79cfad54..a5692bab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,11 +30,6 @@ jobs: os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - - uses: Vampire/setup-wsl@v2 - if: ${{ matrix.os == 'windows-latest' }} - with: - distribution: Alpine - - uses: actions/checkout@v3 with: path: ./ From f68f80ac25902981d02764d5293b8a8a6136811a Mon Sep 17 00:00:00 2001 From: Will Murphy Date: Tue, 7 Nov 2023 09:05:45 -0500 Subject: [PATCH 2/7] stop prefixing wsl to paths Signed-off-by: Will Murphy --- dist/attachReleaseAssets/index.js | 7 +------ dist/downloadSyft/index.js | 7 +------ dist/runSyftAction/index.js | 7 +------ src/github/Executor.ts | 10 +--------- 4 files changed, 4 insertions(+), 27 deletions(-) diff --git a/dist/attachReleaseAssets/index.js b/dist/attachReleaseAssets/index.js index 0653abcd..c5b8ebbc 100644 --- a/dist/attachReleaseAssets/index.js +++ b/dist/attachReleaseAssets/index.js @@ -23438,12 +23438,7 @@ const exec = __importStar(__nccwpck_require__(1514)); */ function execute(cmd, args, options) { return __awaiter(this, void 0, void 0, function* () { - if (process.platform === "win32") { - return yield exec.exec("wsl", [mapToWSLPath(cmd), ...args.map(mapToWSLPath)], options); - } - else { - return exec.exec(cmd, args, options); - } + return exec.exec(cmd, args, options); }); } exports.execute = execute; diff --git a/dist/downloadSyft/index.js b/dist/downloadSyft/index.js index 5a2ed7a8..3ce0d2d9 100644 --- a/dist/downloadSyft/index.js +++ b/dist/downloadSyft/index.js @@ -23486,12 +23486,7 @@ const exec = __importStar(__nccwpck_require__(1514)); */ function execute(cmd, args, options) { return __awaiter(this, void 0, void 0, function* () { - if (process.platform === "win32") { - return yield exec.exec("wsl", [mapToWSLPath(cmd), ...args.map(mapToWSLPath)], options); - } - else { - return exec.exec(cmd, args, options); - } + return exec.exec(cmd, args, options); }); } exports.execute = execute; diff --git a/dist/runSyftAction/index.js b/dist/runSyftAction/index.js index 4cb9c67d..8c20774b 100644 --- a/dist/runSyftAction/index.js +++ b/dist/runSyftAction/index.js @@ -23438,12 +23438,7 @@ const exec = __importStar(__nccwpck_require__(1514)); */ function execute(cmd, args, options) { return __awaiter(this, void 0, void 0, function* () { - if (process.platform === "win32") { - return yield exec.exec("wsl", [mapToWSLPath(cmd), ...args.map(mapToWSLPath)], options); - } - else { - return exec.exec(cmd, args, options); - } + return exec.exec(cmd, args, options); }); } exports.execute = execute; diff --git a/src/github/Executor.ts b/src/github/Executor.ts index 67273e5c..9890366a 100644 --- a/src/github/Executor.ts +++ b/src/github/Executor.ts @@ -11,15 +11,7 @@ export async function execute( args: string[], options?: exec.ExecOptions ) { - if (process.platform === "win32") { - return await exec.exec( - "wsl", - [mapToWSLPath(cmd), ...args.map(mapToWSLPath)], - options - ); - } else { - return exec.exec(cmd, args, options); - } + return exec.exec(cmd, args, options); } /** From a7f36cc87140e25a7891bf48d3e8e3b4f7acbc5d Mon Sep 17 00:00:00 2001 From: Will Murphy Date: Tue, 7 Nov 2023 10:06:09 -0500 Subject: [PATCH 3/7] use path.join instead of / literal Signed-off-by: Will Murphy --- dist/attachReleaseAssets/index.js | 2 +- dist/downloadSyft/index.js | 2 +- dist/runSyftAction/index.js | 2 +- src/github/SyftGithubAction.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/attachReleaseAssets/index.js b/dist/attachReleaseAssets/index.js index c5b8ebbc..14d868f5 100644 --- a/dist/attachReleaseAssets/index.js +++ b/dist/attachReleaseAssets/index.js @@ -24111,7 +24111,7 @@ function downloadSyft() { // Make sure the tool's executable bit is set const syftBinaryPath = `${installPath}_${name}`; yield (0, Executor_1.execute)("sh", [installPath, "-d", "-b", syftBinaryPath, version]); - return `${syftBinaryPath}/${name}`; + return path_1.default.join(`${syftBinaryPath}`, `${name}`); }); } exports.downloadSyft = downloadSyft; diff --git a/dist/downloadSyft/index.js b/dist/downloadSyft/index.js index 3ce0d2d9..3b498377 100644 --- a/dist/downloadSyft/index.js +++ b/dist/downloadSyft/index.js @@ -24159,7 +24159,7 @@ function downloadSyft() { // Make sure the tool's executable bit is set const syftBinaryPath = `${installPath}_${name}`; yield (0, Executor_1.execute)("sh", [installPath, "-d", "-b", syftBinaryPath, version]); - return `${syftBinaryPath}/${name}`; + return path_1.default.join(`${syftBinaryPath}`, `${name}`); }); } exports.downloadSyft = downloadSyft; diff --git a/dist/runSyftAction/index.js b/dist/runSyftAction/index.js index 8c20774b..8fdb9ca2 100644 --- a/dist/runSyftAction/index.js +++ b/dist/runSyftAction/index.js @@ -24111,7 +24111,7 @@ function downloadSyft() { // Make sure the tool's executable bit is set const syftBinaryPath = `${installPath}_${name}`; yield (0, Executor_1.execute)("sh", [installPath, "-d", "-b", syftBinaryPath, version]); - return `${syftBinaryPath}/${name}`; + return path_1.default.join(`${syftBinaryPath}`, `${name}`); }); } exports.downloadSyft = downloadSyft; diff --git a/src/github/SyftGithubAction.ts b/src/github/SyftGithubAction.ts index a2f13acc..c2a1c677 100644 --- a/src/github/SyftGithubAction.ts +++ b/src/github/SyftGithubAction.ts @@ -205,7 +205,7 @@ export async function downloadSyft(): Promise { await execute("sh", [installPath, "-d", "-b", syftBinaryPath, version]); - return `${syftBinaryPath}/${name}`; + return path.join(`${syftBinaryPath}`, `${name}`); } /** From f753891b2689152e00bd99dc0c264aeaf53c365f Mon Sep 17 00:00:00 2001 From: Will Murphy Date: Tue, 7 Nov 2023 10:12:56 -0500 Subject: [PATCH 4/7] append exe to install path on windows Signed-off-by: Will Murphy --- dist/attachReleaseAssets/index.js | 6 +++++- dist/downloadSyft/index.js | 6 +++++- dist/runSyftAction/index.js | 6 +++++- src/github/SyftGithubAction.ts | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/dist/attachReleaseAssets/index.js b/dist/attachReleaseAssets/index.js index 14d868f5..186e0c7a 100644 --- a/dist/attachReleaseAssets/index.js +++ b/dist/attachReleaseAssets/index.js @@ -24111,7 +24111,11 @@ function downloadSyft() { // Make sure the tool's executable bit is set const syftBinaryPath = `${installPath}_${name}`; yield (0, Executor_1.execute)("sh", [installPath, "-d", "-b", syftBinaryPath, version]); - return path_1.default.join(`${syftBinaryPath}`, `${name}`); + const installedPath = path_1.default.join(`${syftBinaryPath}`, `${name}`); + if (process.platform === "win32") { + return `${installedPath}.exe`; + } + return installedPath; }); } exports.downloadSyft = downloadSyft; diff --git a/dist/downloadSyft/index.js b/dist/downloadSyft/index.js index 3b498377..86db05d9 100644 --- a/dist/downloadSyft/index.js +++ b/dist/downloadSyft/index.js @@ -24159,7 +24159,11 @@ function downloadSyft() { // Make sure the tool's executable bit is set const syftBinaryPath = `${installPath}_${name}`; yield (0, Executor_1.execute)("sh", [installPath, "-d", "-b", syftBinaryPath, version]); - return path_1.default.join(`${syftBinaryPath}`, `${name}`); + const installedPath = path_1.default.join(`${syftBinaryPath}`, `${name}`); + if (process.platform === "win32") { + return `${installedPath}.exe`; + } + return installedPath; }); } exports.downloadSyft = downloadSyft; diff --git a/dist/runSyftAction/index.js b/dist/runSyftAction/index.js index 8fdb9ca2..4bedf1ba 100644 --- a/dist/runSyftAction/index.js +++ b/dist/runSyftAction/index.js @@ -24111,7 +24111,11 @@ function downloadSyft() { // Make sure the tool's executable bit is set const syftBinaryPath = `${installPath}_${name}`; yield (0, Executor_1.execute)("sh", [installPath, "-d", "-b", syftBinaryPath, version]); - return path_1.default.join(`${syftBinaryPath}`, `${name}`); + const installedPath = path_1.default.join(`${syftBinaryPath}`, `${name}`); + if (process.platform === "win32") { + return `${installedPath}.exe`; + } + return installedPath; }); } exports.downloadSyft = downloadSyft; diff --git a/src/github/SyftGithubAction.ts b/src/github/SyftGithubAction.ts index c2a1c677..f88c0eb2 100644 --- a/src/github/SyftGithubAction.ts +++ b/src/github/SyftGithubAction.ts @@ -205,7 +205,11 @@ export async function downloadSyft(): Promise { await execute("sh", [installPath, "-d", "-b", syftBinaryPath, version]); - return path.join(`${syftBinaryPath}`, `${name}`); + const installedPath = path.join(`${syftBinaryPath}`, `${name}`); + if (process.platform === "win32") { + return `${installedPath}.exe`; + } + return installedPath; } /** From ecbabe4d908f8ec4f50efed3169a1bacc4696e6c Mon Sep 17 00:00:00 2001 From: Will Murphy Date: Tue, 7 Nov 2023 10:24:01 -0500 Subject: [PATCH 5/7] append .exe to cached tool name on windows Signed-off-by: Will Murphy --- dist/attachReleaseAssets/index.js | 2 +- dist/downloadSyft/index.js | 2 +- dist/runSyftAction/index.js | 2 +- src/github/SyftGithubAction.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/attachReleaseAssets/index.js b/dist/attachReleaseAssets/index.js index 186e0c7a..d47c595a 100644 --- a/dist/attachReleaseAssets/index.js +++ b/dist/attachReleaseAssets/index.js @@ -24124,7 +24124,7 @@ exports.downloadSyft = downloadSyft; */ function getSyftCommand() { return __awaiter(this, void 0, void 0, function* () { - const name = exports.SYFT_BINARY_NAME; + const name = exports.SYFT_BINARY_NAME + (process.platform == "win32" ? ".exe" : ""); const version = exports.SYFT_VERSION; const sourceSyft = yield (0, SyftDownloader_1.downloadSyftFromZip)(version); if (sourceSyft) { diff --git a/dist/downloadSyft/index.js b/dist/downloadSyft/index.js index 86db05d9..8aff83f9 100644 --- a/dist/downloadSyft/index.js +++ b/dist/downloadSyft/index.js @@ -24172,7 +24172,7 @@ exports.downloadSyft = downloadSyft; */ function getSyftCommand() { return __awaiter(this, void 0, void 0, function* () { - const name = exports.SYFT_BINARY_NAME; + const name = exports.SYFT_BINARY_NAME + (process.platform == "win32" ? ".exe" : ""); const version = exports.SYFT_VERSION; const sourceSyft = yield (0, SyftDownloader_1.downloadSyftFromZip)(version); if (sourceSyft) { diff --git a/dist/runSyftAction/index.js b/dist/runSyftAction/index.js index 4bedf1ba..f5d840ff 100644 --- a/dist/runSyftAction/index.js +++ b/dist/runSyftAction/index.js @@ -24124,7 +24124,7 @@ exports.downloadSyft = downloadSyft; */ function getSyftCommand() { return __awaiter(this, void 0, void 0, function* () { - const name = exports.SYFT_BINARY_NAME; + const name = exports.SYFT_BINARY_NAME + (process.platform == "win32" ? ".exe" : ""); const version = exports.SYFT_VERSION; const sourceSyft = yield (0, SyftDownloader_1.downloadSyftFromZip)(version); if (sourceSyft) { diff --git a/src/github/SyftGithubAction.ts b/src/github/SyftGithubAction.ts index f88c0eb2..60e15daf 100644 --- a/src/github/SyftGithubAction.ts +++ b/src/github/SyftGithubAction.ts @@ -216,7 +216,7 @@ export async function downloadSyft(): Promise { * Gets the Syft command to run via exec */ export async function getSyftCommand(): Promise { - const name = SYFT_BINARY_NAME; + const name = SYFT_BINARY_NAME + (process.platform == "win32" ? ".exe" : ""); const version = SYFT_VERSION; const sourceSyft = await downloadSyftFromZip(version); From 6abdba0a0c8ca74cec378d74ce5dcbd2e82212fe Mon Sep 17 00:00:00 2001 From: Will Murphy Date: Tue, 7 Nov 2023 10:49:20 -0500 Subject: [PATCH 6/7] update readme Signed-off-by: Will Murphy --- README.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c5d3ce09..86ed1e41 100644 --- a/README.md +++ b/README.md @@ -167,15 +167,9 @@ Output parameters: ## Windows -Windows is currently supported via Windows Subsystem for Linux (WSL). It is -required to set up a WSL distribution prior to invoking the `sbom-action`, for -example, you can add the small Alpine image: - -```yaml -- uses: Vampire/setup-wsl@v2 - with: - distribution: Alpine -``` +This action is tested on Windows, and should work natively on Windows hosts +without WSL. (Note that it previously required WSL, but should now be run +natively on Windows.) ## Diagnostics From 2ca0d8fb738dd50c64ff2ec53116b33f177a55a3 Mon Sep 17 00:00:00 2001 From: Will Murphy Date: Tue, 7 Nov 2023 15:36:25 -0500 Subject: [PATCH 7/7] extract shared exe suffix logic Signed-off-by: Will Murphy --- dist/attachReleaseAssets/index.js | 9 +++------ dist/downloadSyft/index.js | 9 +++------ dist/runSyftAction/index.js | 9 +++------ src/github/SyftGithubAction.ts | 10 ++++------ 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/dist/attachReleaseAssets/index.js b/dist/attachReleaseAssets/index.js index d47c595a..9d6b6e7d 100644 --- a/dist/attachReleaseAssets/index.js +++ b/dist/attachReleaseAssets/index.js @@ -23959,6 +23959,7 @@ exports.SYFT_VERSION = core.getInput("syft-version") || SyftVersion_1.VERSION; const PRIOR_ARTIFACT_ENV_VAR = "ANCHORE_SBOM_ACTION_PRIOR_ARTIFACT"; const tempDir = fs.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "sbom-action-")); const githubDependencySnapshotFile = `${tempDir}/github.sbom.json`; +const exeSuffix = process.platform == "win32" ? ".exe" : ""; /** * Tries to get a unique artifact name or otherwise as appropriate as possible */ @@ -24111,11 +24112,7 @@ function downloadSyft() { // Make sure the tool's executable bit is set const syftBinaryPath = `${installPath}_${name}`; yield (0, Executor_1.execute)("sh", [installPath, "-d", "-b", syftBinaryPath, version]); - const installedPath = path_1.default.join(`${syftBinaryPath}`, `${name}`); - if (process.platform === "win32") { - return `${installedPath}.exe`; - } - return installedPath; + return path_1.default.join(syftBinaryPath, name) + exeSuffix; }); } exports.downloadSyft = downloadSyft; @@ -24124,7 +24121,7 @@ exports.downloadSyft = downloadSyft; */ function getSyftCommand() { return __awaiter(this, void 0, void 0, function* () { - const name = exports.SYFT_BINARY_NAME + (process.platform == "win32" ? ".exe" : ""); + const name = exports.SYFT_BINARY_NAME + exeSuffix; const version = exports.SYFT_VERSION; const sourceSyft = yield (0, SyftDownloader_1.downloadSyftFromZip)(version); if (sourceSyft) { diff --git a/dist/downloadSyft/index.js b/dist/downloadSyft/index.js index 8aff83f9..67ece520 100644 --- a/dist/downloadSyft/index.js +++ b/dist/downloadSyft/index.js @@ -24007,6 +24007,7 @@ exports.SYFT_VERSION = core.getInput("syft-version") || SyftVersion_1.VERSION; const PRIOR_ARTIFACT_ENV_VAR = "ANCHORE_SBOM_ACTION_PRIOR_ARTIFACT"; const tempDir = fs.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "sbom-action-")); const githubDependencySnapshotFile = `${tempDir}/github.sbom.json`; +const exeSuffix = process.platform == "win32" ? ".exe" : ""; /** * Tries to get a unique artifact name or otherwise as appropriate as possible */ @@ -24159,11 +24160,7 @@ function downloadSyft() { // Make sure the tool's executable bit is set const syftBinaryPath = `${installPath}_${name}`; yield (0, Executor_1.execute)("sh", [installPath, "-d", "-b", syftBinaryPath, version]); - const installedPath = path_1.default.join(`${syftBinaryPath}`, `${name}`); - if (process.platform === "win32") { - return `${installedPath}.exe`; - } - return installedPath; + return path_1.default.join(syftBinaryPath, name) + exeSuffix; }); } exports.downloadSyft = downloadSyft; @@ -24172,7 +24169,7 @@ exports.downloadSyft = downloadSyft; */ function getSyftCommand() { return __awaiter(this, void 0, void 0, function* () { - const name = exports.SYFT_BINARY_NAME + (process.platform == "win32" ? ".exe" : ""); + const name = exports.SYFT_BINARY_NAME + exeSuffix; const version = exports.SYFT_VERSION; const sourceSyft = yield (0, SyftDownloader_1.downloadSyftFromZip)(version); if (sourceSyft) { diff --git a/dist/runSyftAction/index.js b/dist/runSyftAction/index.js index f5d840ff..5ec6e85f 100644 --- a/dist/runSyftAction/index.js +++ b/dist/runSyftAction/index.js @@ -23959,6 +23959,7 @@ exports.SYFT_VERSION = core.getInput("syft-version") || SyftVersion_1.VERSION; const PRIOR_ARTIFACT_ENV_VAR = "ANCHORE_SBOM_ACTION_PRIOR_ARTIFACT"; const tempDir = fs.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "sbom-action-")); const githubDependencySnapshotFile = `${tempDir}/github.sbom.json`; +const exeSuffix = process.platform == "win32" ? ".exe" : ""; /** * Tries to get a unique artifact name or otherwise as appropriate as possible */ @@ -24111,11 +24112,7 @@ function downloadSyft() { // Make sure the tool's executable bit is set const syftBinaryPath = `${installPath}_${name}`; yield (0, Executor_1.execute)("sh", [installPath, "-d", "-b", syftBinaryPath, version]); - const installedPath = path_1.default.join(`${syftBinaryPath}`, `${name}`); - if (process.platform === "win32") { - return `${installedPath}.exe`; - } - return installedPath; + return path_1.default.join(syftBinaryPath, name) + exeSuffix; }); } exports.downloadSyft = downloadSyft; @@ -24124,7 +24121,7 @@ exports.downloadSyft = downloadSyft; */ function getSyftCommand() { return __awaiter(this, void 0, void 0, function* () { - const name = exports.SYFT_BINARY_NAME + (process.platform == "win32" ? ".exe" : ""); + const name = exports.SYFT_BINARY_NAME + exeSuffix; const version = exports.SYFT_VERSION; const sourceSyft = yield (0, SyftDownloader_1.downloadSyftFromZip)(version); if (sourceSyft) { diff --git a/src/github/SyftGithubAction.ts b/src/github/SyftGithubAction.ts index 60e15daf..4cc89cd2 100644 --- a/src/github/SyftGithubAction.ts +++ b/src/github/SyftGithubAction.ts @@ -30,6 +30,8 @@ const PRIOR_ARTIFACT_ENV_VAR = "ANCHORE_SBOM_ACTION_PRIOR_ARTIFACT"; const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "sbom-action-")); const githubDependencySnapshotFile = `${tempDir}/github.sbom.json`; +const exeSuffix = process.platform == "win32" ? ".exe" : ""; + /** * Tries to get a unique artifact name or otherwise as appropriate as possible */ @@ -205,18 +207,14 @@ export async function downloadSyft(): Promise { await execute("sh", [installPath, "-d", "-b", syftBinaryPath, version]); - const installedPath = path.join(`${syftBinaryPath}`, `${name}`); - if (process.platform === "win32") { - return `${installedPath}.exe`; - } - return installedPath; + return path.join(syftBinaryPath, name) + exeSuffix; } /** * Gets the Syft command to run via exec */ export async function getSyftCommand(): Promise { - const name = SYFT_BINARY_NAME + (process.platform == "win32" ? ".exe" : ""); + const name = SYFT_BINARY_NAME + exeSuffix; const version = SYFT_VERSION; const sourceSyft = await downloadSyftFromZip(version);