From 74044faec7410f940b36a73e70146f8b16fc19e6 Mon Sep 17 00:00:00 2001 From: Thomas Gorham Date: Fri, 2 Feb 2024 12:00:19 -0800 Subject: [PATCH] pass json through to output --- src/run.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/run.ts b/src/run.ts index 64e4164..3e019bf 100644 --- a/src/run.ts +++ b/src/run.ts @@ -103,12 +103,28 @@ type ExecRes = { stderr: string } +const printJSONLines = (s: string): void => { + const lines = s.split(`\n`).filter((line) => line.length > 0) + for (const line of lines) { + if (line.startsWith(`::`)) { + core.info(line) + } + + try { + const obj = JSON.parse(line) + core.setOutput('json', JSON.stringify(obj, null, 2)) + } catch (err) { + core.info(line) + } + } +} + const printOutput = (res: ExecRes): void => { if (res.stdout) { - core.info(res.stdout) + printJSONLines(res.stdout) } if (res.stderr) { - core.info(res.stderr) + printJSONLines(res.stderr) } } @@ -137,8 +153,9 @@ async function runLint(lintPath: string, patchPath: string): Promise { .trim() .split(",") .filter((f) => f.length > 0) - .filter((f) => !f.startsWith(`github-actions`)) + .filter((f) => !f.startsWith(`github-actions`) && !f.startsWith(`json`)) .concat("github-actions") + .concat("json") .join(",") addedArgs.push(`--out-format=${formats}`)