Skip to content

Commit

Permalink
chore: test natively on Windows (#426)
Browse files Browse the repository at this point in the history
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 <will.murphy@anchore.com>
  • Loading branch information
willmurphyscode authored Nov 7, 2023
1 parent ace0b97 commit 74207bd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 49 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ./
Expand Down
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 4 additions & 8 deletions dist/attachReleaseAssets/index.js

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

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

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

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

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

10 changes: 1 addition & 9 deletions src/github/Executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/github/SyftGithubAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -205,14 +207,14 @@ export async function downloadSyft(): Promise<string> {

await execute("sh", [installPath, "-d", "-b", syftBinaryPath, version]);

return `${syftBinaryPath}/${name}`;
return path.join(syftBinaryPath, name) + exeSuffix;
}

/**
* Gets the Syft command to run via exec
*/
export async function getSyftCommand(): Promise<string> {
const name = SYFT_BINARY_NAME;
const name = SYFT_BINARY_NAME + exeSuffix;
const version = SYFT_VERSION;

const sourceSyft = await downloadSyftFromZip(version);
Expand Down

0 comments on commit 74207bd

Please sign in to comment.