From 6683e0febcf95d85b01ee3b20988fc858dd4b5e8 Mon Sep 17 00:00:00 2001 From: pgijsbertsen <117165507+pgijsbertsen@users.noreply.github.com> Date: Wed, 18 Feb 2026 16:52:11 +0100 Subject: [PATCH] add comment --- .../workflows/tofu-plan-k8s-wheatley.yaml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/.forgejo/workflows/tofu-plan-k8s-wheatley.yaml b/.forgejo/workflows/tofu-plan-k8s-wheatley.yaml index 701952a..2f6b7d1 100644 --- a/.forgejo/workflows/tofu-plan-k8s-wheatley.yaml +++ b/.forgejo/workflows/tofu-plan-k8s-wheatley.yaml @@ -24,6 +24,7 @@ jobs: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} TF_VAR_proxmox_endpoint: ${{ secrets.PROXMOX_ENDPOINT }} TF_VAR_proxmox_api_token: ${{ secrets.PROXMOX_API_TOKEN }} + PR_NUMBER: ${{ forge.event.pull_request.number }} steps: - uses: https://github.com/actions/checkout@v4 - uses: https://github.com/opentofu/setup-opentofu@v1 @@ -46,3 +47,57 @@ jobs: id: plan run: tofu plan -no-color continue-on-error: true + + - name: Fetch existing comments + id: fetch + run: | + response=$(curl -s \ + -H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \ + "${{ forge.server_url }}/api/v1/repos/${{ forge.repository }}/issues/$PR_NUMBER/comments") + + comment_id=$(echo "$response" | jq -r \ + '.[] | select(.body | test("OpenTofu Format and Style")) | .id' | head -n 1) + + echo "::set-output name=comment_id::$comment_id" + + - name: Set variables + run: | + echo "COMMENT_ID=${{ steps.fetch.outputs.comment_id }}" >> $FORGEJO_ENV + + - name: Upsert comment + env: + COMMENT_BODY: | + `#### OpenTofu Format and Style 🖌\`${{ steps.fmt.outcome }}\` + #### OpenTofu Initialization ⚙️\`${{ steps.init.outcome }}\` + #### OpenTofu Validation 🤖\`${{ steps.validate.outcome }}\` +
Validation Output + + \`\`\`\n + ${{ steps.validate.outputs.stdout }} + \`\`\` + +
+ + #### OpenTofu Plan 📖\`${{ steps.plan.outcome }}\` + +
Show Plan + + \`\`\`\n + ${process.env.PLAN} + \`\`\` + +
+ run: | + if [ -n "$COMMENT_ID" ] && [ "$COMMENT_ID" != "null" ]; then + curl -s -X PATCH \ + -H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \ + -H "Content-Type: application/json" \ + "$FORGEJO_URL/api/v1/repos/${{ forge.repository }}/issues/comments/$COMMENT_ID" \ + -d "{\"body\":\"$COMMENT_BODY\"}" + else + curl -s -X POST \ + -H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \ + -H "Content-Type: application/json" \ + "$FORGEJO_URL/api/v1/repos/${{ forge.repository }}/issues/$PR_NUMBER/comments" \ + -d "{\"body\":\"$COMMENT_BODY\"}" + fi