From 58fa41a10147fcf9315876961aae2176310e3c63 Mon Sep 17 00:00:00 2001 From: Brian DeHamer Date: Thu, 9 May 2024 12:34:14 -0700 Subject: [PATCH] send api errors to gha debug log (#59) Signed-off-by: Brian DeHamer --- dist/index.js | 11 +++++++++++ src/main.ts | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/dist/index.js b/dist/index.js index 6138928f..1a377d14 100644 --- a/dist/index.js +++ b/dist/index.js @@ -79853,11 +79853,19 @@ const COLOR_GRAY = '\x1B[38;5;244m'; const COLOR_DEFAULT = '\x1B[39m'; const ATTESTATION_FILE_NAME = 'attestation.jsonl'; const MAX_SUBJECT_COUNT = 64; +/* istanbul ignore next */ +const logHandler = (level, ...args) => { + // Send any HTTP-related log events to the GitHub Actions debug log + if (level === 'http') { + core.debug(args.join(' ')); + } +}; /** * The main function for the action. * @returns {Promise} Resolves when the action is complete. */ async function run() { + process.on('log', logHandler); // Provenance visibility will be public ONLY if we can confirm that the // repository is public AND the undocumented "private-signing" arg is NOT set. // Otherwise, it will be private. @@ -79910,6 +79918,9 @@ async function run() { core.info(mute(innerErr instanceof Error ? innerErr.toString() : `${innerErr}`)); } } + finally { + process.removeListener('log', logHandler); + } } exports.run = run; const createAttestation = async (subject, predicate, sigstoreInstance) => { diff --git a/src/main.ts b/src/main.ts index 158746a5..f4e08ad3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,11 +19,21 @@ const ATTESTATION_FILE_NAME = 'attestation.jsonl' const MAX_SUBJECT_COUNT = 64 +/* istanbul ignore next */ +const logHandler = (level: string, ...args: unknown[]): void => { + // Send any HTTP-related log events to the GitHub Actions debug log + if (level === 'http') { + core.debug(args.join(' ')) + } +} + /** * The main function for the action. * @returns {Promise} Resolves when the action is complete. */ export async function run(): Promise { + process.on('log', logHandler) + // Provenance visibility will be public ONLY if we can confirm that the // repository is public AND the undocumented "private-signing" arg is NOT set. // Otherwise, it will be private. @@ -98,6 +108,8 @@ export async function run(): Promise { mute(innerErr instanceof Error ? innerErr.toString() : `${innerErr}`) ) } + } finally { + process.removeListener('log', logHandler) } }