Skip to content

Commit

Permalink
chore: add debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
someshkoli committed Mar 15, 2024
1 parent c88f536 commit 9185fcf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
19 changes: 14 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12826,8 +12826,8 @@ const context = github.context;
const inputFilenames = core.getMultilineInput('json-file');
const commentHeader = core.getMultilineInput('comment-header');
const commentFooter = core.getMultilineInput('comment-footer');
const quietMode = core.getMultilineInput('quiet');
const includeLinkToWorkflow = core.getMultilineInput('include-workflow-link');
const quietMode = core.getBooleanInput('quiet');
const includeLinkToWorkflow = core.getBooleanInput('include-workflow-link');


const workflowLink = includeLinkToWorkflow ? `
Expand All @@ -12842,6 +12842,11 @@ const output = () => {
for (const file of inputFilenames) {
const resource_changes = JSON.parse(fs.readFileSync(file)).resource_changes;
try {
let changed_resources = resource_changes.filter((resource) => {
return resource.change.actions != ["no-op"];
})

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 @@ -12892,6 +12897,9 @@ ${details("replace", resources_to_replace, "+")}
${commentFooter.map(a => a == '' ? '\n' : a).join('\n')}
${workflowLink}
`
if (resources_to_create + resources_to_delete + resources_to_update + resources_to_replace == []) {
hasNoChanges = true;
}
} else {
hasNoChanges = true;
console.log("No changes found in the plan. setting hasNoChanges to true.")
Expand Down Expand Up @@ -12930,9 +12938,10 @@ const details = (action, resources, operator) => {
}

try {
let rawOutput = output();
if (includePlanSummary) {
core.info("Adding plan output to job summary")
core.summary.addHeading('Terraform Plan Results').addRaw(output()).write()
core.summary.addHeading('Terraform Plan Results').addRaw(rawOutput).write()
}

if (context.eventName === 'pull_request') {
Expand All @@ -12953,13 +12962,13 @@ try {
}

core.info("Adding comment to PR");
core.info(`Comment: ${output()}`);
core.info(`Comment: ${rawOutput}`);

octokit.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output()
body: rawOutput
});
} catch (error) {
core.setFailed(error.message);
Expand Down
19 changes: 14 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const context = github.context;
const inputFilenames = core.getMultilineInput('json-file');
const commentHeader = core.getMultilineInput('comment-header');
const commentFooter = core.getMultilineInput('comment-footer');
const quietMode = core.getMultilineInput('quiet');
const includeLinkToWorkflow = core.getMultilineInput('include-workflow-link');
const quietMode = core.getBooleanInput('quiet');
const includeLinkToWorkflow = core.getBooleanInput('include-workflow-link');


const workflowLink = includeLinkToWorkflow ? `
Expand All @@ -26,6 +26,11 @@ const output = () => {
for (const file of inputFilenames) {
const resource_changes = JSON.parse(fs.readFileSync(file)).resource_changes;
try {
let changed_resources = resource_changes.filter((resource) => {
return resource.change.actions != ["no-op"];
})

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 @@ -76,6 +81,9 @@ ${details("replace", resources_to_replace, "+")}
${commentFooter.map(a => a == '' ? '\n' : a).join('\n')}
${workflowLink}
`
if (resources_to_create + resources_to_delete + resources_to_update + resources_to_replace == []) {
hasNoChanges = true;
}
} else {
hasNoChanges = true;
console.log("No changes found in the plan. setting hasNoChanges to true.")
Expand Down Expand Up @@ -114,9 +122,10 @@ const details = (action, resources, operator) => {
}

try {
let rawOutput = output();
if (includePlanSummary) {
core.info("Adding plan output to job summary")
core.summary.addHeading('Terraform Plan Results').addRaw(output()).write()
core.summary.addHeading('Terraform Plan Results').addRaw(rawOutput).write()
}

if (context.eventName === 'pull_request') {
Expand All @@ -137,13 +146,13 @@ try {
}

core.info("Adding comment to PR");
core.info(`Comment: ${output()}`);
core.info(`Comment: ${rawOutput}`);

octokit.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output()
body: rawOutput
});
} catch (error) {
core.setFailed(error.message);
Expand Down

0 comments on commit 9185fcf

Please sign in to comment.