Skip to content

Commit

Permalink
(fix) Use Step Outputs to Pass stdout and stderr easier (#23)
Browse files Browse the repository at this point in the history
* (fix) Passing using file to passing using outputs

* (fix) Spacing on plan directive

* (fix) Check the raw plan for changes
  • Loading branch information
ebachle committed Jul 4, 2022
1 parent b70cf96 commit dbba313
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@ runs:
run: |
if [[ '${{ github.ref }}' != 'refs/heads/${{ inputs.apply-branch }}' ]]; then
cd ${{ inputs.path }}
if terraform plan -no-color -lock-timeout=60s -lock=${{ inputs.lock-for-plan }} >${GITHUB_WORKSPACE}/plan.out 2>&1; then
if terraform plan -no-color -lock-timeout=60s -lock=${{ inputs.lock-for-plan }}; then
echo "::set-output name=plan-outcome::success"
else
echo "::set-output name=plan-outcome::failure"
fi
cat ${GITHUB_WORKSPACE}/plan.out
fi
- name: Create/Update Comment
Expand All @@ -114,10 +113,12 @@ runs:
const run_url = process.env.GITHUB_SERVER_URL + '/' + process.env.GITHUB_REPOSITORY + '/actions/runs/' + process.env.GITHUB_RUN_ID
const run_link = '<a href="' + run_url + '">Actions</a>.'
const fs = require('fs')
const plan_file = fs.readFileSync('plan.out', 'utf8')
const plan = plan_file.length > 65000 ? " ..." + plan_file.toString().substring(plan_file.length - 65000, plan_file.length) : plan_file
const truncated_message = plan_file.length > 65000 ? "Output is too long and was truncated. You can read full Plan in " + run_link + "<br /><br />" : ""
const raw_plan = `
${{ steps.plan.outputs.stdout }}
${{ steps.plan.outputs.stderr }}
`
const plan = raw_plan.length > 65000 ? " ..." + raw_plan.toString().substring(raw_plan.length - 65000, raw_plan.length) : raw_plan
const truncated_message = raw_plan.length > 65000 ? "Output is too long and was truncated. You can read full Plan in " + run_link + "<br /><br />" : ""
const commentTitle = `### Terraform Status ${tag}`;
const commentContent = `
Expand All @@ -128,7 +129,9 @@ runs:
<details>
<summary>Show Plan</summary>
\`\`\`${plan}\`\`\`
\`\`\`
${plan}
\`\`\`
</details>
${truncated_message}
Expand All @@ -147,7 +150,7 @@ runs:
comment.body.includes(commentTitle)
);
if (commentContent.includes("No changes.")) {
if (raw_plan.includes("No changes.")) {
if (githubActionsBotComment) {
await github.issues.deleteComment({
comment_id: githubActionsBotComment.id,
Expand Down

0 comments on commit dbba313

Please sign in to comment.