Skip to content

Commit 878c010

Browse files
committed
ass write output to file
1 parent 9327862 commit 878c010

File tree

5 files changed

+55
-13
lines changed

5 files changed

+55
-13
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,9 @@ jobs:
6060
uses: ./
6161
with:
6262
rl_json_path: './data/FD13-FullUSB.zip-report.rl.json'
63+
md_report_path: './report-rl-json.md'
64+
65+
- name: show data files
66+
id: show
67+
run: |
68+
ls -l .

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ inputs:
1212
rl_json_path:
1313
description: The path to the report.rl.json file.
1414
required: true
15+
md_report_path:
16+
description: The path to the markdown file (will be overwritten if exists).
17+
required: true
1518

1619
runs:
1720
using: node20

dist/index.js

Lines changed: 22 additions & 8 deletions
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/main.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as core from '@actions/core'
2-
import * as fs from 'fs'
3-
2+
// import * as fs from 'fs'
3+
import * as fs from 'node:fs'
44
//import { RlJsonReportProcessor } from './rlJsonReportProcessor'
55
// Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true
66

@@ -66,6 +66,23 @@ export class RlJsonReportProcessor {
6666
this.vulnerabilities = this.jpath2dict(this.metadata, 'vulnerabilities')
6767
}
6868

69+
async write(filename: string) {
70+
let filehandle
71+
72+
try {
73+
const filehandle = fs.openSync(filename, 'w')
74+
for (const line of this.out) {
75+
fs.writeSync(filehandle, line + '\n')
76+
}
77+
} catch (error) {
78+
console.error('write failed with error: ' + error)
79+
} finally {
80+
if (filehandle) {
81+
fs.closeSync(filehandle)
82+
}
83+
}
84+
}
85+
6986
jpath2string(data: ODictByString, path_str: string): string {
7087
const path_list: string[] = path_str.split('.')
7188
let z: ODictByString = data
@@ -426,10 +443,12 @@ export class RlJsonReportProcessor {
426443
export async function run(): Promise<void> {
427444
try {
428445
const rl_json_file = core.getInput('rl_json_path')
429-
core.debug(`${rl_json_file}`)
446+
const md_report_path = core.getInput('md_report_path')
447+
core.debug(`input: ${rl_json_file}, output: ${md_report_path}`)
448+
430449
const rjrp = new RlJsonReportProcessor(rl_json_file)
431450
rjrp.simplifyRlJson()
432-
rjrp.output() // prints to console.log()
451+
await rjrp.write(md_report_path)
433452
} catch (error) {
434453
// Fail the workflow run if an error occurs
435454
if (error instanceof Error) {

0 commit comments

Comments
 (0)