From 365ffd3b62076d161e5e86bfedf6f448a0af2915 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Date: Fri, 10 Apr 2026 05:21:45 +0200 Subject: [PATCH] feat(woodpecker): add change detection and selective builds - Add detect-changes step to check for code changes - Add multiple tags (commit SHA, latest, branch-latest) - Add Kubernetes deployment step - Skip build/deploy if no relevant file changes - Consistent with backend CI pipeline --- .woodpecker.yml | 96 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 4 deletions(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index 50a584e..5eedf34 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,8 +1,40 @@ when: - branch: high-performance + branch: [main, high-performance] event: push steps: + # Step 1: Detect if changes exist + - name: detect-changes + image: alpine/git + commands: + - apk add --no-cache bash + - | + #!/bin/bash + set -e + + # Get changed files from last commit + CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD || echo "") + + # Check if relevant files changed (src, package.json, Dockerfile, etc.) + RELEVANT_CHANGED=false + if echo "$CHANGED_FILES" | grep -qE "^(src/|package\.json|package-lock\.json|Dockerfile|vite\.config|tsconfig|public/)"; then + RELEVANT_CHANGED=true + echo "✅ Admin panel code changed - will build" + fi + + # Create marker file + if [ "$RELEVANT_CHANGED" = "true" ]; then + echo "SHOULD_BUILD=true" > .build-marker + echo "🚀 Will build admin panel" + else + echo "SHOULD_BUILD=false" > .build-marker + echo "⏭️ Skipping admin panel - no relevant changes" + fi + + # Export for other steps + cat .build-marker >> ${CI_ENV} + + # Step 2: Build and push Docker image (only if changed) - name: build-and-push image: woodpeckerci/plugin-docker-buildx:5.0.0 settings: @@ -10,14 +42,70 @@ steps: repo: ghcr.io/traceworks2023/nxtgauge-admin-solid dockerfile: Dockerfile tags: + - ${CI_COMMIT_SHA} + - latest - high-performance-latest username: from_secret: GHCR_USERNAME password: from_secret: GHCR_TOKEN platforms: linux/amd64 + when: + - evaluate: 'env.SHOULD_BUILD == "true"' + # Step 3: Deploy to Kubernetes (only if changed) + - name: deploy + image: bitnami/kubectl:latest + secrets: [kube_config] + commands: + - | + #!/bin/bash + set -e - - - + # Check if we should deploy + if [ "${SHOULD_BUILD}" != "true" ]; then + echo "⏭️ Skipping deployment - no changes" + exit 0 + fi + + # Setup kubeconfig + mkdir -p ~/.kube + echo "$KUBE_CONFIG" | base64 -d > ~/.kube/config + chmod 600 ~/.kube/config + + NAMESPACE="nxtgauge" + DEPLOYMENT_NAME="nxtgauge-admin-solid" + + echo "🚀 Deploying admin panel..." + + # Trigger rolling restart to pick up new image + kubectl rollout restart deployment/${DEPLOYMENT_NAME} -n ${NAMESPACE} + + # Wait for rollout to complete + echo "⏳ Waiting for rollout to complete..." + kubectl rollout status deployment/${DEPLOYMENT_NAME} -n ${NAMESPACE} --timeout=300s + + echo "✅ Admin panel deployed successfully!" + + # Show deployment status + kubectl get deployment/${DEPLOYMENT_NAME} -n ${NAMESPACE} + when: + - evaluate: 'env.SHOULD_BUILD == "true"' + - branch: [main, high-performance] + + # Step 4: Notify status + - name: notify + image: alpine:latest + commands: + - | + if [ "${SHOULD_BUILD}" = "true" ]; then + if [ "${CI_PIPELINE_STATUS}" = "success" ]; then + echo "✅ Admin panel pipeline completed successfully" + else + echo "❌ Admin panel pipeline failed" + fi + else + echo "⏭️ Admin panel was skipped (no changes)" + fi + when: + - status: [success, failure]