diff --git a/.github/workflows/tf_tests.yml b/.github/workflows/tf_tests.yml index 1728d81e..ba94f06d 100644 --- a/.github/workflows/tf_tests.yml +++ b/.github/workflows/tf_tests.yml @@ -54,11 +54,11 @@ jobs: cli_uses: ${{ matrix.cli_uses }} command_input: ${{ format('-tf={0} -chdir={1}', github.event.action != 'closed' && 'plan' || 'apply', matrix.test) }} cache_plugins: false - recreate_comment: true - name: Echo TF run: | echo "command: ${{ steps.tf.outputs.command }}" + echo "comment_id: ${{ steps.tf.outputs.comment_id }}" echo "plan_id: ${{ steps.tf.outputs.plan_id }}" echo "tf_fmt: ${{ steps.tf.outputs.tf_fmt }}" echo "tf_output: ${{ steps.tf.outputs.tf_output }}" diff --git a/action.yml b/action.yml index f9bd7158..1affeb17 100644 --- a/action.yml +++ b/action.yml @@ -337,7 +337,7 @@ runs: tf_plan_id: ${{ steps.arguments.outputs.tf_plan_id }} with: retries: 3 - script: await require(`${process.env.GITHUB_ACTION_PATH}/scripts/comment_tf_output.js`)({ github, context }); + script: await require(`${process.env.GITHUB_ACTION_PATH}/scripts/comment_tf_output.js`)({ github, context, core }); # Remove PR comment reaction to indicate that the workflow has ended. - name: Remove reaction diff --git a/scripts/comment_tf_output.js b/scripts/comment_tf_output.js index 976e4d95..d3ad3b10 100644 --- a/scripts/comment_tf_output.js +++ b/scripts/comment_tf_output.js @@ -1,4 +1,4 @@ -module.exports = async ({ github, context }) => { +module.exports = async ({ github, context, core }) => { // Display latest TF change summary as the output header. const comment_summary = process.env.tf_output .split("\n") @@ -68,28 +68,29 @@ ${process.env.tf_output} // reflect the latest TF output, otherwise create a new comment by default. // If recreate_comment is true, then delete the existing comment // before creating a new one. - let pr_comment; if (bot_comment) { if (process.env.recreate_comment === "true") { await github.rest.issues.deleteComment({ ...comment_parameters, comment_id: bot_comment.id, }); - pr_comment = await github.rest.issues.createComment({ + const { data: pr_comment } = await github.rest.issues.createComment({ ...comment_parameters, issue_number: context.issue.number, }); + core.setOutput("id", pr_comment.id); } else { - pr_comment = await github.rest.issues.updateComment({ + const { data: pr_comment } = await github.rest.issues.updateComment({ ...comment_parameters, comment_id: bot_comment.id, }); + core.setOutput("id", pr_comment.id); } } else { - pr_comment = await github.rest.issues.createComment({ + const { data: pr_comment } = await github.rest.issues.createComment({ ...comment_parameters, issue_number: context.issue.number, }); + core.setOutput("id", pr_comment.id); } - core.setOutput("id", pr_comment.id); };