Skip to content

Commit

Permalink
ci: echo comment_id in tf_tests (#202)
Browse files Browse the repository at this point in the history
* ci: echo comment_id in tf_tests

Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com>

* debug output

Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com>

* fix pr comment id

Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com>

* debug output

Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com>

* fix pr comment output id

Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com>

* fix pr comment id output

Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com>

---------

Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com>
  • Loading branch information
RDhar committed Apr 23, 2024
1 parent b7dce3b commit 4c4eac1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tf_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions scripts/comment_tf_output.js
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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);
};

0 comments on commit 4c4eac1

Please sign in to comment.