Skip to content

Commit

Permalink
add a debug option
Browse files Browse the repository at this point in the history
  • Loading branch information
USA-RedDragon committed Jul 2, 2024
1 parent af4abb4 commit 0ba1d88
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
13 changes: 13 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
Expand All @@ -60,6 +69,10 @@ try {
}
}

if (debug) {
core.info(`Patterns: "${patterns}"`);
}

extraValues = { ...value };
delete extraValues.branch;
delete extraValues.tag;
Expand Down

0 comments on commit 0ba1d88

Please sign in to comment.