Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 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
28 changes: 26 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
with:
node-version: 20.x

- name: Install yarn
run: npm install -g yarn
- name: Install npm packages
run: yarn --frozen-lockfile

Expand Down Expand Up @@ -102,11 +104,33 @@ jobs:

- name: Checkout code
uses: actions/checkout@v5
with:
with:
path: different-working-directory

- name: Scan a different directory
uses: ./
with:
api-key: ${{secrets.fossaApiKey}}
working-directory: different-working-directory

# The following two blocks are one test. Don't separate them.
- name: Installs a Specific version
uses : ./
with:
api-key: ${{secrets.fossaApiKey}}
pinned-cli-version: 3.15.0

- name: Check Version
run:
./fossa/fossa --version | grep '3.15.0'

# The following two blocks are one test. Don't separate them.
- name: Installs a Specific version (normalized)
uses : ./
with:
api-key: ${{secrets.fossaApiKey}}
pinned-cli-version: v3.15.0

- name: Check Version
run:
./fossa/fossa --version | grep '3.15.0'
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20.16.0
v20.19.0
6 changes: 6 additions & 0 deletions .stubs/act
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env -S mise tool-stub
# Tool for running github actions locally for testing.

version = "latest"
tool = "act"
bin = "act"
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 20.16.0
nodejs 20.19.0
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,27 @@ jobs:
```


### `pinned-cli-version`

**Optional** By default, the action will use the latest version of FOSSA CLI.
In some specific circumstances it makes sense to pin the version of the CLI used by the action.
To do that you can use `pinned-cli-version`:

```yml
jobs:
fossa-scan:
runs-on: ubuntu-latest
- uses: actions/checkout@v3
- uses: fossas/fossa-action@main
with:
api-key: ${{secrets.FOSSA_API_KEY}}
pinned-cli-version: v3.0.0
- uses: actions/upload-artifact@v3
with:
name: fossa.debug.json.gz
path: ./fossa.debug.json.gz
```

### `working-directory`

**Optional** By default, the action will scan anything in the default github actions working directory. Use this option to scan a project in a different directory.
Expand All @@ -207,7 +228,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
with:
path: my-working-directory
- uses: fossas/fossa-action@main
with:
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ inputs:
description: >-
Your FOSSA API key.
required: true
pinned-cli-version:
description: >-
If set, use the specified FOSSA Cli version.
required: false
run-tests:
description: >-
If set to `true` FOSSA will run the `fossa test` command.
Expand Down
22 changes: 0 additions & 22 deletions dist/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,6 @@ The above copyright notice and this permission notice shall be included in all c

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@fastify/busboy
MIT
Copyright Brian White. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

semver
ISC
The ISC License
Expand Down
6 changes: 3 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[tasks.build-dist]
description = 'Build the dist/ version of the program.'
run = '''
yarn build
'''

[tasks.lint]
description = 'Lint the project.'
run = 'yarn lint'

[tasks.lint-fix]
description = 'Lint the project while also auto-fixing things that can be.'
run = 'yarn lint --fix'

[tasks.test-local]
description = 'Use `act` to test locally.'
run = './.stubs/act push -s fossaApiKey=${FOSSA_API_KEY}'

[tools]
node = "20.19.0"
"npm:eslint" = "latest"
"npm:yarn" = "latest"
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const getInputOptions = (required: boolean = false): InputOptions => ({
trimWhitespace: true,
});

export const PINNED_CLI_VERSION = getInput('pinned-cli-version', getInputOptions(false));
export const FOSSA_API_KEY = getInput('api-key', getInputOptions(true));
export const CONTAINER = getInput('container', getInputOptions());
export const RUN_TESTS = getBooleanInput('run-tests', {required: false});
Expand Down
34 changes: 30 additions & 4 deletions src/download-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { addPath, debug } from '@actions/core';
import { exec } from '@actions/exec';
import { find, downloadTool, cacheDir, cacheFile, findAllVersions } from '@actions/tool-cache';
import * as fs from 'node:fs';
import { PINNED_CLI_VERSION } from './config';

const CACHE_NAME = 'fossa';

Expand Down Expand Up @@ -38,6 +39,28 @@ async function getInstaller() {
return downloadPath;
}

/**
* Select a CLI version to install.
*
* Defaults to latest.
*/
function selectCliVersion(platform: string) : string {
let selectedCliVersion: string;

if (PINNED_CLI_VERSION) {
const trimmed = PINNED_CLI_VERSION.trimStart();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const trimmed = PINNED_CLI_VERSION.trimStart();
const trimmed = PINNED_CLI_VERSION.trim();

Probably want to trim trailing spaces too, no?

if (trimmed.startsWith('v')) {
selectedCliVersion = trimmed;
} else {
selectedCliVersion = `v${trimmed}`;
}
} else {
selectedCliVersion = findAllVersions(CACHE_NAME, platform).sort().reverse()[0] || '-1'; // We'll never cache a version as -1
}

return selectedCliVersion;
}

export async function fetchFossaCli(): Promise<void> {
const devNull = fs.createWriteStream('/dev/null', {flags: 'a'});
const defaultOptions = {outStream: devNull};
Expand All @@ -46,15 +69,18 @@ export async function fetchFossaCli(): Promise<void> {
const platform = getPlatform();

// Get cached path
const latestVersion = findAllVersions(CACHE_NAME, platform).sort().reverse()[0] || '-1'; // We'll never cache a version as -1
let fossaPath = find(CACHE_NAME, latestVersion, platform);
const selectedCliVersion = selectCliVersion(platform);

let fossaPath = find(CACHE_NAME, selectedCliVersion, platform);

if (latestVersion) debug(`Using FOSSA version ${latestVersion}`);
if (selectedCliVersion) debug(`Using FOSSA version ${selectedCliVersion}`);

if (!fossaPath) {
debug(`Fetching new FOSSA version`);

if (await exec('bash', [installer, '-b', './fossa'], {...defaultOptions}) !== 0) {
const versionArgs = (selectedCliVersion !== '-1' && [selectedCliVersion]) || [];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How very bash-y

Suggested change
const versionArgs = (selectedCliVersion !== '-1' && [selectedCliVersion]) || [];
const versionArgs = selectedCliVersion !== '-1' ? [selectedCliVersion] : [];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes when you get in that head-space it's hard to jump back out...


if (await exec('bash', [installer, '-b', './fossa', ...versionArgs], {...defaultOptions}) !== 0) {
throw new Error(`Fossa failed to install correctly`);
}

Expand Down
Loading
Loading