From 815d669c00d3bcb18303a846c49ef49cd2ab19db Mon Sep 17 00:00:00 2001 From: Joshua Date: Tue, 3 Sep 2024 16:05:10 -0700 Subject: [PATCH] feat: adds an input for showing the full list of changed resources in 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. --- README.md | 16 +++++++++++----- action.yml | 4 ++++ dist/index.js | 8 ++++++-- index.js | 9 ++++++--- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 52878cc..9094910 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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/terraform-change-pr-commenter@v1.4.0 with: json-file: my-tfplan.json - expand-comment: 'true' + expand-comment: 'true' ``` Multiple plan files: ```yaml @@ -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) @@ -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 @@ -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) diff --git a/action.yml b/action.yml index 906809b..4b5ccab 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/dist/index.js b/dist/index.js index 220032b..e689dce 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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 }) @@ -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 = [], @@ -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} @@ -13054,6 +13057,7 @@ try { } catch (error) { core.setFailed(error.message); } + })(); module.exports = __webpack_exports__; diff --git a/index.js b/index.js index d6a4015..681b47a 100644 --- a/index.js +++ b/index.js @@ -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 }) @@ -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 = [], @@ -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} @@ -237,4 +240,4 @@ try { } catch (error) { core.setFailed(error.message); -} \ No newline at end of file +}