Skip to content

Commit

Permalink
retry in action.yaml instead now
Browse files Browse the repository at this point in the history
Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com>
  • Loading branch information
rdhar committed May 19, 2024
1 parent 629db76 commit 972a194
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 34 deletions.
14 changes: 14 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ inputs:
fmt_enable:
description: Boolean flag to enable TF fmt command and display diff of changes.
default: true
plan_outline:
description: Boolean flag to output TF plan outline of changes.
default: true
recreate_comment:
description: Boolean flag to recreate PR comment on update instead of editing the existing one.
default: true
Expand Down Expand Up @@ -258,6 +261,17 @@ runs:
shell: bash
run: ${{ env.TF_CLI_USES }} ${{ steps.arguments.outputs.arg_chdir }} plan -out=tfplan ${{ steps.arguments.outputs.arg_compact_warnings }} ${{ steps.arguments.outputs.arg_concise }} ${{ steps.arguments.outputs.arg_destroy }} ${{ steps.arguments.outputs.arg_lock }} ${{ steps.arguments.outputs.arg_lock_timeout }} ${{ steps.arguments.outputs.arg_parallelism }} ${{ steps.arguments.outputs.arg_refresh }} ${{ steps.arguments.outputs.arg_refresh_only }} ${{ steps.arguments.outputs.arg_replace }} ${{ steps.arguments.outputs.arg_target }} ${{ steps.arguments.outputs.arg_var_file }}

# Generate an outline of changes from the TF plan file.
- name: TF plan outline
if: inputs.plan_outline == 'true'
id: plan_outline
shell: bash
run: ${{ env.TF_CLI_USES }} ${{ steps.arguments.outputs.arg_chdir }} show -no-color tfplan

- name: Print TF plan outline
if: inputs.plan_outline == 'true'
run: echo "${{ steps.plan_outline.outputs.stdout }}"

# If "-tf=plan" is successful, then upload the TF plan file as a zipped
# repository artifact with a unique identifier for later use.
- name: Upload TF plan file
Expand Down
65 changes: 31 additions & 34 deletions scripts/comment_tf_output.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,39 @@ ${process.env.tf_fmt}
repo: context.repo.repo,
});

// If [tf] of process.env.tf_command object equals "plan", then parse the TFplan file.
console.log("process.env.tf_command.tf:", JSON.parse(process.env.tf_command).tf);

// Parse the TFplan file to create an outline of changes.
let comment_outline = "";
if (JSON.parse(process.env.tf_command).tf === "plan") {
// Parse TFplan file.
let tfplan = "";
const data_handler = (data) => {
tfplan += data.toString();
};
const options = {
listeners: {
stdout: data_handler,
stderr: data_handler,
},
};
await exec.exec(process.env.TF_CLI, [`-chdir=${process.env.TF_CHDIR}`, "show", "-no-color", "tfplan"], options);

// Create an outline from lines starting with ' # ' while removing the prefix for the first 12000 characters.
const changed_lines = tfplan
.split("\n")
.filter((line) => line.startsWith(" # "))
.map((line) => line.slice(4))
.slice(0, 12000);

// Display the TFplan outline.
comment_outline = `
<details><summary>Outline of changes.</summary>
\`\`\`hcl
${changed_lines.join("\n")}
\`\`\`
</details>
`;
}
// if (JSON.parse(process.env.tf_command).tf === "plan") {
// // Parse TFplan file.
// let tfplan = "";
// const data_handler = (data) => {
// tfplan += data.toString();
// };
// const options = {
// listeners: {
// stdout: data_handler,
// stderr: data_handler,
// },
// };
// await exec.exec(process.env.TF_CLI, [`-chdir=${process.env.TF_CHDIR}`, "show", "-no-color", "tfplan"], options);

// // Create an outline from lines starting with ' # ' while removing the prefix for the first 12000 characters.
// const changed_lines = tfplan
// .split("\n")
// .filter((line) => line.startsWith(" # "))
// .map((line) => line.slice(4))
// .slice(0, 12000);

// // Display the TFplan outline.
// comment_outline = `
// <details><summary>Outline of changes.</summary>

// \`\`\`hcl
// ${changed_lines.join("\n")}
// \`\`\`
// </details>
// `;
// }

// Display the: TF command, TF output, and workflow authorip.
const comment_output = `
Expand Down

0 comments on commit 972a194

Please sign in to comment.