Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: comment body output #410

Merged
merged 27 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tf_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
run: |
echo "check-id: ${{ steps.tf.outputs.check-id }}"
echo "command: ${{ steps.tf.outputs.command }}"
echo "comment-body:"
echo "comment-id: ${{ steps.tf.outputs.comment-id }}"
echo "diff: ${{ steps.tf.outputs.diff }}"
echo "exitcode: ${{ steps.tf.outputs.exitcode }}"
Expand Down
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,21 @@ For each workflow run, a matrix-friendly job summary with logs is added as a fal

### Outputs

| Type | Name | Description |
| -------- | ------------ | --------------------------------------------- |
| Artifact | `plan-id` | ID of the plan file artifact. |
| Artifact | `plan-url` | URL of the plan file artifact. |
| CLI | `command` | Input of the last TF command. |
| CLI | `diff` | Diff of changes, if present (truncated). |
| CLI | `exitcode` | Exit code of the last TF command. |
| CLI | `result` | Result of the last TF command (truncated). |
| CLI | `summary` | Summary of the last TF command. |
| Workflow | `check-id` | ID of the check run. |
| Workflow | `comment-id` | ID of the PR comment. |
| Workflow | `job-id` | ID of the workflow job. |
| Workflow | `run-url` | URL of the workflow run. |
| Workflow | `identifier` | Unique name of the workflow run and artifact. |
| Type | Name | Description |
| -------- | -------------- | --------------------------------------------- |
| Artifact | `plan-id` | ID of the plan file artifact. |
| Artifact | `plan-url` | URL of the plan file artifact. |
| CLI | `command` | Input of the last TF command. |
| CLI | `diff` | Diff of changes, if present (truncated). |
| CLI | `exitcode` | Exit code of the last TF command. |
| CLI | `result` | Result of the last TF command (truncated). |
| CLI | `summary` | Summary of the last TF command. |
| Workflow | `check-id` | ID of the check run. |
| Workflow | `comment-body` | Body of the PR comment. |
| Workflow | `comment-id` | ID of the PR comment. |
| Workflow | `job-id` | ID of the workflow job. |
| Workflow | `run-url` | URL of the workflow run. |
| Workflow | `identifier` | Unique name of the workflow run and artifact. |

</br>

Expand Down
18 changes: 8 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,7 @@ runs:
# Parse the tf.console.txt file, truncated for character limit.
console=$(head --bytes=42000 tf.console.txt)
if [[ ${#console} -eq 42000 ]]; then console="${console}"$'\n…'; fi
{ echo 'result<<EOTFVIAPR'
echo "$console"
echo EOTFVIAPR
} >> "$GITHUB_OUTPUT"
echo "result<<EORESULTTFVIAPR"$'\n'"$console"$'\n'EORESULTTFVIAPR >> "$GITHUB_OUTPUT"

# Parse the tf.console.txt file for the summary.
summary=$(awk '/^(Error:|Plan:|Apply complete!|No changes.|Success)/ {line=$0} END {if (line) print line; else print "View output."}' tf.console.txt)
Expand Down Expand Up @@ -334,10 +331,7 @@ runs:
# Parse diff of changes, truncated for character limit.
diff_truncated=$(head --bytes=24000 tf.diff.txt)
if [[ ${#diff_truncated} -eq 24000 ]]; then diff_truncated="${diff_truncated}"$'\n…'; fi
{ echo 'diff<<EOTFVIAPR'
echo "$diff_truncated"
echo EOTFVIAPR
} >> "$GITHUB_OUTPUT"
echo "diff<<EODIFFTFVIAPR"$'\n'"$diff_truncated"$'\n'EODIFFTFVIAPR >> "$GITHUB_OUTPUT"

diff="
<details><summary>Diff of ${diff_count} ${diff_change}.</summary>
Expand All @@ -362,7 +356,7 @@ runs:
if [[ "$tag_actor" == "true" ]]; then handle="@"; else handle=""; fi

# Collate body content.
body=$(cat <<EOTFVIAPR
body=$(cat <<EOBODYTFVIAPR
<!-- placeholder-1 -->
\`\`\`fish
${command}
Expand All @@ -383,11 +377,12 @@ runs:
<!-- placeholder-5 -->
<!-- ${{ steps.identifier.outputs.name }} -->
<!-- placeholder-6 -->
EOTFVIAPR
EOBODYTFVIAPR
)

# Post output to job summary.
echo "$body" >> $GITHUB_STEP_SUMMARY
echo "comment_body<<EOCOMMENTTFVIAPR"$'\n'"$body"$'\n'EOCOMMENTTFVIAPR >> "$GITHUB_OUTPUT"

# Post PR comment if configured and PR exists.
if [[ "$create_comment" == "true" && "${{ steps.identifier.outputs.pr }}" != "0" ]]; then
Expand Down Expand Up @@ -431,6 +426,9 @@ outputs:
command:
description: "Input of the last TF command."
value: ${{ steps.post.outputs.command }}
comment-body:
description: "Body of the PR comment."
value: ${{ steps.post.outputs.comment_body }}
comment-id:
description: "ID of the PR comment."
value: ${{ steps.post.outputs.comment_id }}
Expand Down
Loading