Skip to content

Commit a4bc36a

Browse files
authored
Test diff. (#41)
* Test diff. * Run yarn upgrade. * Use the right option, document the new option in action.yml. * Fix revision. * Smarter example * Try head_ref. * Base sha. * Fix readme.
1 parent 47ef11b commit a4bc36a

File tree

6 files changed

+1048
-621
lines changed

6 files changed

+1048
-621
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ jobs:
6868
api-key: ${{secrets.fossaApiKey}}
6969
run-tests: true
7070

71+
- name: Run FOSSA test with --diff
72+
uses: ./
73+
with:
74+
api-key: ${{secrets.fossaApiKey}}
75+
run-tests: ${{ github.event_name == 'pull_request' }}
76+
test-diff-revision: ${{ github.event.pull_request.base.sha }}
77+
7178
- name: Run FOSSA test with container
7279
uses: ./
7380
with:

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,28 @@ jobs:
5252
run-tests: true
5353
```
5454

55+
## `test-diff-revision`
56+
**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).
57+
58+
Setting this field has no effect if `run-tests` is `false`.
59+
You must also set `run-tests` to `true` in order for this field to take effect.
60+
61+
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.
62+
63+
```yml
64+
jobs:
65+
fossa-scan:
66+
runs-on: ubuntu-latest
67+
steps:
68+
- uses: actions/checkout@v3
69+
- uses: fossas/fossa-action@main # Use a specific version if locking is preferred
70+
with:
71+
api-key: ${{secrets.fossaApiKey}}
72+
run-tests: ${{ github.event_name == 'pull_request' }}
73+
test-diff-revision: ${{ github.event.pull_request.base.sha }}
74+
75+
```
76+
5577
### `container`
5678
**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`).
5779

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ inputs:
3535
mode will generate a debug bundle that can be uploaded as a build artifact
3636
after this action completes.
3737
default: false
38+
test-diff-revision:
39+
description: >-
40+
Run fossa test with the `--diff <revision>` option, which checks if there are new issues relative to `<revision>`.
41+
Requires `run-tests` to be set in order to take effect.
42+
required: false
3843

3944
runs:
4045
using: node20

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const getInputOptions = (required: boolean = false): InputOptions => ({
1010
export const FOSSA_API_KEY = getInput('api-key', getInputOptions(true));
1111
export const CONTAINER = getInput('container', getInputOptions());
1212
export const RUN_TESTS = getBooleanInput('run-tests', {required: false});
13+
export const TEST_DIFF_REV = getInput('test-diff-revision', {required: false});
1314
export const ENDPOINT = getInput('endpoint', getInputOptions());
1415
export const BRANCH = getInput('branch', getInputOptions());
1516
export const PROJECT = getInput('project', getInputOptions());

src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
CONTAINER,
55
FOSSA_API_KEY,
66
RUN_TESTS,
7+
TEST_DIFF_REV,
78
ENDPOINT,
89
BRANCH,
910
PROJECT,
@@ -61,7 +62,13 @@ export async function analyze(): Promise<void> {
6162
}
6263
} else if (RUN_TESTS) {
6364
output = '';
64-
const exitCode = await exec('fossa', [...getArgs('test'), CONTAINER], defaultOptions);
65+
let args = [...getArgs('test'), CONTAINER];
66+
67+
if (TEST_DIFF_REV && TEST_DIFF_REV !== '') {
68+
args.push('--diff', TEST_DIFF_REV);
69+
}
70+
71+
const exitCode = await exec('fossa', args, defaultOptions);
6572

6673
// Check output or exitCode
6774
if (exitCode !== 0 || output.match(failedRegex)) {

0 commit comments

Comments
 (0)