From 8e6083e5af7066221db58701362a73adc58dc5a6 Mon Sep 17 00:00:00 2001 From: Bakery Admin Date: Thu, 22 Jan 2026 17:53:02 +0100 Subject: [PATCH] Fix resources isues 15 --- .../templates/task-detect-changes.yaml | 61 ++++++++++--------- .../templates/task-pipeline-summary.yaml | 2 +- .../templates/task-update-gitops.yaml | 2 +- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/infrastructure/cicd/tekton-helm/templates/task-detect-changes.yaml b/infrastructure/cicd/tekton-helm/templates/task-detect-changes.yaml index cc4c3dcb..7f3d4de5 100644 --- a/infrastructure/cicd/tekton-helm/templates/task-detect-changes.yaml +++ b/infrastructure/cicd/tekton-helm/templates/task-detect-changes.yaml @@ -32,7 +32,7 @@ spec: - name: HOME value: /tekton/home script: | - #!/bin/bash + #!/bin/sh set -e # Mark workspace as safe directory to avoid ownership issues @@ -41,7 +41,7 @@ spec: cd $(workspaces.source.path) # Get the list of changed files - CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || git diff --name-only $(git rev-parse --abbrev-ref HEAD)@{upstream} HEAD 2>/dev/null || echo "") + CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "") if [ -z "$CHANGED_FILES" ]; then # No changes detected, assume all services need building @@ -50,53 +50,54 @@ spec: exit 0 fi - # Initialize an array to collect changed services - declare -a changed_services=() + echo "Changed files:" + echo "$CHANGED_FILES" + + # Initialize empty string to collect changed services + CHANGED_SERVICES="" + + # Helper function to add service if not already present + add_service() { + svc="$1" + case ",$CHANGED_SERVICES," in + *",$svc,"*) ;; # Already present + *) + if [ -z "$CHANGED_SERVICES" ]; then + CHANGED_SERVICES="$svc" + else + CHANGED_SERVICES="$CHANGED_SERVICES,$svc" + fi + ;; + esac + } # Check for changes in services/ directory - while IFS= read -r service_dir; do - if [ -n "$service_dir" ]; then - service_name=$(basename "$service_dir") - if [[ ! " ${changed_services[@]} " =~ " ${service_name} " ]]; then - changed_services+=("$service_name") - fi + for svc in $(echo "$CHANGED_FILES" | grep '^services/' | cut -d'/' -f2 | sort -u); do + if [ -n "$svc" ]; then + add_service "$svc" fi - done < <(echo "$CHANGED_FILES" | grep '^services/' | cut -d'/' -f2 | sort -u) + done # Check for changes in gateway/ directory if echo "$CHANGED_FILES" | grep -q '^gateway/'; then - if [[ ! " ${changed_services[@]} " =~ " gateway " ]]; then - changed_services+=("gateway") - fi + add_service "gateway" fi # Check for changes in frontend/ directory if echo "$CHANGED_FILES" | grep -q '^frontend/'; then - if [[ ! " ${changed_services[@]} " =~ " frontend " ]]; then - changed_services+=("frontend") - fi + add_service "frontend" fi # Check for changes in shared/ directory (might affect multiple services) if echo "$CHANGED_FILES" | grep -q '^shared/'; then - if [[ ! " ${changed_services[@]} " =~ " shared " ]]; then - changed_services+=("shared") - fi + add_service "shared" fi - # Convert array to comma-separated string - CHANGED_SERVICES="" - for service in "${changed_services[@]}"; do - if [ -z "$CHANGED_SERVICES" ]; then - CHANGED_SERVICES="$service" - else - CHANGED_SERVICES="$CHANGED_SERVICES,$service" - fi - done - if [ -z "$CHANGED_SERVICES" ]; then # Changes are in infrastructure or other non-service files + echo "Detected: infrastructure changes only" echo "infrastructure" > $(results.changed-services.path) else + echo "Detected changed services: $CHANGED_SERVICES" echo "$CHANGED_SERVICES" > $(results.changed-services.path) fi \ No newline at end of file diff --git a/infrastructure/cicd/tekton-helm/templates/task-pipeline-summary.yaml b/infrastructure/cicd/tekton-helm/templates/task-pipeline-summary.yaml index f5e78426..35edf6bf 100644 --- a/infrastructure/cicd/tekton-helm/templates/task-pipeline-summary.yaml +++ b/infrastructure/cicd/tekton-helm/templates/task-pipeline-summary.yaml @@ -30,7 +30,7 @@ spec: seccompProfile: type: RuntimeDefault script: | - #!/bin/bash + #!/bin/sh set -e echo "=== Bakery-IA CI Pipeline Summary ===" diff --git a/infrastructure/cicd/tekton-helm/templates/task-update-gitops.yaml b/infrastructure/cicd/tekton-helm/templates/task-update-gitops.yaml index c0f4a4d5..f8fddee6 100644 --- a/infrastructure/cicd/tekton-helm/templates/task-update-gitops.yaml +++ b/infrastructure/cicd/tekton-helm/templates/task-update-gitops.yaml @@ -59,7 +59,7 @@ spec: name: gitea-git-credentials key: password script: | - #!/bin/bash + #!/bin/sh set -e echo "============================================"