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

Test diff. #41

Merged
merged 8 commits into from
Aug 6, 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
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ jobs:
api-key: ${{secrets.fossaApiKey}}
run-tests: true

- name: Run FOSSA test with --diff
uses: ./
with:
api-key: ${{secrets.fossaApiKey}}
run-tests: ${{ github.event_name == 'pull_request' }}
test-diff-revision: ${{ github.event.pull_request.base.sha }}

- name: Run FOSSA test with container
uses: ./
with:
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ jobs:
run-tests: true
```

## `test-diff-revision`
**Optional** If set to a string, FOSSA will run the `fossa test` command with the `--diff` [option](https://github.com/fossas/fossa-cli/blob/master/docs/references/subcommands/test.md#test-for-new-issues-compared-to-another-revision).

Setting this field has no effect if `run-tests` is `false`.
You must also set `run-tests` to `true` in order for this field to take effect.

This example will run fossa test only if the workflow run event is a pull request and verify that there are no new issues relative to the base ref.

```yml
jobs:
fossa-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: fossas/fossa-action@main # Use a specific version if locking is preferred
with:
api-key: ${{secrets.fossaApiKey}}
run-tests: ${{ github.event_name == 'pull_request' }}
test-diff-revision: ${{ github.event.pull_request.base.sha }}

```

### `container`
**Optional** A container name or OCI image path. Set to use FOSSA's container scanning functionality. This will run `fossa container analyze` (default behavior) and `fossa container test` (if used in combination with `run-tests`).

Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ inputs:
mode will generate a debug bundle that can be uploaded as a build artifact
after this action completes.
default: false
test-diff-revision:
description: >-
Run fossa test with the `--diff <revision>` option, which checks if there are new issues relative to `<revision>`.
Requires `run-tests` to be set in order to take effect.
required: false

runs:
using: node20
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const getInputOptions = (required: boolean = false): InputOptions => ({
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});
export const TEST_DIFF_REV = getInput('test-diff-revision', {required: false});
export const ENDPOINT = getInput('endpoint', getInputOptions());
export const BRANCH = getInput('branch', getInputOptions());
export const PROJECT = getInput('project', getInputOptions());
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
CONTAINER,
FOSSA_API_KEY,
RUN_TESTS,
TEST_DIFF_REV,
ENDPOINT,
BRANCH,
PROJECT,
Expand Down Expand Up @@ -61,7 +62,13 @@ export async function analyze(): Promise<void> {
}
} else if (RUN_TESTS) {
output = '';
const exitCode = await exec('fossa', [...getArgs('test'), CONTAINER], defaultOptions);
let args = [...getArgs('test'), CONTAINER];

if (TEST_DIFF_REV && TEST_DIFF_REV !== '') {
args.push('--diff', TEST_DIFF_REV);
}

const exitCode = await exec('fossa', args, defaultOptions);

// Check output or exitCode
if (exitCode !== 0 || output.match(failedRegex)) {
Expand Down
Loading
Loading