Skip to content

Commit

Permalink
retry
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 72418bc commit 66e34a5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 34 deletions.
21 changes: 20 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,12 @@ runs:
- name: Print TF plan outline
if: inputs.plan_outline == 'true'
shell: bash
run: echo "${{ steps.plan_outline.outputs.stdout }}"
run: |
echo "${{ steps.plan_outline.outputs.stdout }}"
# Create an outline from lines starting with ' # ' while removing the prefix for the first 12000 characters.
echo 'tf_plan_outline<<EOTF' >> $GITHUB_OUTPUT
echo "${{ steps.plan_outline.outputs.stdout }}" | grep -E '^ # ' | sed 's/^ # //' | head -c 12000 >> $GITHUB_OUTPUT
echo 'EOTF' >> $GITHUB_OUTPUT
# If "-tf=plan" is successful, then upload the TF plan file as a zipped
# repository artifact with a unique identifier for later use.
Expand Down Expand Up @@ -341,6 +346,19 @@ runs:
echo "$tf_fmt_raw" | head -c 6000 >> $GITHUB_OUTPUT
echo 'EOTF' >> $GITHUB_OUTPUT
# Create an outline from lines starting with ' # ' while removing the
# prefix for the first 12000 characters.
if [ "${{ steps.plan_outline.outcome }}" != "skipped" ]
then
tf_plan_outline_raw=$(cat <<'EOTF'
${{ steps.plan_outline.outputs.stdout }}
EOTF
)
echo 'tf_plan_outline<<EOTF' >> $GITHUB_OUTPUT
echo "$tf_plan_outline_raw" | grep -E '^ # ' | sed 's/^ # //' | head -c 12000 >> $GITHUB_OUTPUT
echo 'EOTF' >> $GITHUB_OUTPUT
fi
# Add or update PR comment with rendered TF output before exiting.
- name: Comment TF output
id: pr_comment
Expand All @@ -354,6 +372,7 @@ runs:
tf_fmt: ${{ steps.render.outputs.tf_fmt }}
tf_output: ${{ steps.render.outputs.tf_output }}
tf_plan_id: ${{ steps.arguments.outputs.tf_plan_id }}
tf_plan_outline: ${{ steps.render.outputs.tf_plan_outline }}
with:
retries: 3
script: await require(`${process.env.GITHUB_ACTION_PATH}/scripts/comment_tf_output.js`)({ github, context, core, exec });
Expand Down
42 changes: 9 additions & 33 deletions scripts/comment_tf_output.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,15 @@ ${process.env.tf_fmt}
repo: context.repo.repo,
});

// 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>
// `;
// }
// Display the TFplan outline.
const comment_outline = `
<details><summary>Outline of changes.</summary>
\`\`\`hcl
${process.env.tf_plan_outline}
\`\`\`
</details>
`;

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

0 comments on commit 66e34a5

Please sign in to comment.