1616 environment : ${{ steps.set-env.outputs.environment }}
1717 cm_url : ${{ steps.set-env.outputs.cm_url }}
1818 event_processor_tag : ${{ steps.set-env.outputs.event_processor_tag }}
19+ gh_environment : ${{ steps.set-env.outputs.gh_environment }}
1920 steps :
2021 - name : Determine Build Environment
2122 id : set-env
3435 BRANCH_VERSION=$(echo "${{ github.ref }}" | sed 's|refs/heads/release/||')
3536 echo "Branch version: $BRANCH_VERSION"
3637
37- RESPONSE=$(curl -s "${CM_URL}/api/v1/versions/latest")
38+ RESPONSE=$(curl -s "${CM_URL}/api/v1/versions/latest?product=utmstack-v11-dev ")
3839 LATEST_VERSION=$(echo "$RESPONSE" | jq -r '.version // empty')
3940 echo "Latest version from CM: $LATEST_VERSION"
4041
5859 echo "environment=$ENVIRONMENT" >> $GITHUB_OUTPUT
5960 echo "cm_url=$CM_URL" >> $GITHUB_OUTPUT
6061 echo "event_processor_tag=${{ vars.TW_EVENT_PROCESSOR_VERSION_DEV }}" >> $GITHUB_OUTPUT
62+ echo "gh_environment=v11-dev" >> $GITHUB_OUTPUT
6163
6264 # =====================================================================
6365 # PRODUCTION — release.published (prerelease or not)
8284 echo "environment=production" >> $GITHUB_OUTPUT
8385 echo "cm_url=$CM_URL" >> $GITHUB_OUTPUT
8486 echo "event_processor_tag=${{ vars.TW_EVENT_PROCESSOR_VERSION_PROD }}" >> $GITHUB_OUTPUT
87+ echo "gh_environment=v11-prod" >> $GITHUB_OUTPUT
8588 fi
8689
8790 build_agent :
@@ -512,6 +515,7 @@ jobs:
512515 name : Publish New Version to Customer Manager
513516 needs : [all_builds_complete, generate_changelog, setup_deployment]
514517 if : ${{ always() && needs.all_builds_complete.result == 'success' && needs.setup_deployment.outputs.tag != '' }}
518+ environment : ${{ needs.setup_deployment.outputs.gh_environment }}
515519 runs-on : ubuntu-24.04
516520 steps :
517521 - name : Check out code
@@ -523,6 +527,7 @@ jobs:
523527 ENVIRONMENT : ${{ needs.setup_deployment.outputs.environment }}
524528 TAG : ${{ needs.setup_deployment.outputs.tag }}
525529 CM_URL : ${{ needs.setup_deployment.outputs.cm_url }}
530+ SCHEDULE_INSTANCES : ${{ vars.SCHEDULE_INSTANCES }}
526531 run : |
527532 # Use AI changelog for production releases, generic for dev.
528533 if [ "$ENVIRONMENT" != "dev" ] && [ -n "$CHANGELOG_CONTENT" ]; then
@@ -535,87 +540,155 @@ jobs:
535540 echo "CM URL: $CM_URL"
536541 echo "Tag: $TAG"
537542
538- # Select CM_SERVICE_ACCOUNT based on environment
539543 if [ "$ENVIRONMENT" = "dev" ]; then
540- cmAuth=$(echo '${{ secrets.CM_SERVICE_ACCOUNT_DEV }}' | jq -r '.')
544+ cmAuth='${{ secrets.CM_SERVICE_ACCOUNT_DEV }}'
541545 else
542- cmAuth=$(echo '${{ secrets.CM_SERVICE_ACCOUNT_PROD }}' | jq -r '.')
546+ cmAuth='${{ secrets.CM_SERVICE_ACCOUNT_PROD }}'
543547 fi
544-
545548 id=$(echo "$cmAuth" | jq -r '.id')
546549 key=$(echo "$cmAuth" | jq -r '.key')
547550
548- body=$(jq -n \
549- --arg version "$TAG" \
550- --arg changelog "$changelog" \
551- '{version: $version, changelog: $changelog}'
552- )
551+ # CM-dev already has the products schema (same as v12). CM-prod
552+ # doesn't yet, so production keeps registering one version with no
553+ # product_id, exactly as before -- only dev goes through the
554+ # per-product loop.
555+ if [ "$ENVIRONMENT" = "dev" ]; then
556+ if ! echo "$SCHEDULE_INSTANCES" | jq empty > /dev/null 2>&1; then
557+ echo "❌ SCHEDULE_INSTANCES is not valid JSON: $SCHEDULE_INSTANCES"
558+ exit 1
559+ fi
560+
561+ for product_id in $(echo "$SCHEDULE_INSTANCES" | jq -r 'keys[]'); do
562+ echo "Registering $TAG for product: $product_id"
563+
564+ body=$(jq -n \
565+ --arg version "$TAG" \
566+ --arg changelog "$changelog" \
567+ --arg product_id "$product_id" \
568+ '{version: $version, changelog: $changelog, product_id: $product_id}'
569+ )
570+
571+ response=$(curl -s -X POST "${CM_URL}/api/v1/versions/register" \
572+ -H "Content-Type: application/json" \
573+ -H "id: $id" \
574+ -H "key: $key" \
575+ -d "$body")
553576
554- response=$(curl -s -X POST "${CM_URL}/api/v1/versions/register" \
555- -H "Content-Type: application/json" \
556- -H "id: $id" \
557- -H "key: $key" \
558- -d "$body")
577+ echo "Response: $response"
578+ done
579+ else
580+ body=$(jq -n \
581+ --arg version "$TAG" \
582+ --arg changelog "$changelog" \
583+ '{version: $version, changelog: $changelog}'
584+ )
585+
586+ response=$(curl -s -X POST "${CM_URL}/api/v1/versions/register" \
587+ -H "Content-Type: application/json" \
588+ -H "id: $id" \
589+ -H "key: $key" \
590+ -d "$body")
559591
560- echo "Response: $response"
592+ echo "Response: $response"
593+ fi
561594
562595 schedule :
563596 name : Schedule release to our instances
564597 needs : [publish_new_version, setup_deployment]
565598 if : ${{ always() && needs.publish_new_version.result == 'success' && needs.setup_deployment.outputs.tag != '' }}
599+ environment : ${{ needs.setup_deployment.outputs.gh_environment }}
566600 runs-on : ubuntu-24.04
567601 env :
568602 ENVIRONMENT : ${{ needs.setup_deployment.outputs.environment }}
569603 TAG : ${{ needs.setup_deployment.outputs.tag }}
570604 CM_URL : ${{ needs.setup_deployment.outputs.cm_url }}
605+ SCHEDULE_INSTANCES : ${{ vars.SCHEDULE_INSTANCES }}
606+ CM_AUTH_DEV : ${{ secrets.CM_SERVICE_ACCOUNT_DEV }}
607+ CM_AUTH_PROD : ${{ secrets.CM_SERVICE_ACCOUNT_PROD }}
571608 steps :
572609 - name : Schedule updates
573610 run : |
574611 echo "🔍 Environment: $ENVIRONMENT"
575612 echo "🔍 Version: $TAG"
576613 echo "🔍 CM URL: $CM_URL"
577614
578- # Select instance IDs and auth based on environment
579615 if [ "$ENVIRONMENT" = "dev" ]; then
580- instance_ids="${{ vars.SCHEDULE_INSTANCES_DEV }}"
581- auth_json='${{ secrets.CM_SERVICE_ACCOUNT_DEV }}'
616+ auth_json="$CM_AUTH_DEV"
582617 else
583- instance_ids="${{ vars.SCHEDULE_INSTANCES_PROD }}"
584- auth_json='${{ secrets.CM_SERVICE_ACCOUNT_PROD }}'
618+ auth_json="$CM_AUTH_PROD"
585619 fi
586-
587- # Extract id and key from auth JSON
588620 auth_id=$(echo "$auth_json" | jq -r '.id')
589621 auth_key=$(echo "$auth_json" | jq -r '.key')
590622
591- # Parse IDs (handle single ID or comma-separated IDs)
592- IFS=',' read -ra ID_ARRAY <<< "$instance_ids"
623+ scheduled=0
593624
594- # Iterate over each instance ID
595- for instance_id in "${ID_ARRAY[@]}"; do
596- instance_id=$(echo "$instance_id" | xargs)
625+ # CM-dev has the products schema (same as v12). CM-prod doesn't
626+ # yet, so production keeps scheduling against the flat instance
627+ # list with no product_id, exactly as before -- only dev goes
628+ # through the per-product loop.
629+ if [ "$ENVIRONMENT" = "dev" ]; then
630+ if ! echo "$SCHEDULE_INSTANCES" | jq empty > /dev/null 2>&1; then
631+ echo "❌ SCHEDULE_INSTANCES is not valid JSON: $SCHEDULE_INSTANCES"
632+ exit 1
633+ fi
597634
598- echo "📅 Scheduling release for instance: $instance_id"
635+ for product_id in $(echo "$SCHEDULE_INSTANCES" | jq -r 'keys[]'); do
636+ for instance_id in $(echo "$SCHEDULE_INSTANCES" | jq -r --arg p "$product_id" '.[$p][]'); do
637+ echo "📅 Scheduling release for instance: $instance_id (product: $product_id)"
638+
639+ response=$(curl -s -w "\n%{http_code}" -X POST "${CM_URL}/api/v1/updates" \
640+ -H "Content-Type: application/json" \
641+ -H "id: $auth_id" \
642+ -H "key: $auth_key" \
643+ -d "{\"instances_ids\": [\"$instance_id\"], \"version\": \"$TAG\", \"product_id\": \"$product_id\"}")
644+
645+ http_code=$(echo "$response" | tail -n1)
646+ body=$(echo "$response" | sed '$d')
647+
648+ if [ "$http_code" -ge 200 ] && [ "$http_code" -lt 300 ]; then
649+ echo "✅ Successfully scheduled for instance: $instance_id"
650+ scheduled=$((scheduled + 1))
651+ else
652+ echo "❌ Failed to schedule for instance: $instance_id (HTTP $http_code)"
653+ echo "Response: $body"
654+ exit 1
655+ fi
656+ done
657+ done
658+ else
659+ IFS=',' read -ra ID_ARRAY <<< "$SCHEDULE_INSTANCES"
599660
600- response=$(curl -s -w "\n%{http_code}" -X POST "${CM_URL}/api/v1/updates" \
601- -H "Content-Type: application/json" \
602- -H "id: $auth_id" \
603- -H "key: $auth_key" \
604- -d "{\"instances_ids\": [\"$instance_id\"], \"version\": \"$TAG\"}")
661+ for instance_id in "${ID_ARRAY[@]}"; do
662+ instance_id=$(echo "$instance_id" | xargs)
605663
606- http_code=$(echo "$response" | tail -n1)
607- body=$(echo "$response" | sed '$d')
664+ echo "📅 Scheduling release for instance: $instance_id"
608665
609- if [ "$http_code" -ge 200 ] && [ "$http_code" -lt 300 ]; then
610- echo "✅ Successfully scheduled for instance: $instance_id"
611- else
612- echo "❌ Failed to schedule for instance: $instance_id (HTTP $http_code)"
613- echo "Response: $body"
614- exit 1
615- fi
616- done
666+ response=$(curl -s -w "\n%{http_code}" -X POST "${CM_URL}/api/v1/updates" \
667+ -H "Content-Type: application/json" \
668+ -H "id: $auth_id" \
669+ -H "key: $auth_key" \
670+ -d "{\"instances_ids\": [\"$instance_id\"], \"version\": \"$TAG\"}")
671+
672+ http_code=$(echo "$response" | tail -n1)
673+ body=$(echo "$response" | sed '$d')
674+
675+ if [ "$http_code" -ge 200 ] && [ "$http_code" -lt 300 ]; then
676+ echo "✅ Successfully scheduled for instance: $instance_id"
677+ scheduled=$((scheduled + 1))
678+ else
679+ echo "❌ Failed to schedule for instance: $instance_id (HTTP $http_code)"
680+ echo "Response: $body"
681+ exit 1
682+ fi
683+ done
684+ fi
685+
686+ if [ "$scheduled" -eq 0 ]; then
687+ echo "❌ No instances were scheduled — check SCHEDULE_INSTANCES for this environment"
688+ exit 1
689+ fi
617690
618- echo "✅ Scheduled release for all instances with version $TAG"
691+ echo "✅ Scheduled release for all $scheduled instance(s) with version $TAG"
619692
620693
621694
0 commit comments