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: ability to hide previous comments & fix for summary issue #65

Merged
merged 82 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
1bccc23
feat: always add plan results to summary if enabled
DeWildeDaan Aug 30, 2024
d239fde
feat: adding extra debug info
DeWildeDaan Aug 30, 2024
b6eeba3
fix: commenting out exit for testing purposes
DeWildeDaan Aug 30, 2024
77bff9a
fix: removing await key
DeWildeDaan Aug 30, 2024
9cb79ee
fix: removing await key
DeWildeDaan Aug 30, 2024
0f4fcae
Merge pull request #1 from DeWildeDaan/always-add-to-summary
DeWildeDaan Aug 30, 2024
3b7c09b
fix: adding built code
DeWildeDaan Aug 30, 2024
4fd95a5
Merge pull request #2 from DeWildeDaan/always-add-to-summary
DeWildeDaan Aug 30, 2024
c3370e3
feat: adding built code to pr
DeWildeDaan Aug 30, 2024
9faeea9
feat: adding built code to pr
DeWildeDaan Aug 30, 2024
4a927cd
Adding compiled dist.
DeWildeDaan Aug 30, 2024
e09af47
Merge pull request #3 from DeWildeDaan/always-add-to-summary
DeWildeDaan Aug 30, 2024
1a22039
fix: moving pr comment code to pull request check and removing exits
DeWildeDaan Aug 30, 2024
164f966
Merge branch 'always-add-to-summary' of https://github.com/DeWildeDaa…
DeWildeDaan Aug 30, 2024
8d08237
Adding compiled dist.
DeWildeDaan Aug 30, 2024
f5ab41f
Merge pull request #4 from DeWildeDaan/always-add-to-summary
DeWildeDaan Aug 30, 2024
b26c189
fix: adding bool flag to add comment instead of exiting early
DeWildeDaan Aug 30, 2024
167d60f
Merge branch 'always-add-to-summary' of https://github.com/DeWildeDaa…
DeWildeDaan Aug 30, 2024
65c0db7
Adding compiled dist.
DeWildeDaan Aug 30, 2024
2c90bca
Merge pull request #5 from DeWildeDaan/always-add-to-summary
DeWildeDaan Aug 30, 2024
02f77ca
feat: adding function to minimize previous comment
DeWildeDaan Aug 30, 2024
75ab909
feat: adding function to minimize previous comment
DeWildeDaan Aug 30, 2024
b1541d2
Adding compiled dist.
DeWildeDaan Aug 30, 2024
e4d5212
Merge branch 'main' into minimize-prev-comment
DeWildeDaan Aug 30, 2024
bf2f912
Adding compiled dist.
DeWildeDaan Aug 30, 2024
4c17489
feat: adding function to minimize previous comment
DeWildeDaan Aug 30, 2024
289e1aa
Merge branch 'minimize-prev-comment' of https://github.com/DeWildeDaa…
DeWildeDaan Aug 30, 2024
7c39ee1
Adding compiled dist.
DeWildeDaan Aug 30, 2024
fe78e91
feat: adding function to minimize previous comment
DeWildeDaan Aug 30, 2024
3ce2ee2
Adding compiled dist.
DeWildeDaan Aug 30, 2024
2c08121
feat: adding function to minimize previous comment
DeWildeDaan Aug 30, 2024
fbefd81
Merge branch 'minimize-prev-comment' of https://github.com/DeWildeDaa…
DeWildeDaan Aug 30, 2024
d9d6788
Adding compiled dist.
DeWildeDaan Aug 30, 2024
5af492f
feat: adding function to minimize previous comment
DeWildeDaan Aug 30, 2024
5996320
Merge branch 'minimize-prev-comment' of https://github.com/DeWildeDaa…
DeWildeDaan Aug 30, 2024
8620242
Adding compiled dist.
DeWildeDaan Aug 30, 2024
6b4f11b
feat: adding function to minimize previous comment
DeWildeDaan Aug 30, 2024
1cd5cb8
Merge branch 'minimize-prev-comment' of https://github.com/DeWildeDaa…
DeWildeDaan Aug 30, 2024
236fa59
Adding compiled dist.
DeWildeDaan Aug 30, 2024
b986932
feat: adding function to minimize previous comment
DeWildeDaan Aug 30, 2024
70685cc
Adding compiled dist.
DeWildeDaan Aug 30, 2024
ec7855d
feat: adding logs
DeWildeDaan Aug 30, 2024
7cb3248
Adding compiled dist.
DeWildeDaan Aug 30, 2024
14cf6f0
feat: adding logs
DeWildeDaan Aug 30, 2024
064f94a
feat: adding comment hider function
DeWildeDaan Aug 30, 2024
263e03d
feat: adding comment hider function
DeWildeDaan Aug 30, 2024
5e1531a
feat: adding comment hider function
DeWildeDaan Aug 30, 2024
9e64129
Adding compiled dist.
DeWildeDaan Aug 30, 2024
06a660f
feat: adding better logging
DeWildeDaan Aug 30, 2024
e69fa4b
Merge branch 'minimize-prev-comment' of https://github.com/DeWildeDaa…
DeWildeDaan Aug 30, 2024
ab4b553
Adding compiled dist.
DeWildeDaan Aug 30, 2024
05b69b5
feat: adding better logging
DeWildeDaan Aug 30, 2024
9730c18
Adding compiled dist.
DeWildeDaan Aug 30, 2024
04cc637
feat: testing async
DeWildeDaan Aug 30, 2024
90607db
Merge branch 'minimize-prev-comment' of https://github.com/DeWildeDaa…
DeWildeDaan Aug 30, 2024
03f1811
feat: testing async
DeWildeDaan Aug 30, 2024
f47c162
Adding compiled dist.
DeWildeDaan Aug 30, 2024
db1cb98
feat: testing async
DeWildeDaan Aug 30, 2024
4d7b695
Merge branch 'minimize-prev-comment' of https://github.com/DeWildeDaa…
DeWildeDaan Aug 30, 2024
6973ae2
Adding compiled dist.
DeWildeDaan Aug 30, 2024
fcf29fa
feat: removed async
DeWildeDaan Aug 30, 2024
9351d8a
Adding compiled dist.
DeWildeDaan Aug 30, 2024
ac12014
feat: added test and bool to hide previous comments
DeWildeDaan Aug 30, 2024
5d10b59
Adding compiled dist.
DeWildeDaan Aug 30, 2024
a047219
feat: added test
DeWildeDaan Aug 30, 2024
ac10916
Merge branch 'minimize-prev-comment' of https://github.com/DeWildeDaa…
DeWildeDaan Aug 30, 2024
b7f9c85
feat: added test
DeWildeDaan Aug 30, 2024
fdeb39b
refactor: cleanup
DeWildeDaan Aug 30, 2024
6aa3043
docs: updated docs
DeWildeDaan Aug 30, 2024
e708f8c
Adding compiled dist.
DeWildeDaan Aug 30, 2024
41fbafd
docs: updated docs
DeWildeDaan Aug 30, 2024
c896a8f
Merge branch 'minimize-prev-comment' of https://github.com/DeWildeDaa…
DeWildeDaan Aug 30, 2024
8f1bc34
refactor: cleanup
DeWildeDaan Aug 30, 2024
6ca28e7
Adding compiled dist.
DeWildeDaan Aug 30, 2024
a368f7f
Merge pull request #6 from DeWildeDaan/minimize-prev-comment
DeWildeDaan Aug 30, 2024
acd2f6e
docs: updating docs
DeWildeDaan Aug 30, 2024
5b46d6e
Merge branch 'minimize-prev-comment' of https://github.com/DeWildeDaa…
DeWildeDaan Aug 30, 2024
3b4238b
Merge pull request #7 from DeWildeDaan/minimize-prev-comment
DeWildeDaan Aug 30, 2024
4454bb3
chore: removed action commiting the dist folder
DeWildeDaan Aug 30, 2024
7455df2
Merge pull request #8 from DeWildeDaan/minimize-prev-comment
DeWildeDaan Aug 30, 2024
3ddbf38
chore: removed ref on checkout step
DeWildeDaan Aug 30, 2024
83826f0
Merge pull request #9 from DeWildeDaan/minimize-prev-comment
DeWildeDaan Aug 30, 2024
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
11 changes: 11 additions & 0 deletions .github/workflows/action-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ jobs:
test-data/tf_test2.json
test-data/tf_test3.json

