Skip to content

Commit

Permalink
feat: adds an input for showing the full list of changed resources in…
Browse files Browse the repository at this point in the history
… the action output (#68)

* feat: adds an input for showing the full list of changed resources in the action output

* chore: result of yarn run v1.22.21
$ ncc build index.js --out dist --license licenses.txt
ncc: Version 0.33.4
ncc: Compiling file index.js into CJS
 36kB  dist/licenses.txt
900kB  dist/index.js
936kB  [723ms] - ncc 0.33.4
Done in 0.99s.
  • Loading branch information
jburns24 authored Sep 3, 2024
1 parent 1f1413b commit 815d669
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Implementing this Action is _super_ simple and the comments are consise and easy

## Features

- 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.
- 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.
Expand Down Expand Up @@ -80,13 +80,19 @@ Implementing this Action is _super_ simple and the comments are consise and easy

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

### `log-changed-resources`

**Optional** Defaults to `true`

- Logs all the changed resources found in the plan to the action output.

## Example usage
Single plan file:
```yaml
uses: liatrio/[email protected]
with:
json-file: my-tfplan.json
expand-comment: 'true'
expand-comment: 'true'
```
Multiple plan files:
```yaml
Expand All @@ -104,7 +110,7 @@ with:
expand-comment: 'true'
include-plan-job-summary: 'true'
```
**Note:**
**Note:**
- When `include-plan-job-summary = true`, if the action is executed in non-Pull Request workflows, the plan output will also be posted to the job summary of that run. If you do not wish to have this behavior, apply conditional logic to your workflow file.
#### Example Job Summary Output
![Plan output job summary](assets/plan-output-job-summary.png)
Expand All @@ -119,7 +125,7 @@ To use this action with OpenTofu you need to initialize OpenTofu without the wra
- uses: opentofu/setup-opentofu@v1
with:
tofu_wrapper: false
- name: Create planfile
run: tofu plan -no-color -out=./.planfile
Expand Down Expand Up @@ -151,7 +157,7 @@ If you'd like to suggest changes, feel free to submit a Pull Request or [open an

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)
![Release](https://github.com/liatrio/terraform-change-pr-commenter/actions/workflows/release.yml/badge.svg?branch=main)
[![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ inputs:
description: Hides privious comments on the PR
required: false
default: false
log-changed-resources:
description: Log the changed resources in action output
required: false
default: "true"
runs:
using: node20
main: dist/index.js
8 changes: 6 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12829,6 +12829,7 @@ const commentFooter = core.getMultilineInput('comment-footer');
const quietMode = core.getBooleanInput('quiet');
const includeLinkToWorkflow = core.getBooleanInput('include-workflow-link');
const hidePreviousComments = core.getBooleanInput('hide-previous-comments');
const logChangedResources = core.getBooleanInput('log-changed-resources');

const workflowLink = includeLinkToWorkflow ? `
[Workflow: ${context.workflow}](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId })
Expand Down Expand Up @@ -12871,7 +12872,9 @@ const output = () => {
return resource.change.actions != ["no-op"];
})

console.log("changed_resources", changed_resources)
if (logChangedResources) {
console.log("changed_resources", changed_resources)
}
if (Array.isArray(resource_changes) && resource_changes.length > 0) {
const resources_to_create = [],
resources_to_update = [],
Expand Down Expand Up @@ -12906,7 +12909,7 @@ const output = () => {
}
}
// the body must be indented at the start otherwise
// there will be formatting error when comment is
// there will be formatting error when comment is
// showed on GitHub
body += `
${commentHeader}
Expand Down Expand Up @@ -13054,6 +13057,7 @@ try {
} catch (error) {
core.setFailed(error.message);
}

})();

module.exports = __webpack_exports__;
Expand Down
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const commentFooter = core.getMultilineInput('comment-footer');
const quietMode = core.getBooleanInput('quiet');
const includeLinkToWorkflow = core.getBooleanInput('include-workflow-link');
const hidePreviousComments = core.getBooleanInput('hide-previous-comments');
const logChangedResources = core.getBooleanInput('log-changed-resources');

const workflowLink = includeLinkToWorkflow ? `
[Workflow: ${context.workflow}](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId })
Expand Down Expand Up @@ -55,7 +56,9 @@ const output = () => {
return resource.change.actions != ["no-op"];
})

console.log("changed_resources", changed_resources)
if (logChangedResources) {
console.log("changed_resources", changed_resources)
}
if (Array.isArray(resource_changes) && resource_changes.length > 0) {
const resources_to_create = [],
resources_to_update = [],
Expand Down Expand Up @@ -90,7 +93,7 @@ const output = () => {
}
}
// the body must be indented at the start otherwise
// there will be formatting error when comment is
// there will be formatting error when comment is
// showed on GitHub
body += `
${commentHeader}
Expand Down Expand Up @@ -237,4 +240,4 @@ try {

} catch (error) {
core.setFailed(error.message);
}
}

0 comments on commit 815d669

Please sign in to comment.