From 627cfcc689ff59dd76db697109bfd45bb6ad5382 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 27 Nov 2026 08:12:23 -0400 Subject: [PATCH] Honor the report name from JSON scan configs --- entrypoint.sh | 18 ++++++++++++++++-- test/e2e/entrypoint.test.js | 5 ++--- test/helpers/run-entrypoint.js | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index bf42ec6..cb2fc69 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -68,7 +68,22 @@ fi # KICS appends the extension itself, so a trailing .json would only confuse the file lookup INPUT_OUTPUT_NAME="${INPUT_OUTPUT_NAME%.json}" -[[ ! -z "$INPUT_OUTPUT_NAME" ]] && set -- "$@" --output-name "$INPUT_OUTPUT_NAME" +cd "$GITHUB_WORKSPACE" +if [ -n "$INPUT_OUTPUT_NAME" ]; then + set -- "$@" --output-name "$INPUT_OUTPUT_NAME" +elif [ -n "$INPUT_CONFIG_PATH" ]; then + # KICS still reads the config itself and reports any config errors. + INPUT_OUTPUT_NAME=$(node -e ' + const { readFileSync } = require("node:fs"); + try { + const name = JSON.parse(readFileSync(process.argv[1], "utf8"))?.["output-name"]; + if (typeof name === "string" && !/[\/\\\r\n\0]/.test(name)) { + process.stdout.write(name.replace(/\.json$/, "")); + } + } catch {} + ' -- "$INPUT_CONFIG_PATH") +fi +export INPUT_OUTPUT_NAME CP_PATH="./${INPUT_OUTPUT_NAME:-results}.json" if [ ! -z "$INPUT_OUTPUT_PATH" ]; then @@ -81,7 +96,6 @@ fi #################### # Run KICS Scan # #################### -cd "$GITHUB_WORKSPACE" echo "${DATETIME} - INF : about to scan directory $INPUT_PATH" echo "${DATETIME} - INF : kics command kics -p $INPUT_PATH $OUTPUT_FORMATS_PARAM $PLATFORM_TYPE_PARAM $EXCLUDE_CATEGORIES_PARAM $EXCLUDE_RESULTS_PARAM $EXCLUDE_SEVERITIES_PARAM $EXCLUDE_QUERIES_PARAM $EXCLUDE_GITIGNORE $VERBOSE_PARAM $IGNORE_ON_EXIT_PARAM $FAIL_ON_PARAM $TIMEOUT_PARAM $PROFILING_PARAM $BOM_PARAM $INCLUDE_QUERIES_PARAM $DISABLE_SECRETS_PARAM $DISABLE_FULL_DESCRIPTIONS_PARAM $CLOUD_PROVIDER $*" /app/bin/kics scan --no-progress -p "$INPUT_PATH" $OUTPUT_FORMATS_PARAM $PLATFORM_TYPE_PARAM $EXCLUDE_CATEGORIES_PARAM $EXCLUDE_RESULTS_PARAM $EXCLUDE_SEVERITIES_PARAM $EXCLUDE_QUERIES_PARAM $EXCLUDE_GITIGNORE $VERBOSE_PARAM $IGNORE_ON_EXIT_PARAM $FAIL_ON_PARAM $TIMEOUT_PARAM $PROFILING_PARAM $BOM_PARAM $INCLUDE_QUERIES_PARAM $DISABLE_SECRETS_PARAM $DISABLE_FULL_DESCRIPTIONS_PARAM $CLOUD_PROVIDER "$@" diff --git a/test/e2e/entrypoint.test.js b/test/e2e/entrypoint.test.js index 6cbd4bd..8101658 100644 --- a/test/e2e/entrypoint.test.js +++ b/test/e2e/entrypoint.test.js @@ -7,7 +7,6 @@ const path = require('node:path') const { runEntrypoint, flagValue } = require('../helpers/run-entrypoint') const { startFakeGitHub } = require('../helpers/fake-github') const { kicsResults } = require('../helpers/fixtures') -const { knownBug } = require('../helpers/known-bug') const DEFAULT_QUERIES = '/app/bin/assets/queries' @@ -248,13 +247,13 @@ test('whole action: entrypoint, KICS, JavaScript stage and GitHub', async (t) => assert.equal(fs.existsSync(path.join(run.workspace, 'results.json')), true) }) - await t.test('reports from a config file with a custom output-name are still picked up', knownBug('main.js only reads results.json, so a config with output-name makes the scan fail with ENOENT (#96, #106)'), async (t) => { + await t.test('reports from a config file with a custom output-name are still picked up', async (t) => { const run = await runEntrypoint(t, { runMain: true, results: kicsResults(), resultsName: 'my-results', workspaceFiles: { 'kics.json': JSON.stringify({ 'output-name': 'my-results' }) }, - inputs: { config_path: 'kics.json', enable_jobs_summary: 'true' }, + inputs: { config_path: 'kics.json', output_path: 'reports', enable_jobs_summary: 'true' }, }) assert.match(run.summary, /\| TOTAL \| 4 \|/, run.stdout + run.stderr) }) diff --git a/test/helpers/run-entrypoint.js b/test/helpers/run-entrypoint.js index 1d45270..8ff90df 100644 --- a/test/helpers/run-entrypoint.js +++ b/test/helpers/run-entrypoint.js @@ -47,6 +47,7 @@ exit "\${FAKE_KICS_EXIT:-0}" ` const NODE_SHIM = `#!/bin/bash +if [ "$1" = "-e" ]; then exec "$REAL_NODE" "$@"; fi { echo "cwd=$(pwd)"; echo "args=$*"; echo "KICS_EXIT_CODE=$KICS_EXIT_CODE"; } > "$SANDBOX/node-call.txt" if [ -n "$RUN_MAIN" ]; then exec "$REAL_NODE" "$MAIN_JS"; fi `