Files
bart 2ca8b6486b
Sync Smart Home Manifests to GitOps / Sync Manifests to GitOps Repo (push) Successful in 3s
feat: add k8s manifests and gitops sync workflow for smart-home
2026-10-17 17:00:28 +02:00

77 lines
2.6 KiB
YAML

name: Sync Smart Home Manifests to GitOps
on:
push:
branches:
- main
- master
paths:
- 'k8s/**'
- '.gitea/workflows/**'
permissions:
contents: read
env:
GITOPS_REPO: git.bnhmeijer.nl/bart/k8s-infra-vmserver.git
GITOPS_PATH: workloads/smart-home
ARGOCD_SERVER: ${{ vars.ARGOCD_SERVER || 'argocd.bnhmeijer.nl' }}
jobs:
sync-to-gitops:
name: Sync Manifests to GitOps Repo
runs-on: ubuntu-latest
steps:
- name: Checkout smart-home repository
uses: actions/checkout@v4
- name: Sync manifests to k8s-infra-vmserver
env:
TOKEN: ${{ secrets.GITOPS_PAT || secrets.CI_TOKEN }}
GITEA_SHA: ${{ gitea.sha }}
run: |
git config --global user.name "Gitea Actions Bot"
git config --global user.email "actions@git.bnhmeijer.nl"
echo "Cloning GitOps repository..."
git clone https://${TOKEN}@${GITOPS_REPO} gitops-repo
echo "Syncing k8s manifests into ${GITOPS_PATH}..."
mkdir -p "gitops-repo/${GITOPS_PATH}"
rm -rf "gitops-repo/${GITOPS_PATH}"/*
cp -r k8s/* "gitops-repo/${GITOPS_PATH}/"
cd gitops-repo
if [ -n "$(git status --porcelain)" ]; then
git add .
git commit -m "ci(smart-home): sync manifests (${GITEA_SHA::7})"
git push origin main
echo "Successfully pushed updated manifests to k8s-infra-vmserver!"
else
echo "No manifest changes detected in GitOps repository."
fi
- name: Trigger ArgoCD Sync for smart-home
env:
ARGOCD_SERVER: ${{ env.ARGOCD_SERVER }}
ARGOCD_TOKEN: ${{ secrets.ARGOCD_TOKEN }}
run: |
if [ -n "$ARGOCD_TOKEN" ]; then
SERVER_URL="${ARGOCD_SERVER}"
if [[ ! "$SERVER_URL" =~ ^https?:// ]]; then
SERVER_URL="https://${SERVER_URL}"
fi
echo "Triggering ArgoCD sync for application smart-home on $SERVER_URL..."
RESPONSE=$(curl -s -S -k -w "\nHTTP_STATUS:%{http_code}" -X POST \
-H "Authorization: Bearer $ARGOCD_TOKEN" \
-H "Content-Type: application/json" \
"${SERVER_URL}/api/v1/applications/smart-home/sync" || true)
HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS:" | cut -d':' -f2)
BODY=$(echo "$RESPONSE" | grep -v "HTTP_STATUS:")
echo "ArgoCD API Response (HTTP $HTTP_STATUS): $BODY"
else
echo "ARGOCD_TOKEN secret is not set, skipping ArgoCD sync trigger (ArgoCD auto-sync will pick up changes)."
fi