diff --git a/.github/workflows/plan.yml b/.github/workflows/plan.yml index 37f7d21..5f450f3 100644 --- a/.github/workflows/plan.yml +++ b/.github/workflows/plan.yml @@ -59,7 +59,7 @@ jobs: - name: Terraform Plan id: plan run: | - out="$(terraform plan -no-color)" + out="$(terraform plan -no-color | grep -v -E '^(module\..+|Reading|Read complete|Refreshing state)')" out="${out//'%'/'%25'}" out="${out//$'\n'/'%0A'}" out="${out//$'\r'/'%0D'}" @@ -71,8 +71,12 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const output = `#### Terraform Plan 📖 - \`${{ steps.plan.outcome }}\` + const issue_number = context.issue.number; + const owner = context.repo.owner; + const repo = context.repo.repo; + const commentIdentifier = ''; + const newCommentBody = `#### Terraform Plan 📖 + ${commentIdentifier}
Show Plan \`\`\`terraform @@ -81,9 +85,30 @@ jobs:
`; - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: output + // Get existing comments + const { data: comments } = await github.rest.issues.listComments({ + owner, + repo, + issue_number }); + + // Find existing comment + const existingComment = comments.find(comment => comment.body.includes(commentIdentifier)); + + if (existingComment) { + // Update existing comment + await github.rest.issues.updateComment({ + owner, + repo, + comment_id: existingComment.id, + body: newCommentBody + }); + } else { + // Create new comment + await github.rest.issues.createComment({ + owner, + repo, + issue_number, + body: newCommentBody + }); + } \ No newline at end of file