From 3f2c189ca6511184c397516bbeb9d20cbbe60848 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 2 Jan 2025 11:42:06 +1100 Subject: [PATCH] fix: Always Output Step Summary, Change Output Name, and Changed PR Context Detection --- action.yml | 2 +- dist/index.js | 18 +++++++++--------- src/index.ts | 29 ++++++++++++++--------------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/action.yml b/action.yml index 7f21770..b4886df 100644 --- a/action.yml +++ b/action.yml @@ -28,7 +28,7 @@ inputs: required: true default: "false" outputs: - plan-markdown: + markdown: description: The raw markdown output of the terraform plan runs: using: node20 diff --git a/dist/index.js b/dist/index.js index 5c9ddd8..b118f6f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -30697,21 +30697,21 @@ async function run() { workingDirectory: inputs.workingDirectory }) ); + const planMarkdown = await core.group("Render plan diff markdown", () => { + const markdown = renderMarkdown({ plan, header: inputs.header }); + core.setOutput("markdown", markdown); + return Promise.resolve(markdown); + }); + await core.group("Adding plan to step summary", async () => { + await core.summary.addRaw(planMarkdown).write(); + }); if (!inputs.skipEmpty || !planIsEmpty(plan)) { - const prContext = "pull_request" in github2.context.payload; - const planMarkdown = await core.group("Render plan diff markdown", () => { - const markdown = renderMarkdown({ plan, header: inputs.header }); - core.setOutput("plan-markdown", markdown); - return Promise.resolve(markdown); - }); + const prContext = github2.context.eventName === "pull_request"; if (prContext === true) { await core.group("Render comment", () => { return createOrUpdateComment({ octokit, content: planMarkdown }); }); } - await core.group("Adding plan to step summary", async () => { - await core.summary.addRaw(planMarkdown).write(); - }); } } async function main() { diff --git a/src/index.ts b/src/index.ts index c8134d2..aa24d60 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,27 +24,26 @@ async function run() { }) ) - if (!inputs.skipEmpty || !planIsEmpty(plan)) { - const prContext = 'pull_request' in github.context.payload - - // 3) Render the plan diff markdown and set it as output - const planMarkdown = await core.group('Render plan diff markdown', () => { - const markdown = renderMarkdown({ plan, header: inputs.header }) - core.setOutput('plan-markdown', markdown) - return Promise.resolve(markdown) - }) + // 3) Render the plan diff markdown and set it as output + const planMarkdown = await core.group('Render plan diff markdown', () => { + const markdown = renderMarkdown({ plan, header: inputs.header }) + core.setOutput('markdown', markdown) + return Promise.resolve(markdown) + }) + + // 4) Add plan to GitHub step summary + await core.group('Adding plan to step summary', async () => { + await core.summary.addRaw(planMarkdown).write() + }) - // 4) Post comment with markdown (if applicable) + if (!inputs.skipEmpty || !planIsEmpty(plan)) { + // 5) Post comment with markdown (if applicable) + const prContext = github.context.eventName === 'pull_request' if (prContext === true) { await core.group('Render comment', () => { return createOrUpdateComment({ octokit, content: planMarkdown }) }) } - - // 5) Add plan to GitHub step summary - await core.group('Adding plan to step summary', async () => { - await core.summary.addRaw(planMarkdown).write() - }) } }