Skip to content

Commit

Permalink
try moving from bash to github-script for summary (#882)
Browse files Browse the repository at this point in the history
Co-authored-by: tjololo <1145298+tjololo@users.noreply.github.com>
  • Loading branch information
tjololo and tjololo authored Aug 26, 2024
1 parent 41314b5 commit 464c391
Showing 1 changed file with 39 additions and 36 deletions.
75 changes: 39 additions & 36 deletions actions/terraform/plan/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,47 +141,50 @@ runs:

- name: Terraform Summary
id: action_summary
shell: bash
if: always()
env:
VALIDATE_OUTPUT: ${{ steps.validate.outputs.stdout }}
PLAN_OUTPUT: ${{ steps.plan.outputs.stdout }}
working-directory: ${{ inputs.working_directory }}
run: |
echo "#"" Terraform ${{ inputs.oidc_type }} ${{ inputs.oidc_value }}" >> $GITHUB_STEP_SUMMARY
echo "#### Initialization ⚙️\`${{ steps.init.outcome }}\`" >> $GITHUB_STEP_SUMMARY
echo "#### Format and Style 🖌\`${{ steps.fmt.outcome }}\`" >> $GITHUB_STEP_SUMMARY
echo "#### Validation 🤖\`${{ steps.validate.outcome }}\`" >> $GITHUB_STEP_SUMMARY
echo "<details><summary>Validation Output</summary>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`\n" >> $GITHUB_STEP_SUMMARY
echo "${VALIDATE_OUTPUT}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "#### Plan 📖\`${{ steps.plan.outcome }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "<details><summary>Show Plan</summary>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`\n" >> $GITHUB_STEP_SUMMARY
echo "${PLAN_OUTPUT}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Context | Values |" >> $GITHUB_STEP_SUMMARY
echo "| - | - |" >> $GITHUB_STEP_SUMMARY
echo "| Pusher | @${{ github.actor }} |" >> $GITHUB_STEP_SUMMARY
echo "| Action | \`${{ github.event_name }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Working Directory | \`${{ inputs.working_directory }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| State | \`${{ env.TF_STATE_FILE }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Artifact | \`${{ env.ARTIFACT_KEY }}\` |" >> $GITHUB_STEP_SUMMARY
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// 1. Prep the output
const output = `# Terraform ${{ inputs.oidc_type }} ${{ inputs.oidc_value }}
#### Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Validation 🤖\`${{ steps.validate.outcome }}\`
<details><summary>Validation Output</summary>
\`\`\`\n
${process.env.VALIDATE_OUTPUT}
\`\`\`
</details>
#### Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN_OUTPUT}
\`\`\`
</details>
| Context | Values |
| - | - |
| Pusher | @${{ github.actor }} |
| Action | \`${{ github.event_name }}\` |
| Working Directory | \`${{ inputs.working_directory }}\` |
| State | \`${{ env.TF_STATE_FILE }}\` |
| Artifact | \`${{ env.ARTIFACT_KEY }}\` |`;
// 2. Set the output variable
const fs = require('fs');
fs.writeFileSync('${{ env.tf_actions_working_dir }}/summary.md', output);
core.setOutput('summary', output);
- name: GitHub Issue
id: issue_number
Expand Down

0 comments on commit 464c391

Please sign in to comment.