66 - main
77 - dev
88 - demo
9+ workflow_dispatch :
910
1011 schedule :
1112 - cron : ' 0 0,12 * * *' # Runs at 12:00 AM and 12:00 PM GMT
13+
1214
1315jobs :
1416 deploy :
@@ -41,23 +43,23 @@ jobs:
4143
4244 - name : Create Resource Group
4345 run : |
44- az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location eastus
46+ az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location eastus2
4547
4648 - name : Generate Unique Solution Prefix
4749 id : generate_solution_prefix
4850 run : |
4951 set -e
5052 COMMON_PART="km"
5153 TIMESTAMP=$(date +%s)
52- UPDATED_TIMESTAMP=$(echo $TIMESTAMP | tail -c 3 )
54+ UPDATED_TIMESTAMP=$(echo $TIMESTAMP | tail -c 5 )
5355 UNIQUE_SOLUTION_PREFIX="${COMMON_PART}${UPDATED_TIMESTAMP}"
5456 echo "SOLUTION_PREFIX=${UNIQUE_SOLUTION_PREFIX}" >> $GITHUB_ENV
5557 echo "Generated SOLUTION_PREFIX: ${UNIQUE_SOLUTION_PREFIX}"
5658
5759
5860 - name : Determine Tag Name Based on Branch
5961 id : determine_tag
60- run : echo "tagname=${{ github.ref_name == 'main' && 'latest' || github.ref_name == 'dev' && 'dev' || github.ref_name == 'demo' && 'demo' || github.head_ref || 'default' }}" >> $GITHUB_OUTPUT
62+ run : echo "tagname=${{ github.ref_name == 'main' && 'latest' || github.ref_name == 'dev' && 'dev' || github.ref_name == 'demo' && 'demo' || github.ref_name == 'dependabotchanges' && 'dependabotchanges' || github. head_ref || 'default' }}" >> $GITHUB_OUTPUT
6163
6264 - name : Deploy Bicep Template
6365 id : deploy
6668 az deployment group create \
6769 --resource-group ${{ env.RESOURCE_GROUP_NAME }} \
6870 --template-file infra/main.bicep \
69- --parameters contentUnderstandingLocation='West US' environmentName=${{ env.SOLUTION_PREFIX }} secondaryLocation=eastus2 imageTag=${{ steps.determine_tag.outputs.tagname }}
71+ --parameters environmentName=${{env.SOLUTION_PREFIX}} contentUnderstandingLocation="West US" secondaryLocation="eastus2" imageTag=${{ steps.determine_tag.outputs.tagname }}
72+
73+
74+ - name : Extract AI Services and Key Vault Names
75+ if : always()
76+ run : |
77+ echo "Fetching AI Services and Key Vault names before deletion..."
78+
79+ # # Get Key Vault name
80+ # KEYVAULT_NAME=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --resource-type "Microsoft.KeyVault/vaults" --query "[].name" -o tsv)
81+ # echo "Detected Key Vault: $KEYVAULT_NAME"
82+ # echo "KEYVAULT_NAME=$KEYVAULT_NAME" >> $GITHUB_ENV
83+
84+ # Get AI Services names and convert them into a space-separated string
85+ AI_SERVICES=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --resource-type "Microsoft.CognitiveServices/accounts" --query "[].name" -o tsv | tr '\n' ' ')
86+
87+ echo "Detected AI Services: $AI_SERVICES"
88+ echo "AI_SERVICES=$AI_SERVICES" >> $GITHUB_ENV
89+
90+
91+
7092
7193 - name : Send Notification on Failure
7294 if : failure()
88110
89111
90112 - name : Delete Bicep Deployment
91-
113+ if : always()
92114 run : |
93115 set -e
94116 echo "Checking if resource group exists..."
@@ -103,4 +125,60 @@ jobs:
103125 else
104126 echo "Resource group does not exists."
105127 fi
128+
129+ - name : Wait for Soft Deletion of Key Vault and AI Services
130+ if : always()
131+ run : |
132+ echo "Waiting for resources to be soft deleted..."
133+
134+ # Wait for Key Vault to be soft deleted
135+ if [ -n "${{ env.KEYVAULT_NAME }}" ]; then
136+ while true; do
137+ DELETED_VAULT=$(az keyvault show-deleted --name ${{ env.KEYVAULT_NAME }} --query "id" -o tsv 2>/dev/null || echo "")
138+ if [ -n "$DELETED_VAULT" ]; then
139+ echo "Key Vault soft deleted!"
140+ break
141+ fi
142+ echo "Key Vault not yet soft deleted. Retrying in 15s..."
143+ sleep 15
144+ done
145+ fi
146+
147+
148+ # Wait for AI Services to be soft deleted
149+ for AI_SERVICE in ${{ env.AI_SERVICES }}; do
150+ while true; do
151+ DELETED_AI_SERVICE=$(az cognitiveservices account list-deleted --query "[?name=='$AI_SERVICE'].id" -o tsv 2>/dev/null || echo "")
152+ if [ -n "$DELETED_AI_SERVICE" ]; then
153+ echo "AI Service $AI_SERVICE is soft deleted!"
154+ break
155+ fi
156+ echo "AI Service $AI_SERVICE not yet soft deleted. Retrying in 15s..."
157+ sleep 15
158+ done
159+ done
160+
161+
162+ - name : Purge Key Vault and AI Services
163+ if : always()
164+ run : |
165+ echo "Purging soft deleted resources..."
166+
167+ # Ensure AI_SERVICES is properly split into individual services
168+ IFS=' ' read -r -a SERVICES <<< "${{ env.AI_SERVICES }}"
169+
170+ for AI_SERVICE in "${SERVICES[@]}"; do
171+ echo "Checking location for AI Service: $AI_SERVICE"
172+
173+ # Fetch AI Service location
174+ SERVICE_LOCATION=$(az cognitiveservices account list-deleted --query "[?name=='$AI_SERVICE'].location" -o tsv 2>/dev/null || echo "")
175+
176+ if [ -n "$SERVICE_LOCATION" ]; then
177+ echo "Purging AI Service $AI_SERVICE in $SERVICE_LOCATION"
178+ az cognitiveservices account purge --location "$SERVICE_LOCATION" --resource-group "${{ env.RESOURCE_GROUP_NAME }}" --name "$AI_SERVICE"
179+ else
180+ echo "Could not determine location for AI Service: $AI_SERVICE. Skipping purge."
181+ fi
182+ done
183+ shell : bash
106184
0 commit comments