From 0ba1d886cd97ad7ce047131de6792b10dc626a6d Mon Sep 17 00:00:00 2001 From: Jacob McSwain Date: Tue, 2 Jul 2024 16:29:54 -0500 Subject: [PATCH] add a debug option --- action.yml | 8 ++++++-- dist/index.js | 13 +++++++++++++ src/index.js | 13 +++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index db9089c..94d79d9 100644 --- a/action.yml +++ b/action.yml @@ -13,11 +13,15 @@ inputs: description: List/CSV of jobs to deploy per environment. required: false default: app + debug: + description: Adds debug logging to the output + required: false + default: "false" outputs: matrix: description: Matrix JSON to be used in another job. count: description: Count of matching environments. runs: - using: 'node20' - main: 'dist/index.js' + using: "node20" + main: "dist/index.js" diff --git a/dist/index.js b/dist/index.js index 41ce623..b20aacd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36925,10 +36925,15 @@ const parseDynamicList = (s) => { try { const envs = js_yaml.load(core.getInput("envs")); const jobs = parseDynamicList(core.getInput("jobs")); + const debug = core.getInput("debug") === 'true'; const matrix = { include: [] }; // Split GitHub ref into type (heads, tags) and ref const [, type, ref] = github.context.ref.match(/^refs\/(.+)\/(.+)$/); + if (debug) { + core.info(`Type: "${type}"`); + core.info(`Ref: "${ref}"`); + } let count = 0; for (let [env, value] of Object.entries(envs)) { @@ -36941,20 +36946,24 @@ try { patterns = value; } else { if (value.type === "temp") { + if (debug) core.info(`Temporary Environment`) // Temp environments enabled if (github.context.eventName === "pull_request") { const prEvent = github.context.payload; let matches = false; if (value.label) { + if (debug) core.info(`Pull Request Event: Labelled: ${value.label}`) matches = prEvent.pull_request.labels.some( (label) => label.name === value.label, ); } else if (value.removed_label) { + if (debug) core.info(`Pull Request Event: Unlabelled: ${value.removed_label}`) matches = !prEvent.pull_request.labels.some( (label) => label.name === value.removed_label, ); } if (matches) { + if (debug) core.info(`Labels match: ${value.label}`) patterns = ref; value.name = `${value.name || toTitleCase(env)} #${prEvent.number}`; env += prEvent.number; @@ -36973,6 +36982,10 @@ try { } } + if (debug) { + core.info(`Patterns: "${patterns}"`); + } + extraValues = { ...value }; delete extraValues.branch; delete extraValues.tag; diff --git a/src/index.js b/src/index.js index 4cae47e..baeba96 100644 --- a/src/index.js +++ b/src/index.js @@ -12,10 +12,15 @@ import { try { const envs = yaml.load(core.getInput("envs")); const jobs = parseDynamicList(core.getInput("jobs")); + const debug = core.getInput("debug") === 'true'; const matrix = { include: [] }; // Split GitHub ref into type (heads, tags) and ref const [, type, ref] = github.context.ref.match(/^refs\/(.+)\/(.+)$/); + if (debug) { + core.info(`Type: "${type}"`); + core.info(`Ref: "${ref}"`); + } let count = 0; for (let [env, value] of Object.entries(envs)) { @@ -28,20 +33,24 @@ try { patterns = value; } else { if (value.type === "temp") { + if (debug) core.info(`Temporary Environment`) // Temp environments enabled if (github.context.eventName === "pull_request") { const prEvent = github.context.payload; let matches = false; if (value.label) { + if (debug) core.info(`Pull Request Event: Labelled: ${value.label}`) matches = prEvent.pull_request.labels.some( (label) => label.name === value.label, ); } else if (value.removed_label) { + if (debug) core.info(`Pull Request Event: Unlabelled: ${value.removed_label}`) matches = !prEvent.pull_request.labels.some( (label) => label.name === value.removed_label, ); } if (matches) { + if (debug) core.info(`Labels match: ${value.label}`) patterns = ref; value.name = `${value.name || toTitleCase(env)} #${prEvent.number}`; env += prEvent.number; @@ -60,6 +69,10 @@ try { } } + if (debug) { + core.info(`Patterns: "${patterns}"`); + } + extraValues = { ...value }; delete extraValues.branch; delete extraValues.tag;