Skip to content

Commit 5eb0889

Browse files
Kludgy4borchero
andauthored
feat: Output markdown as Step Summary and Text, and Optionally Output PR comment (#35)
Co-authored-by: Oliver Borchert <[email protected]>
1 parent 95fee01 commit 5eb0889

File tree

7 files changed

+127
-53
lines changed

7 files changed

+127
-53
lines changed

.github/workflows/e2e.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ jobs:
3636
token: ${{ github.token }}
3737
planfile: .planfile
3838
working-directory: tests/ci/1-change
39+
skip-comment: ${{ github.event.pull_request.head.repo.full_name != 'borchero/terraform-plan-comment' }}

README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,30 @@ GitHub Action to post the output of `terraform plan` to a pull request comment.
4444
4545
## Parameters
4646
47-
This action provides a few input parameters that allow for customization:
47+
```yaml
48+
- uses: borchero/terraform-plan-comment@v2
49+
with:
50+
# GitHub token for API access (Required)
51+
token: ""
52+
53+
# Path to the Terraform plan file (Required)
54+
planfile: ""
55+
56+
# Command to execute the Terraform binary
57+
terraform-cmd: terraform
58+
59+
# Directory where Terraform should be called
60+
working-directory: "."
61+
62+
# Header for the PR comment
63+
header: 📝 Terraform Plan
64+
65+
# Skip comments for empty plans
66+
skip-empty: false
67+
68+
# Skip PR comment creation entirely. When enabled, the plan will still be available in the step summary
69+
skip-comment: false
70+
```
4871
4972
### `token` (required)
5073

@@ -76,3 +99,18 @@ The directory where the Terraform binary ought to be called. Defaults to `$GITHU
7699

77100
The header that is used for the pull request comment posted by this action. Changing the default allows to distinguish
78101
multiple Terraform runs: each sticky pull request comment is identified by its header.
102+
103+
### `skip-empty`
104+
105+
Whether to skip posting a pull request comment when no changes need to be performed. Defaults to `false`.
106+
107+
### `skip-comment`
108+
109+
Whether to skip posting a pull request comment entirely. When enabled, the plan will still be available in the step
110+
summary.
111+
112+
## Outputs
113+
114+
This action provides the following output:
115+
116+
- `markdown`: The raw markdown output of the terraform plan

action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ inputs:
2727
description: Whether to skip posting a pull request comment when no changes need to be performed.
2828
required: true
2929
default: "false"
30+
skip-comment:
31+
description: Whether to skip posting a pull request comment entirely.
32+
required: true
33+
default: "false"
34+
outputs:
35+
markdown:
36+
description: The raw markdown output of the terraform plan
3037
runs:
3138
using: node20
3239
main: dist/index.js

dist/index.js

Lines changed: 49 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/comment.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function renderBody(plan: RenderedPlan): string {
4444
return body
4545
}
4646

47-
export function renderComment({
47+
export function renderMarkdown({
4848
plan,
4949
header,
5050
includeFooter
@@ -59,9 +59,10 @@ export function renderComment({
5959
// Build footer
6060
let footer = ''
6161
if (includeFooter === undefined || includeFooter === true) {
62-
footer =
63-
`\n\n---\n\n_Triggered by @${github.context.actor},` +
64-
` Commit: \`${(github.context.payload as PullRequestEvent).pull_request.head.sha}\`_`
62+
footer = `\n\n---\n\n_Triggered by @${github.context.actor}`
63+
if (github.context.eventName === 'pull_request') {
64+
footer += `, Commit: \`${(github.context.payload as PullRequestEvent).pull_request.head.sha}\`_`
65+
}
6566
}
6667

6768
return `## ${header}\n\n${body}${footer}`

0 commit comments

Comments
 (0)