Skip to content

Commit

Permalink
Update ci.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiraalA authored Apr 2, 2024
1 parent 82cfec6 commit 8ea3593
Showing 1 changed file with 28 additions and 37 deletions.
65 changes: 28 additions & 37 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,43 +44,34 @@ jobs:
with:
plan: ${{ fromJSON(steps.plan-run.outputs.payload).data.relationships.plan.data.id }}

- name: Update PR
uses: actions/github-script@v7
id: plan-comment
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment => {
return comment.user.type === 'Bot' && comment.body.includes('Terraform Cloud Plan Output')
});
const output = `#### Terraform Cloud Plan Output
\`\`\`
Plan: ${{ steps.plan-output.outputs.add }} to add, ${{ steps.plan-output.outputs.change }} to change, ${{ steps.plan-output.outputs.destroy }} to destroy.
\`\`\`
[Terraform Cloud Plan](${{ steps.plan-run.outputs.run_link }})
`;
if (botComment) {
github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
});
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
});
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
- name: Update Pull Request
uses: actions/github-script@v7
with:
github-token: ${{ secrets.USER_TOKEN }}
script: |
const output = `#### Terraform Format and Style <img draggable="false" role="img" class="emoji" alt="🖌" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/1f58c.svg">\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization <img draggable="false" role="img" class="emoji" alt="🤖" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/1f916.svg">\`${{ steps.init.outcome }}\`
#### Terraform Validation <img draggable="false" role="img" class="emoji" alt="🤖" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/1f916.svg">\`${{ steps.validate.outcome }}\`
#### Terraform Plan <img draggable="false" role="img" class="emoji" alt="📖" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/1f4d6.svg">\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${{ steps.plan.outputs.stdout }}
\`\`\`

</details>

*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;

github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1

- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
Expand Down

0 comments on commit 8ea3593

Please sign in to comment.