diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7c60f7e..17b1f59 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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)
diff --git a/dist/index.js b/dist/index.js
index a40e039..aa9715d 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -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}\`
- 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.
-
+
+ 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.
+
${details("create", resources_to_create, "+")}
${details("delete", resources_to_delete, "-")}
${details("update", resources_to_update, "!")}
${details("replace", resources_to_replace, "+")}
There were no changes done to the infrastructure.
+` + 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; } @@ -11776,6 +11790,7 @@ try { } catch (error) { core.setFailed(error.message); } + })(); module.exports = __webpack_exports__; diff --git a/package.json b/package.json index fc87565..270bbf2 100644 --- a/package.json +++ b/package.json @@ -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": {