- name: Test PR comment hiding
uses: ./
with:
json-file: |
test-data/tf_test.json
test-data/tf_test2.json
test-data/tf_test3.json
hide-previous-comments: true
comment-header: "Same as previous but previous comment should be hidden."


- name: Test PR Comment Expand feature
uses: ./
with:
Expand Down
83 changes: 77 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,73 @@ Implementing this Action is _super_ simple and the comments are consise and easy
- Display changes in a Terraform plan without posting larger sections of the plan change log. This approach will, in most cases, avoid the situation where plan contents are too large for a single PR comment.
- Collapsed as a summary by default, when expanded, the comment is broken up into sections for deletion, creation, and resource changes. The changes are also color-coded to help draw attention to each proposed modification.
- This JavaScript GitHub Action runs directly on a host runner and executes faster than a Docker container Action.
- Possibility to add the output to your workflow summary.
- Possibility to hide previous comments generated by this action.
- Possibility to not create any comments in case there are no infrastructure changes.
- Customize the header and the footer of the generated output.

### Example Comment
![terraform-changes](./assets/terraform-changes.png)

## Inputs

## `expand-comment`
### `json-file`

**Optional** Defaults to `tfplan.json`

- The location of the JSON file created by running `terraform show -no-color -json tfplan.plan > tfplan.json` (Or whatever you choose to name your plan or json outputs)

