Skip to content

Commit cc5b270

Browse files
authored
feat: comment body output (#410)
* feat: comment body output Signed-off-by: Rishav Dhar <[email protected]> * add comment-body to test tf echo output Signed-off-by: Rishav Dhar <[email protected]> * unique eot identifers for multiline github outputs Signed-off-by: Rishav Dhar <[email protected]> * comment out comment-body Signed-off-by: Rishav Dhar <[email protected]> * undo Signed-off-by: Rishav Dhar <[email protected]> * oops Signed-off-by: Rishav Dhar <[email protected]> * try from manumagalhaes.medium.com/c228727722f8 Signed-off-by: Rishav Dhar <[email protected]> * retry Signed-off-by: Rishav Dhar <[email protected]> * drop echo Signed-off-by: Rishav Dhar <[email protected]> * what now Signed-off-by: Rishav Dhar <[email protected]> * retry with printf instead of echo Signed-off-by: Rishav Dhar <[email protected]> * replace echo with printf in tests echo outputs Signed-off-by: Rishav Dhar <[email protected]> * drop echo again Signed-off-by: Rishav Dhar <[email protected]> * constraint tests temp Signed-off-by: Rishav Dhar <[email protected]> * comment out comment_body to github_output Signed-off-by: Rishav Dhar <[email protected]> * ok Signed-off-by: Rishav Dhar <[email protected]> * try result<<EORESULTTFVIAPR Signed-off-by: Rishav Dhar <[email protected]> * now try diff<<EODIFFTFVIAPR Signed-off-by: Rishav Dhar <[email protected]> * surely Signed-off-by: Rishav Dhar <[email protected]> * echo -e flag Signed-off-by: Rishav Dhar <[email protected]> * i have to take the L Signed-off-by: Rishav Dhar <[email protected]> * reenable tests Signed-off-by: Rishav Dhar <[email protected]> * just in case Signed-off-by: Rishav Dhar <[email protected]> * of course not Signed-off-by: Rishav Dhar <[email protected]> * taking L after L Signed-off-by: Rishav Dhar <[email protected]> --------- Signed-off-by: Rishav Dhar <[email protected]>
1 parent ee2ca59 commit cc5b270

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

Diff for: .github/workflows/tf_tests.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ jobs:
7272
run: |
7373
echo "check-id: ${{ steps.tf.outputs.check-id }}"
7474
echo "command: ${{ steps.tf.outputs.command }}"
75+
echo "comment-body:"
7576
echo "comment-id: ${{ steps.tf.outputs.comment-id }}"
7677
echo "diff: ${{ steps.tf.outputs.diff }}"
7778
echo "exitcode: ${{ steps.tf.outputs.exitcode }}"

Diff for: README.md

+15-14
Original file line numberDiff line numberDiff line change
@@ -245,20 +245,21 @@ For each workflow run, a matrix-friendly job summary with logs is added as a fal
245245

246246
### Outputs
247247

248-
| Type | Name | Description |
249-
| -------- | ------------ | --------------------------------------------- |
250-
| Artifact | `plan-id` | ID of the plan file artifact. |
251-
| Artifact | `plan-url` | URL of the plan file artifact. |
252-
| CLI | `command` | Input of the last TF command. |
253-
| CLI | `diff` | Diff of changes, if present (truncated). |
254-
| CLI | `exitcode` | Exit code of the last TF command. |
255-
| CLI | `result` | Result of the last TF command (truncated). |
256-
| CLI | `summary` | Summary of the last TF command. |
257-
| Workflow | `check-id` | ID of the check run. |
258-
| Workflow | `comment-id` | ID of the PR comment. |
259-
| Workflow | `job-id` | ID of the workflow job. |
260-
| Workflow | `run-url` | URL of the workflow run. |
261-
| Workflow | `identifier` | Unique name of the workflow run and artifact. |
248+
| Type | Name | Description |
249+
| -------- | -------------- | --------------------------------------------- |
250+
| Artifact | `plan-id` | ID of the plan file artifact. |
251+
| Artifact | `plan-url` | URL of the plan file artifact. |
252+
| CLI | `command` | Input of the last TF command. |
253+
| CLI | `diff` | Diff of changes, if present (truncated). |
254+
| CLI | `exitcode` | Exit code of the last TF command. |
255+
| CLI | `result` | Result of the last TF command (truncated). |
256+
| CLI | `summary` | Summary of the last TF command. |
257+
| Workflow | `check-id` | ID of the check run. |
258+
| Workflow | `comment-body` | Body of the PR comment. |
259+
| Workflow | `comment-id` | ID of the PR comment. |
260+
| Workflow | `job-id` | ID of the workflow job. |
261+
| Workflow | `run-url` | URL of the workflow run. |
262+
| Workflow | `identifier` | Unique name of the workflow run and artifact. |
262263

263264
</br>
264265

Diff for: action.yml

+8-10
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,7 @@ runs:
303303
# Parse the tf.console.txt file, truncated for character limit.
304304
console=$(head --bytes=42000 tf.console.txt)
305305
if [[ ${#console} -eq 42000 ]]; then console="${console}"$'\n…'; fi
306-
{ echo 'result<<EOTFVIAPR'
307-
echo "$console"
308-
echo EOTFVIAPR
309-
} >> "$GITHUB_OUTPUT"
306+
echo "result<<EORESULTTFVIAPR"$'\n'"$console"$'\n'EORESULTTFVIAPR >> "$GITHUB_OUTPUT"
310307
311308
# Parse the tf.console.txt file for the summary.
312309
summary=$(awk '/^(Error:|Plan:|Apply complete!|No changes.|Success)/ {line=$0} END {if (line) print line; else print "View output."}' tf.console.txt)
@@ -334,10 +331,7 @@ runs:
334331
# Parse diff of changes, truncated for character limit.
335332
diff_truncated=$(head --bytes=24000 tf.diff.txt)
336333
if [[ ${#diff_truncated} -eq 24000 ]]; then diff_truncated="${diff_truncated}"$'\n…'; fi
337-
{ echo 'diff<<EOTFVIAPR'
338-
echo "$diff_truncated"
339-
echo EOTFVIAPR
340-
} >> "$GITHUB_OUTPUT"
334+
echo "diff<<EODIFFTFVIAPR"$'\n'"$diff_truncated"$'\n'EODIFFTFVIAPR >> "$GITHUB_OUTPUT"
341335
342336
diff="
343337
<details><summary>Diff of ${diff_count} ${diff_change}.</summary>
@@ -362,7 +356,7 @@ runs:
362356
if [[ "$tag_actor" == "true" ]]; then handle="@"; else handle=""; fi
363357
364358
# Collate body content.
365-
body=$(cat <<EOTFVIAPR
359+
body=$(cat <<EOBODYTFVIAPR
366360
<!-- placeholder-1 -->
367361
\`\`\`fish
368362
${command}
@@ -383,11 +377,12 @@ runs:
383377
<!-- placeholder-5 -->
384378
<!-- ${{ steps.identifier.outputs.name }} -->
385379
<!-- placeholder-6 -->
386-
EOTFVIAPR
380+
EOBODYTFVIAPR
387381
)
388382
389383
# Post output to job summary.
390384
echo "$body" >> $GITHUB_STEP_SUMMARY
385+
echo "comment_body<<EOCOMMENTTFVIAPR"$'\n'"$body"$'\n'EOCOMMENTTFVIAPR >> "$GITHUB_OUTPUT"
391386
392387
# Post PR comment if configured and PR exists.
393388
if [[ "$create_comment" == "true" && "${{ steps.identifier.outputs.pr }}" != "0" ]]; then
@@ -431,6 +426,9 @@ outputs:
431426
command:
432427
description: "Input of the last TF command."
433428
value: ${{ steps.post.outputs.command }}
429+
comment-body:
430+
description: "Body of the PR comment."
431+
value: ${{ steps.post.outputs.comment_body }}
434432
comment-id:
435433
description: "ID of the PR comment."
436434
value: ${{ steps.post.outputs.comment_id }}

0 commit comments

Comments
 (0)