infrastructure/.forgejo/workflows/tofu-plan-k8s-wheatley.yaml

138 lines
4.2 KiB
YAML
Raw Normal View History

2025-11-28 15:34:52 +01:00
---
2025-11-28 20:53:52 +01:00
name: tofu plan k8s-wheatley
2025-11-28 15:34:52 +01:00
on:
workflow_dispatch:
workflow_call:
pull_request:
branches:
- main
2026-02-18 12:54:32 +01:00
paths:
- pve01.wheatley.in/k8s-wheatley/**
2026-02-18 13:59:13 +01:00
- .forgejo/workflows/tofu-plan-k8s-wheatley.yaml
2025-11-29 11:15:28 +01:00
2025-11-28 15:34:52 +01:00
jobs:
2025-11-28 20:53:52 +01:00
tofu-plan-k8s-wheatley:
2025-11-28 15:34:52 +01:00
runs-on: docker
2026-01-19 15:35:38 +01:00
defaults:
run:
2026-02-18 12:54:32 +01:00
working-directory: pve01.wheatley.in/k8s-wheatley
2026-01-19 15:35:38 +01:00
permissions:
pull-requests: write
2026-02-18 13:43:17 +01:00
env:
AWS_S3_ENDPOINT: ${{ secrets.AWS_S3_ENDPOINT }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
2026-02-18 13:47:39 +01:00
TF_VAR_proxmox_endpoint: ${{ secrets.PROXMOX_ENDPOINT }}
TF_VAR_proxmox_api_token: ${{ secrets.PROXMOX_API_TOKEN }}
2026-02-18 16:52:11 +01:00
PR_NUMBER: ${{ forge.event.pull_request.number }}
2025-11-28 15:34:52 +01:00
steps:
2026-02-18 13:59:13 +01:00
- uses: https://github.com/actions/checkout@v4
- uses: https://github.com/opentofu/setup-opentofu@v1
with:
tofu_version: 1.11.5
2026-02-18 12:43:31 +01:00
2026-02-18 17:01:23 +01:00
- name: Install deps
run: |
2026-02-18 17:16:46 +01:00
apt update
2026-02-18 17:01:23 +01:00
apt install -y jq
2026-02-18 13:59:13 +01:00
- name: OpenTofu Init
id: init
run: tofu init --upgrade
2025-11-29 12:15:12 +01:00
2026-02-18 13:59:13 +01:00
- name: OpenTofu Format
id: fmt
run: tofu fmt -check
2025-11-28 15:34:52 +01:00
2026-02-18 13:59:13 +01:00
- name: OpenTofu Validate
id: validate
run: tofu validate -no-color
2025-11-28 15:34:52 +01:00
2026-02-18 13:59:13 +01:00
- name: OpenTofu Plan
id: plan
run: tofu plan -no-color
continue-on-error: true
2026-02-18 16:52:11 +01:00
- name: Fetch existing comments
id: fetch
run: |
2026-02-18 17:19:51 +01:00
set -euxo pipefail
echo "PR_NUMBER: $PR_NUMBER"
echo "Forgejo URL: ${{ forge.server_url }}"
echo "Repo: ${{ forge.repository }}"
url="${{ forge.server_url }}/api/v1/repos/${{ forge.repository }}/issues/$PR_NUMBER/comments"
echo "Requesting: $url"
response=$(curl -sS -w "\nHTTP_STATUS:%{http_code}\n" \
2026-02-18 16:52:11 +01:00
-H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \
2026-02-18 17:19:51 +01:00
"$url")
http_status=$(echo "$response" | sed -n 's/HTTP_STATUS://p')
body=$(echo "$response" | sed '/HTTP_STATUS:/d')
echo "HTTP status: $http_status"
2026-02-18 16:52:11 +01:00
2026-02-18 17:19:51 +01:00
if [ "$http_status" != "200" ]; then
echo "Forgejo API call failed"
exit 1
fi
echo "Parsing JSON…"
echo "$body" | jq .
comment_id=$(echo "$body" | jq -r \
2026-02-18 16:52:11 +01:00
'.[] | select(.body | test("OpenTofu Format and Style")) | .id' | head -n 1)
2026-02-18 17:19:51 +01:00
echo "Matched comment_id: '$comment_id'"
if [ -z "$comment_id" ] || [ "$comment_id" = "null" ]; then
echo "No existing comment found matching marker"
exit 1
2026-02-18 17:16:17 +01:00
fi
2026-02-18 17:19:51 +01:00
echo "Found comment id: $comment_id"
echo "comment_id=$comment_id" >> "$GITHUB_OUTPUT"
2026-02-18 16:52:11 +01:00
- name: Upsert comment
2026-02-18 16:58:51 +01:00
id: comment
2026-02-18 16:52:11 +01:00
env:
COMMENT_BODY: |
`#### OpenTofu Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### OpenTofu Initialization ⚙️\`${{ steps.init.outcome }}\`
#### OpenTofu Validation 🤖\`${{ steps.validate.outcome }}\`
<details><summary>Validation Output</summary>
\`\`\`\n
${{ steps.validate.outputs.stdout }}
\`\`\`
</details>
#### OpenTofu Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
run: |
2026-02-18 17:11:13 +01:00
if [ -n "${{ steps.fetch.outputs.comment_id }}" ] && [ "${{ steps.fetch.outputs.comment_id }}" != "null" ]; then
2026-02-18 16:52:11 +01:00
curl -s -X PATCH \
-H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \
-H "Content-Type: application/json" \
2026-02-18 17:11:13 +01:00
"${{ forge.server_url }}/api/v1/repos/${{ forge.repository }}/issues/comments/${{ steps.fetch.outputs.comment_id }}" \
2026-02-18 16:52:11 +01:00
-d "{\"body\":\"$COMMENT_BODY\"}"
else
curl -s -X POST \
-H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \
-H "Content-Type: application/json" \
2026-02-18 16:58:51 +01:00
"${{ forge.server_url }}/api/v1/repos/${{ forge.repository }}/issues/$PR_NUMBER/comments" \
2026-02-18 16:52:11 +01:00
-d "{\"body\":\"$COMMENT_BODY\"}"
fi