From f71c7a93c52720efddde2ec9014a5caf76c199ff Mon Sep 17 00:00:00 2001 From: pgijsbertsen <117165507+pgijsbertsen@users.noreply.github.com> Date: Wed, 18 Feb 2026 22:17:39 +0100 Subject: [PATCH 1/2] always comment --- .forgejo/workflows/tofu-plan-k8s-wheatley.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.forgejo/workflows/tofu-plan-k8s-wheatley.yaml b/.forgejo/workflows/tofu-plan-k8s-wheatley.yaml index b1cfa72..b2efbe7 100644 --- a/.forgejo/workflows/tofu-plan-k8s-wheatley.yaml +++ b/.forgejo/workflows/tofu-plan-k8s-wheatley.yaml @@ -55,6 +55,7 @@ jobs: - name: Add comment id: comment + if: always() env: COMMENT_BODY: | ### ${{forge.workflow}} From 344b5344ea3534019b5ea17cebf50bdf81bd58ce Mon Sep 17 00:00:00 2001 From: pgijsbertsen <117165507+pgijsbertsen@users.noreply.github.com> Date: Wed, 18 Feb 2026 22:19:01 +0100 Subject: [PATCH 2/2] enable templates comment --- .forgejo/workflows/tofu-plan-templates.yaml | 70 +++++++++++++++++++-- 1 file changed, 64 insertions(+), 6 deletions(-) diff --git a/.forgejo/workflows/tofu-plan-templates.yaml b/.forgejo/workflows/tofu-plan-templates.yaml index a28e9b7..3ce63a5 100644 --- a/.forgejo/workflows/tofu-plan-templates.yaml +++ b/.forgejo/workflows/tofu-plan-templates.yaml @@ -3,12 +3,12 @@ name: tofu plan k8s-wheatley on: workflow_dispatch: workflow_call: - # pull_request: - # branches: - # - main - # paths: - # - pve01.wheatley.in/templates/** - # - .forgejo/workflows/tofu-plan-templates.yaml + pull_request: + branches: + - main + paths: + - pve01.wheatley.in/templates/** + - .forgejo/workflows/tofu-plan-templates.yaml jobs: tofu-plan-k8s-wheatley: @@ -24,12 +24,18 @@ 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 with: tofu_version: 1.11.5 + - name: Install deps + run: | + apt update + apt install -y jq + - name: OpenTofu Init id: init run: tofu init --upgrade @@ -46,3 +52,55 @@ jobs: id: plan run: tofu plan -no-color continue-on-error: true + + - name: Add comment + id: comment + if: always() + env: + COMMENT_BODY: | + ### ${{forge.workflow}} + #### ${{ steps.fmt.outcome == 'success' && '✅' || '❌' }} OpenTofu Format and Style 🖌 + #### ${{ steps.init.outcome == 'success' && '✅' || '❌' }} OpenTofu Initialization ⚙️ + #### ${{ steps.validate.outcome == 'success' && '✅' || '❌' }} OpenTofu Validation 🤖 +
Validation Output + + ``` + ${{ steps.validate.outputs.stdout }} + ``` + +
+ + #### ${{ steps.plan.outcome == 'success' && '✅' || '❌' }} OpenTofu Plan 📖 + +
Show Plan + + ``` + ${{ steps.plan.outputs.stdout }} + ``` + +
+ run: | + payload=$(jq -Rs --arg body "$COMMENT_BODY" '{body: $body}' <<< "$COMMENT_BODY") + + existing_comment=$(curl -s \ + -H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \ + "${{ forge.api_url }}/repos/${{ forge.repository }}/issues/$PR_NUMBER/comments") + comment_id=$(echo "$existing_comment" | jq -r \ + '.[] | select(.body | test("${{ forge.workflow }}")) | .id' | head -n 1) + + + if [ -n "${comment_id}" ] && [ "${comment_id}" != "null" ]; then + echo "Found comment with id ${comment_id}, updating..." && \ + curl -s -X PATCH \ + -H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \ + -H "Content-Type: application/json" \ + "${{ forge.api_url }}/repos/${{ forge.repository }}/issues/comments/${comment_id}" \ + -d "$payload" + else + echo "Creating new comment..." && \ + curl -s -X POST \ + -H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \ + -H "Content-Type: application/json" \ + "${{ forge.api_url }}/repos/${{ forge.repository }}/issues/$PR_NUMBER/comments" \ + -d "$payload" + fi