All checks were successful
Tofu Plan k8s-wheatley / tofu-plan-k8s-wheatley (pull_request) Successful in 23s
123 lines
3.6 KiB
YAML
123 lines
3.6 KiB
YAML
---
|
|
name: Tofu Plan k8s-wheatley
|
|
on:
|
|
workflow_dispatch:
|
|
workflow_call:
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- pve01.wheatley.in/k8s-wheatley/**
|
|
- .forgejo/workflows/tofu-plan-k8s-wheatley.yaml
|
|
|
|
jobs:
|
|
tofu-plan-k8s-wheatley:
|
|
runs-on: docker
|
|
defaults:
|
|
run:
|
|
working-directory: pve01.wheatley.in/k8s-wheatley
|
|
permissions:
|
|
pull-requests: write
|
|
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 }}
|
|
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
|
|
|
|
- name: OpenTofu Format
|
|
id: fmt
|
|
run: tofu fmt -check
|
|
|
|
- name: OpenTofu Validate
|
|
id: validate
|
|
run: tofu validate -no-color
|
|
|
|
- name: OpenTofu Plan
|
|
id: plan
|
|
run: tofu plan -no-color
|
|
continue-on-error: true
|
|
|
|
- name: Fetch existing comment ID
|
|
id: fetch
|
|
run: |
|
|
response=$(curl -s \
|
|
-H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \
|
|
"${{ forge.api_url }}/repos/${{ forge.repository }}/issues/$PR_NUMBER/comments")
|
|
|
|
comment_id=$(echo "$response" | jq -r \
|
|
'.[] | select(.body | test("${{ forge.workflow }}")) | .id' | head -n 1)
|
|
|
|
echo "$comment_id"
|
|
|
|
- name: Add comment
|
|
id: comment
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
emoji() {
|
|
[ "$1" = "success" ] && echo "✅" || echo "❌"
|
|
}
|
|
|
|
FMT_OUTPUT="$(emoji "${{ steps.fmt.outcome }}") OpenTofu Format and Style"
|
|
INIT_OUTPUT="$(emoji "${{ steps.init.outcome }}") OpenTofu Initialization"
|
|
VALIDATE_OUTPUT="$(emoji "${{ steps.validate.outcome }}") OpenTofu Validation"
|
|
PLAN_OUTPUT="$(emoji "${{ steps.plan.outcome }}") OpenTofu Plan 📖"
|
|
|
|
COMMENT_BODY=$(cat <<EOF
|
|
### ${{ forge.workflow }}
|
|
|
|
${FMT_OUTPUT}
|
|
${INIT_OUTPUT}
|
|
${VALIDATE_OUTPUT}
|
|
|
|
<details><summary>Validation Output</summary>
|
|
|
|
```
|
|
${{ steps.validate.outputs.stdout }}
|
|
```
|
|
|
|
</details>
|
|
|
|
${PLAN_OUTPUT}
|
|
|
|
<details><summary>Show Plan</summary>
|
|
|
|
```
|
|
${{ steps.plan.outputs.stdout }}
|
|
```
|
|
|
|
</details>
|
|
EOF
|
|
)
|
|
|
|
payload=$(jq -Rs --arg body "$COMMENT_BODY" '{body: $body}' <<< "$COMMENT_BODY")
|
|
|
|
if [ -n "${{ steps.fetch.outputs }}" ] && [ "${{ steps.fetch.outputs }}" != "null" ]; then
|
|
curl -s -X PATCH \
|
|
-H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \
|
|
-H "Content-Type: application/json" \
|
|
"${{ forge.api_url }}/repos/${{ forge.repository }}/issues/comments/${{ steps.fetch.outputs }}" \
|
|
-d "$payload"
|
|
else
|
|
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
|