From edbe1946712d62a9600598b2d2bdf8ef7bd8540b Mon Sep 17 00:00:00 2001
From: Okesanya Odunayo <94924061+DrInTech22@users.noreply.github.com>
Date: Wed, 11 Dec 2024 02:51:24 +0100
Subject: [PATCH] add pr comment update
---
.github/workflows/terraform-plan.yml | 48 +++++++++++++++++++++-------
1 file changed, 37 insertions(+), 11 deletions(-)
diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml
index c765091..fb68492 100644
--- a/.github/workflows/terraform-plan.yml
+++ b/.github/workflows/terraform-plan.yml
@@ -93,15 +93,41 @@ jobs:
--github-token=${{ github.token }} \
--pull-request=${{ github.event.pull_request.number }} \
--behavior=update
- - name: Comment PR
- uses: thollander/actions-comment-pull-request@v3
+ - name: Update PR Comment
+ uses: actions/github-script@v6
+ if: github.event_name == 'pull_request'
+ env:
+ PLAN: ${{ steps.plan.outcome }}
with:
- file-path: /tmp/tfplan.txt
- pr-number: ${{ github.event.pull_request.number }}
- comment-tag: comment-output
- - name: Comment PR
- uses: thollander/actions-comment-pull-request@v3
- with:
- file-path: /tmp/infracost-new.txt
- pr-number: ${{ github.event.pull_request.number }}
- comment-tag: comment-output
\ No newline at end of file
+ github-token: ${{ secrets.GITHUB_TOKEN }}
+ script: |
+ const fs = require('fs');
+ const plan = fs.readFileSync('/tmp/tfplan.txt', 'utf8');
+ const infracost = fs.readFileSync('/tmp/infracost-new.txt', 'utf8');
+
+ const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
+ #### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
+
+ Show Plan
+
+ \`\`\`hcl
+ ${plan}
+ \`\`\`
+
+
+
+ #### New Infracost Breakdown 💰
+ Show Breakdown
+ \`\`\`
+ ${infracost}
+ \`\`\`
+
+
+ *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
+ })
\ No newline at end of file