Skip to content

Commit 8471733

Browse files
committed
ci(v12-pipeline): serialize runs and fix product-scoped update scheduling
1 parent 714b63c commit 8471733

1 file changed

Lines changed: 26 additions & 25 deletions

File tree

.github/workflows/v12-deployment-pipeline.yml

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
release:
88
types: [published]
99

10+
concurrency:
11+
group: v12-build-deploy-pipeline
12+
cancel-in-progress: false
13+
1014
jobs:
1115
setup_deployment:
1216
name: Setup Deployment
@@ -572,44 +576,41 @@ jobs:
572576
echo "🔍 Version: $TAG"
573577
echo "🔍 CM URL: $CM_URL"
574578
575-
# Select instance IDs and auth based on environment
576579
if [ "$ENVIRONMENT" = "dev" ]; then
577-
instance_ids="${{ vars.SCHEDULE_INSTANCES_DEV }}"
580+
targets_json="${{ vars.SCHEDULE_INSTANCES_DEV }}"
578581
auth_json='${{ secrets.CM_SERVICE_ACCOUNT_DEV }}'
579582
else
580-
instance_ids="${{ vars.SCHEDULE_INSTANCES_PROD }}"
583+
targets_json="${{ vars.SCHEDULE_INSTANCES_PROD }}"
581584
auth_json='${{ secrets.CM_SERVICE_ACCOUNT_PROD }}'
582585
fi
583586
584587
# Extract id and key from auth JSON
585588
auth_id=$(echo "$auth_json" | jq -r '.id')
586589
auth_key=$(echo "$auth_json" | jq -r '.key')
587590
588-
# Parse IDs (handle single ID or comma-separated IDs)
589-
IFS=',' read -ra ID_ARRAY <<< "$instance_ids"
590-
591-
# Iterate over each instance ID
592-
for instance_id in "${ID_ARRAY[@]}"; do
593-
instance_id=$(echo "$instance_id" | xargs)
591+
# Targets are grouped by product_id (CM scopes instances/versions by
592+
# product and /api/v1/updates requires it): {"<product_id>": ["<instance_id>", ...]}
593+
for product_id in $(echo "$targets_json" | jq -r 'keys[]'); do
594+
for instance_id in $(echo "$targets_json" | jq -r --arg p "$product_id" '.[$p][]'); do
595+
echo "📅 Scheduling release for instance: $instance_id (product: $product_id)"
594596
595-
echo "📅 Scheduling release for instance: $instance_id"
597+
response=$(curl -s -w "\n%{http_code}" -X POST "${CM_URL}/api/v1/updates" \
598+
-H "Content-Type: application/json" \
599+
-H "id: $auth_id" \
600+
-H "key: $auth_key" \
601+
-d "{\"instances_ids\": [\"$instance_id\"], \"version\": \"$TAG\", \"product_id\": \"$product_id\"}")
596602
597-
response=$(curl -s -w "\n%{http_code}" -X POST "${CM_URL}/api/v1/updates" \
598-
-H "Content-Type: application/json" \
599-
-H "id: $auth_id" \
600-
-H "key: $auth_key" \
601-
-d "{\"instances_ids\": [\"$instance_id\"], \"version\": \"$TAG\"}")
603+
http_code=$(echo "$response" | tail -n1)
604+
body=$(echo "$response" | sed '$d')
602605
603-
http_code=$(echo "$response" | tail -n1)
604-
body=$(echo "$response" | sed '$d')
605-
606-
if [ "$http_code" -ge 200 ] && [ "$http_code" -lt 300 ]; then
607-
echo "✅ Successfully scheduled for instance: $instance_id"
608-
else
609-
echo "❌ Failed to schedule for instance: $instance_id (HTTP $http_code)"
610-
echo "Response: $body"
611-
exit 1
612-
fi
606+
if [ "$http_code" -ge 200 ] && [ "$http_code" -lt 300 ]; then
607+
echo "✅ Successfully scheduled for instance: $instance_id"
608+
else
609+
echo "❌ Failed to schedule for instance: $instance_id (HTTP $http_code)"
610+
echo "Response: $body"
611+
exit 1
612+
fi
613+
done
613614
done
614615
615616
echo "✅ Scheduled release for all instances with version $TAG"

0 commit comments

Comments
 (0)