- Multiple files can be provided using a text block.

### `github-token`

**Optional** Boolean defaults to `${{github.token}}`

- Used to authenticate with the GitHub API.

### `expand-comment`

**Optional** Boolean defaults to `false`

- Will expand the changes in comments by default rather than having them collapsed beneath the summary

### `json-file`
### `include-plan-job-summary`

**Optional** Defaults to `tfplan.json`
**Optional** Defaults to `false`

- The location of the JSON file created by running `terraform show -no-color -json tfplan.plan > tfplan.json` (Or whatever you choose to name your plan or json outputs)
- Will write the plan output to the workflow summary.

- Multiple files can be provided using a text block.
- The workflow summary will still be set when running this action outside of a PR context.

### `comment-header`

**Optional** Defaults to `Terraform Plan Changes`

- Will set the header of the PR comment and/or workflow summary.

### `comment-footer`

**Optional** Defaults to `""`

- Will set a footer of the PR comment and/or workflow summary.

### `include-workflow-link`

**Optional** Defaults to `false`

- Will include a link back to the workflow in the PR comment and/or workflow summary.

### `quiet`

**Optional** Defaults to `false`

- Will not create a PR comment when there are no infrastructure changes.

### `hide-previous-comments`

**Optional** Defaults to `false`

- Will hide/minimize all previous comments generated by this action.

## Example usage
Single plan file:
Expand Down Expand Up @@ -61,6 +109,29 @@ with:
#### Example Job Summary Output
![Plan output job summary](assets/plan-output-job-summary.png)

## Example usage with OpenTofu

To use this action with OpenTofu you need to initialize OpenTofu without the wrapper, like discussed in the `known issues` below.

**You also need to convert the planfile to a JSON planfile using the `tofu show -json` command.**

```yaml
- uses: opentofu/setup-opentofu@v1
with:
tofu_wrapper: false

- name: Create planfile
run: tofu plan -no-color -out=./.planfile

- name: Convert planfile to JSON planfile
run: tofu show -json ./.planfile >> ./my-planfile.json

- name: Create PR comment
uses: liatrio/[email protected]
with:
json-file: my-planfile.json
```

## Terraform Configuration / Known Issues
#### Known issue when including the [Terraform Wrapper script](https://github.com/hashicorp/setup-terraform#inputs)
- Execution may error with `Error: Unexpected token c in JSON at position 1`
Expand All @@ -78,7 +149,7 @@ with:
### Contributions are welcome!
If you'd like to suggest changes, feel free to submit a Pull Request or [open an issue](https://github.com/liatrio/terraform-change-pr-commenter/issues/new).

Otherwise if things aren't working as expected, please [open a new issue](https://github.com/liatrio/terraform-change-pr-commenter/issues/new). Pleae include code references, a description of the issue, and expected behavior.
Otherwise if things aren't working as expected, please [open a new issue](https://github.com/liatrio/terraform-change-pr-commenter/issues/new). Please include code references, a description of the issue, and expected behavior.

---
![CodeQL Security Scan](https://github.com/liatrio/terraform-change-pr-commenter/actions/workflows/codeql-analysis.yml/badge.svg?branch=main)
Expand Down
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ inputs:
expand-comment:
description: If true, expand the details comment by default
required: false
default: "false"
default: false
include-plan-job-summary:
description: If true, add the results of the plan to the workflow job summary
required: false
default: "false"
default: false
comment-header:
description: Header to use for the comment
required: false
Expand All @@ -36,6 +36,10 @@ inputs:
description: Skips the comment if there are no changes
required: false
default: false
hide-previous-comments:
description: Hides privious comments on the PR
required: false
default: false
runs:
using: node20
main: dist/index.js
Loading