Skip to content

Commit 97750c9

Browse files
Update deploy workflow for Azure OpenAI integration
1 parent 1242dcb commit 97750c9

File tree

1 file changed

+6
-61
lines changed

1 file changed

+6
-61
lines changed

.github/workflows/deploy.yml

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ on:
66
types:
77
- completed
88
branches:
9-
- main
10-
- dev
11-
- demo
129
- vee-pipeline-fixes
1310
schedule:
1411
- cron: '0 5,17 * * *' # Runs at 5:00 AM and 5:00 PM GMT
@@ -37,6 +34,10 @@ jobs:
3734
run: |
3835
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
3936
37+
- name: Install Azure OpenAI Extension
38+
run: |
39+
az extension add --upgrade -n openai
40+
4041
- name: Select Region with Sufficient OpenAI Quota
4142
id: select_region
4243
run: |
@@ -154,7 +155,6 @@ jobs:
154155
--role "Contributor" \
155156
--scope /subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ env.RESOURCE_GROUP_NAME }}
156157
157-
158158
- name: Get Deployment Output and extract Values
159159
id: get_output
160160
run: |
@@ -202,22 +202,15 @@ jobs:
202202
203203
set -e
204204
echo "Fetching Log Analytics workspace from resource group ${{ env.RESOURCE_GROUP_NAME }}..."
205-
206-
# Run the az monitor log-analytics workspace list command to get the workspace name
207205
log_analytics_workspace_name=$(az monitor log-analytics workspace list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --query "[0].name" -o tsv)
208-
209206
if [ -z "$log_analytics_workspace_name" ]; then
210207
echo "No Log Analytics workspace found in resource group ${{ env.RESOURCE_GROUP_NAME }}."
211208
else
212209
echo "LOG_ANALYTICS_WORKSPACE_NAME=${log_analytics_workspace_name}" >> $GITHUB_ENV
213210
echo "Log Analytics workspace name: ${log_analytics_workspace_name}"
214211
fi
215-
216212
echo "Fetching OpenAI resource from resource group ${{ env.RESOURCE_GROUP_NAME }}..."
217-
218-
# Run the az resource list command to get the OpenAI resource name
219213
openai_resource_name=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --resource-type "Microsoft.CognitiveServices/accounts" --query "[0].name" -o tsv)
220-
221214
if [ -z "$openai_resource_name" ]; then
222215
echo "No OpenAI resource found in resource group ${{ env.RESOURCE_GROUP_NAME }}."
223216
exit 1
@@ -233,17 +226,12 @@ jobs:
233226
234227
set -e
235228
echo "Listing all KeyVaults in the resource group ${RESOURCE_GROUP_NAME}..."
236-
237-
# Get the list of KeyVaults in the specified resource group
238229
keyvaults=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --query "[?type=='Microsoft.KeyVault/vaults'].name" -o tsv)
239-
240230
if [ -z "$keyvaults" ]; then
241231
echo "No KeyVaults found in resource group ${RESOURCE_GROUP_NAME}."
242232
echo "KEYVAULTS=[]" >> $GITHUB_ENV # If no KeyVaults found, set an empty array
243233
else
244234
echo "KeyVaults found: $keyvaults"
245-
246-
# Format the list into an array with proper formatting (no trailing comma)
247235
keyvault_array="["
248236
first=true
249237
for kv in $keyvaults; do
@@ -255,8 +243,6 @@ jobs:
255243
fi
256244
done
257245
keyvault_array="$keyvault_array]"
258-
259-
# Output the formatted array and save it to the environment variable
260246
echo "KEYVAULTS=$keyvault_array" >> $GITHUB_ENV
261247
fi
262248
@@ -283,50 +269,28 @@ jobs:
283269
run: |
284270
285271
set -e
286-
# Purge Log Analytics Workspace
287272
echo "Purging the Log Analytics Workspace..."
288273
if ! az monitor log-analytics workspace delete --force --resource-group ${{ env.RESOURCE_GROUP_NAME }} --workspace-name ${{ env.LOG_ANALYTICS_WORKSPACE_NAME }} --yes --verbose; then
289274
echo "Failed to purge Log Analytics workspace: ${{ env.LOG_ANALYTICS_WORKSPACE_NAME }}"
290275
else
291276
echo "Purged the Log Analytics workspace: ${{ env.LOG_ANALYTICS_WORKSPACE_NAME }}"
292277
fi
293-
294278
echo "Log analytics workspace resource purging completed successfully"
295-
296279
297280
- name: Wait for resource deletion to complete
298281
if: always()
299282
run: |
300-
301-
# List of keyvaults
302283
KEYVAULTS="${{ env.KEYVAULTS }}"
303-
304-
# Remove the surrounding square brackets, if they exist
305284
stripped_keyvaults=$(echo "$KEYVAULTS" | sed 's/\[\|\]//g')
306-
307-
# Convert the comma-separated string into an array
308285
IFS=',' read -r -a resources_to_check <<< "$stripped_keyvaults"
309-
310-
# Append new resources to the array
311286
resources_to_check+=("${{ env.LOG_ANALYTICS_WORKSPACE_NAME }}" "${{ env.OPENAI_RESOURCE_NAME }}")
312-
313287
echo "List of resources to check: ${resources_to_check[@]}"
314-
315-
# Maximum number of retries
316288
max_retries=3
317-
318-
# Retry intervals in seconds (30, 60, 120)
319289
retry_intervals=(30 60 120)
320-
321-
# Retry mechanism to check resources
322290
retries=0
323291
while true; do
324292
resource_found=false
325-
326-
# Get the list of resources in YAML format again on each retry
327293
resource_list=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --output yaml)
328-
329-
# Iterate through the resources to check
330294
for resource in "${resources_to_check[@]}"; do
331295
echo "Checking resource: $resource"
332296
if echo "$resource_list" | grep -q "name: $resource"; then
@@ -336,15 +300,12 @@ jobs:
336300
echo "Resource '$resource' does not exist in the resource group."
337301
fi
338302
done
339-
340-
# If any resource exists, retry
341303
if [ "$resource_found" = true ]; then
342304
retries=$((retries + 1))
343305
if [ "$retries" -gt "$max_retries" ]; then
344306
echo "Maximum retry attempts reached. Exiting."
345307
break
346308
else
347-
# Wait for the appropriate interval for the current retry
348309
echo "Waiting for ${retry_intervals[$retries-1]} seconds before retrying..."
349310
sleep ${retry_intervals[$retries-1]}
350311
fi
@@ -353,44 +314,30 @@ jobs:
353314
break
354315
fi
355316
done
356-
317+
357318
- name: Purging the Resources
358319
if: always()
359320
run: |
360321
361322
set -e
362-
363323
echo "Azure OpenAI: ${{ env.OPENAI_RESOURCE_NAME }}"
364-
365-
# Purge OpenAI Resource
366324
echo "Purging the OpenAI Resource..."
367325
if ! az resource delete --ids /subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/providers/Microsoft.CognitiveServices/locations/${{ env.SELECTED_REGION }}/resourceGroups/${{ env.RESOURCE_GROUP_NAME }}/deletedAccounts/${{ env.OPENAI_RESOURCE_NAME }} --verbose; then
368326
echo "Failed to purge openai resource: ${{ env.OPENAI_RESOURCE_NAME }}"
369327
else
370328
echo "Purged the openai resource: ${{ env.OPENAI_RESOURCE_NAME }}"
371329
fi
372-
373-
# List of keyvaults
374330
KEYVAULTS="${{ env.KEYVAULTS }}"
375-
376-
# Remove the surrounding square brackets, if they exist
377331
stripped_keyvaults=$(echo "$KEYVAULTS" | sed 's/\[\|\]//g')
378-
379-
# Convert the comma-separated string into an array
380332
IFS=',' read -r -a keyvault_array <<< "$stripped_keyvaults"
381-
382333
echo "Using KeyVaults Array..."
383334
for keyvault_name in "${keyvault_array[@]}"; do
384335
echo "Processing KeyVault: $keyvault_name"
385-
# Check if the KeyVault is soft-deleted
386336
deleted_vaults=$(az keyvault list-deleted --query "[?name=='$keyvault_name']" -o json --subscription ${{ secrets.AZURE_SUBSCRIPTION_ID }})
387-
388-
# If the KeyVault is found in the soft-deleted state, purge it
389337
if [ "$(echo "$deleted_vaults" | jq length)" -gt 0 ]; then
390338
echo "KeyVault '$keyvault_name' is soft-deleted. Proceeding to purge..."
391-
# Purge the KeyVault
392339
if az keyvault purge --name "$keyvault_name" --no-wait; then
393-
echo "Successfully purged KeyVault '$keyvault_name'."
340+
echo "Successfully purged KeyVault '$keyvault_name'."
394341
else
395342
echo "Failed to purge KeyVault '$keyvault_name'."
396343
fi
@@ -404,14 +351,12 @@ jobs:
404351
if: failure() || needs.deploy.result == 'failure'
405352
run: |
406353
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
407-
408354
EMAIL_BODY=$(cat <<EOF
409355
{
410356
"body": "<p>Dear Team,</p><p>We would like to inform you that the DocGen Deployment Automation process has encountered an issue and has failed to complete successfully.</p><p><strong>Build URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a><br></p><p>Please investigate the matter at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>"
411357
}
412358
EOF
413359
)
414-
415360
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
416361
-H "Content-Type: application/json" \
417362
-d "$EMAIL_BODY" || echo "Failed to send notification"

0 commit comments

Comments
 (0)