Skip to content

Commit ef29ba4

Browse files
authored
Fix report options (#57)
1 parent 6eb50db commit ef29ba4

File tree

6 files changed

+28
-25
lines changed

6 files changed

+28
-25
lines changed

.github/pull_request_template.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
# Checklist
44

5-
[ ] If I changed code, I ran `yarn build` and committed resulting changes.
6-
[ ] I added an example exercising this PRs functionality to `.github/workflows/test.yml` or explained why it doesn't make sense to do so.
5+
- [ ] If I changed code, I ran `yarn build` and committed resulting changes.
6+
- [ ] I added an example exercising this PRs functionality to `.github/workflows/test.yml` or explained why it doesn't make sense to do so.

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ on:
1212

1313
jobs:
1414
fossa-scan:
15-
strategy:
16-
fail-fast: false
1715
runs-on: ubuntu-latest
1816
steps:
1917
- name: Checkout code
@@ -88,5 +86,7 @@ jobs:
8886
with:
8987
api-key: ${{secrets.fossaApiKey}}
9088
generate-report: json
91-
92-
- run: echo ${{ steps.example-generate-report.outputs.report }}
89+
90+
- name: Demonstrate report output
91+
run: |
92+
echo '${{ steps.example-generate-report.outputs.report }}' | jq

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
api-key: ${{secrets.fossaApiKey}}
8282
run-tests: true
8383
generate-report: html
84-
- run: ${{ steps.fossa.outputs.report }} > report.html
84+
- run: echo '${{ steps.fossa.outputs.report }}' > report.html
8585
```
8686

8787
## `test-diff-revision`

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ export async function analyze(): Promise<void> {
4040
POLICY,
4141
];
4242

43-
const getArgs = (cmd: string) => [
43+
const getArgs = (cmd: string[]) => [
4444
CONTAINER ? 'container' : null,
45-
cmd,
45+
...cmd,
4646
...getEndpointArgs(),
4747
...getBranchArgs(),
4848
...getProjectArgs(),
@@ -68,15 +68,15 @@ export async function analyze(): Promise<void> {
6868

6969
if (!RUN_TESTS) {
7070
output = '';
71-
const exitCode = await exec('fossa', [...getArgs('analyze'), CONTAINER], defaultOptions);
71+
const exitCode = await exec('fossa', [...getArgs(['analyze']), CONTAINER], defaultOptions);
7272

7373
// Check output or exitCode
7474
if (exitCode !== 0 || output.match(failedRegex)) {
7575
throw new Error(`FOSSA failed to scan`);
7676
}
7777
} else if (RUN_TESTS) {
7878
output = '';
79-
const args = [...getArgs('test'), CONTAINER];
79+
const args = [...getArgs(['test']), CONTAINER];
8080

8181
if (TEST_DIFF_REV && TEST_DIFF_REV !== '') {
8282
args.push('--diff', TEST_DIFF_REV);
@@ -105,37 +105,40 @@ export async function report(): Promise<void> {
105105
REPORT_FORMAT,
106106
];
107107

108-
const getArgs = (cmd: string) => [
109-
cmd,
108+
const getArgs = (cmd: string[]) => [
109+
...cmd,
110110
...getEndpointArgs(),
111111
...getProjectArgs(),
112112
...getFormatArgs(),
113113
DEBUG ? '--debug' : null,
114114
].filter(arg => arg);
115115

116116
// Setup listeners
117-
let output;
118-
const collectOutput = (data: Buffer) => {
119-
output += data.toString();
117+
let stdout = '';
118+
let stderr = '';
119+
const collectStdout = (data: Buffer) => {
120+
stdout += data.toString();
121+
};
122+
const collectStderr = (data: Buffer) => {
123+
stderr += data.toString();
120124
};
121125

122126
const listeners: ExecListeners = {
123-
stdout: collectOutput,
124-
stderr: collectOutput,
127+
stdout: collectStdout,
128+
stderr: collectStderr,
125129
};
126130

127131
// Collect default options: Env and listeners
128132
const PATH = process.env.PATH || '';
129133
const defaultOptions = { env: { ...process.env, PATH, FOSSA_API_KEY }, listeners };
130-
output = '';
131-
const exitCode = await exec('fossa', [...getArgs('report attribution')], defaultOptions);
134+
const exitCode = await exec('fossa', getArgs(['report', 'attribution']), defaultOptions);
132135

133136
// Check output or exitCode
134-
if (exitCode !== 0 || output.match(failedRegex)) {
137+
if (exitCode !== 0 || stderr.match(failedRegex)) {
135138
throw new Error(`FOSSA failed to scan`);
136139
}
137140

138-
setOutput('report', output);
141+
setOutput('report', stdout);
139142
}
140143

141144
async function run() {
@@ -147,7 +150,7 @@ async function run() {
147150

148151
try {
149152
await analyze();
150-
if(REPORT_FORMAT?.length) {
153+
if (REPORT_FORMAT?.length) {
151154
await report();
152155
}
153156
} catch (e) {

0 commit comments

Comments
 (0)