Skip to content

Commit

Permalink
chore(release): 1.3.2 [skip ci]
Browse files Browse the repository at this point in the history
## [1.3.2](v1.3.1...v1.3.2) (2022-06-09)

### Bug Fixes

* [#30](#30) empty plan would failed the action ([#31](#31)) ([c4ea052](c4ea052))
  • Loading branch information
semantic-release-bot committed Jun 9, 2022
1 parent c4ea052 commit 4effb80
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 38 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [1.3.2](https://github.com/liatrio/terraform-change-pr-commenter/compare/v1.3.1...v1.3.2) (2022-06-09)


### Bug Fixes

* [#30](https://github.com/liatrio/terraform-change-pr-commenter/issues/30) empty plan would failed the action ([#31](https://github.com/liatrio/terraform-change-pr-commenter/issues/31)) ([c4ea052](https://github.com/liatrio/terraform-change-pr-commenter/commit/c4ea0520ce5c086465dda4da3f75fca6527a60e0))

## [1.3.1](https://github.com/liatrio/terraform-change-pr-commenter/compare/v1.3.0...v1.3.1) (2022-04-29)


Expand Down
89 changes: 52 additions & 37 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11683,55 +11683,69 @@ const context = github.context;
const inputFilenames = core.getMultilineInput('json-file');

const output = () => {
let body = "";
let body = '';
// for each file
for(const file of inputFilenames) {
const resource_changes = JSON.parse(fs.readFileSync(file)).resource_changes;
const resources_to_create = []
, resources_to_update = []
, resources_to_delete = []
, resources_to_replace = []
, resources_unchanged = [];

// for each resource changes
for(const resource of resource_changes) {
const change = resource.change;
const address = resource.address;

switch(change.actions[0]) {
default:
break;
case "no-op":
resources_unchanged.push(address);
break;
case "create":
resources_to_create.push(address);
break;
case "delete":
if(change.actions.length > 1) {
resources_to_replace.push(address);
} else {
resources_to_delete.push(address);
try {
if(Array.isArray(resource_changes) && resource_changes.length > 0) {
const resources_to_create = []
, resources_to_update = []
, resources_to_delete = []
, resources_to_replace = []
, resources_unchanged = [];

// for each resource changes
for(const resource of resource_changes) {
const change = resource.change;
const address = resource.address;

switch(change.actions[0]) {
default:
break;
case "no-op":
resources_unchanged.push(address);
break;
case "create":
resources_to_create.push(address);
break;
case "delete":
if(change.actions.length > 1) {
resources_to_replace.push(address);
} else {
resources_to_delete.push(address);
}
break;
case "update":
resources_to_update.push(address);
break;
}
break;
case "update":
resources_to_update.push(address);
break;
}
}

body += `
}
// the body must be indented at the start otherwise
// there will be formatting error when comment is
// showed on GitHub
body += `
\`${file}\`
<details ${expandDetailsComment ? "open" : ""}>
<summary>
<b>Terraform Plan: ${resources_to_create.length} to be created, ${resources_to_delete.length} to be deleted, ${resources_to_update.length} to be updated, ${resources_to_replace.length} to be replaced, ${resources_unchanged.length} unchanged.</b>
</summary>
<summary>
<b>Terraform Plan: ${resources_to_create.length} to be created, ${resources_to_delete.length} to be deleted, ${resources_to_update.length} to be updated, ${resources_to_replace.length} to be replaced, ${resources_unchanged.length} unchanged.</b>
</summary>
${details("create", resources_to_create, "+")}
${details("delete", resources_to_delete, "-")}
${details("update", resources_to_update, "!")}
${details("replace", resources_to_replace, "+")}
</details>
`
} else {
body += `
\`${file}\`
<p>There were no changes done to the infrastructure.</p>
`
core.info(`"The content of ${file} did not result in a valid array or the array is empty... Skipping."`)
}
} catch (error) {
core.error(`${file} is not a valid JSON file.`);
}
}
return body;
}
Expand Down Expand Up @@ -11776,6 +11790,7 @@ try {
} catch (error) {
core.setFailed(error.message);
}

})();

module.exports = __webpack_exports__;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "terraform-change-pr-commenter",
"version": "1.3.1",
"version": "1.3.2",
"description": "GitHub Action to read changes from Terraform plan JSON, summarize changes, and post them in a GitHub Pull Request Comment",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 4effb80

Please sign in to comment.