26
26
export GPT_MIN_CAPACITY="30"
27
27
export TEXT_EMBEDDING_MIN_CAPACITY="45"
28
28
export AZURE_REGIONS="${{ vars.AZURE_REGIONS_RA }}"
29
-
30
29
chmod +x ResearchAssistant/Deployment/scripts/checkquota.sh
31
30
if ! ResearchAssistant/Deployment/scripts/checkquota.sh; then
32
31
# If quota check fails due to insufficient quota, set the flag
47
46
}
48
47
EOF
49
48
)
50
-
51
49
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
52
50
-H "Content-Type: application/json" \
53
51
-d "$EMAIL_BODY" || echo "Failed to send notification"
54
-
55
52
- name : Fail Pipeline if Quota Check Fails
56
53
if : env.QUOTA_FAILED == 'true'
57
54
run : exit 1
@@ -60,28 +57,25 @@ jobs:
60
57
run : |
61
58
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
62
59
az --version # Verify installation
63
-
64
60
- name : Login to Azure
65
61
run : |
66
62
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
67
-
68
63
- name : Install Bicep CLI
69
64
run : az bicep install
70
65
71
66
- name : Set Deployment Region
72
67
run : |
73
68
echo "Selected Region: $VALID_REGION"
74
69
echo "AZURE_LOCATION=$VALID_REGION" >> $GITHUB_ENV
75
-
76
70
- name : Generate Resource Group Name
77
71
id : generate_rg_name
78
72
run : |
79
73
echo "Generating a unique resource group name..."
80
- TIMESTAMP=$(date +%Y%m%d%H%M%S)
81
- COMMON_PART="pslautomationRes"
82
- UNIQUE_RG_NAME="${COMMON_PART}${TIMESTAMP }"
74
+ ACCL_NAME="rabyoc" # Account name as specified
75
+ SHORT_UUID=$(uuidgen | cut -d'-' -f1)
76
+ UNIQUE_RG_NAME="arg-${ACCL_NAME}-${SHORT_UUID }"
83
77
echo "RESOURCE_GROUP_NAME=${UNIQUE_RG_NAME}" >> $GITHUB_ENV
84
- echo "Generated Resource_GROUP_PREFIX : ${UNIQUE_RG_NAME}"
78
+ echo "Generated RESOURCE_GROUP_NAME : ${UNIQUE_RG_NAME}"
85
79
86
80
- name : Check and Create Resource Group
87
81
id : check_create_rg
95
89
else
96
90
echo "Resource group already exists."
97
91
fi
98
-
99
92
- name : Generate Unique Solution Prefix
100
93
id : generate_solution_prefix
101
94
run : |
106
99
UNIQUE_SOLUTION_PREFIX="${COMMON_PART}${UPDATED_TIMESTAMP}"
107
100
echo "SOLUTION_PREFIX=${UNIQUE_SOLUTION_PREFIX}" >> $GITHUB_ENV
108
101
echo "Generated SOLUTION_PREFIX: ${UNIQUE_SOLUTION_PREFIX}"
109
-
110
102
- name : Deploy Bicep Template
111
103
id : deploy
112
104
run : |
@@ -115,23 +107,19 @@ jobs:
115
107
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
116
108
--template-file ResearchAssistant/Deployment/bicep/main.bicep \
117
109
--parameters solutionPrefix=${{ env.SOLUTION_PREFIX }}
118
-
119
110
- name : List KeyVaults and Store in Array
120
111
id : list_keyvaults
121
112
run : |
122
-
123
113
set -e
124
114
echo "Listing all KeyVaults in the resource group ${RESOURCE_GROUP_NAME}..."
125
115
126
116
# Get the list of KeyVaults in the specified resource group
127
117
keyvaults=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --query "[?type=='Microsoft.KeyVault/vaults'].name" -o tsv)
128
-
129
118
if [ -z "$keyvaults" ]; then
130
119
echo "No KeyVaults found in resource group ${RESOURCE_GROUP_NAME}."
131
120
echo "KEYVAULTS=[]" >> $GITHUB_ENV # If no KeyVaults found, set an empty array
132
121
else
133
122
echo "KeyVaults found: $keyvaults"
134
-
135
123
# Format the list into an array with proper formatting (no trailing comma)
136
124
keyvault_array="["
137
125
first=true
@@ -144,101 +132,97 @@ jobs:
144
132
fi
145
133
done
146
134
keyvault_array="$keyvault_array]"
147
-
148
135
# Output the formatted array and save it to the environment variable
149
136
echo "KEYVAULTS=$keyvault_array" >> $GITHUB_ENV
150
137
fi
151
138
152
139
- name : Delete Bicep Deployment
153
- if : success ()
140
+ if : always ()
154
141
run : |
155
142
set -e
156
143
echo "Checking if resource group exists..."
157
144
rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
158
145
if [ "$rg_exists" = "true" ]; then
159
- echo "Resource group exist . Cleaning..."
160
- az group delete \
161
- --name ${{ env.RESOURCE_GROUP_NAME }} \
162
- --yes \
163
- --no-wait
164
- echo "Resource group deleted... ${{ env.RESOURCE_GROUP_NAME }}"
146
+ echo "Resource group exists . Cleaning..."
147
+ az group delete --name ${{ env.RESOURCE_GROUP_NAME }} --yes --no-wait
148
+ echo "Initiated deletion of resource group: ${{ env.RESOURCE_GROUP_NAME }}"
149
+ echo "Waiting for resource group deletion to complete..."
150
+ az group wait --deleted --name ${{ env.RESOURCE_GROUP_NAME }}
151
+ echo "Resource group deletion completed: ${{ env.RESOURCE_GROUP_NAME }}"
165
152
else
166
- echo "Resource group does not exists ."
153
+ echo "Resource group does not exist ."
167
154
fi
168
-
155
+
169
156
- name : Wait for resource deletion to complete
170
157
run : |
171
-
172
- # List of keyvaults
173
- KEYVAULTS="${{ env.KEYVAULTS }}"
174
-
175
- # Remove the surrounding square brackets, if they exist
176
- stripped_keyvaults=$(echo "$KEYVAULTS" | sed 's/\[\|\]//g')
177
-
178
- # Convert the comma-separated string into an array
179
- IFS=',' read -r -a resources_to_check <<< "$stripped_keyvaults"
180
-
181
- # Append new resources to the array
182
- resources_to_check+=("${{ env.SOLUTION_PREFIX }}-openai" "${{ env.SOLUTION_PREFIX }}-cogser")
183
-
184
- echo "List of resources to check: ${resources_to_check[@]}"
185
-
186
- # Get the list of resources in YAML format
187
- resource_list=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --output yaml)
188
-
189
- # Maximum number of retries
190
- max_retries=3
191
-
192
- # Retry intervals in seconds (30, 60, 120)
193
- retry_intervals=(30 60 120)
194
-
195
- # Retry mechanism to check resources
196
- retries=0
197
- while true; do
198
- resource_found=false
199
-
200
- # Iterate through the resources to check
201
- for resource in "${resources_to_check[@]}"; do
202
- echo "Checking resource: $resource"
203
- if echo "$resource_list" | grep -q "name: $resource"; then
204
- echo "Resource '$resource' exists in the resource group."
205
- resource_found=true
158
+ echo "Verifying if resource group '${{ env.RESOURCE_GROUP_NAME }}' still exists..."
159
+ if az group exists --name ${{ env.RESOURCE_GROUP_NAME }} | grep -q "true"; then
160
+ echo "Resource group exists. Proceeding with resource checks..."
161
+ # List of keyvaults
162
+ KEYVAULTS="${{ env.KEYVAULTS }}"
163
+ # Remove the surrounding square brackets, if they exist
164
+ stripped_keyvaults=$(echo "$KEYVAULTS" | sed 's/\[\|\]//g')
165
+
166
+ # Convert the comma-separated string into an array
167
+ IFS=',' read -r -a resources_to_check <<< "$stripped_keyvaults"
168
+
169
+ # Append new resources to the array
170
+ resources_to_check+=("${{ env.SOLUTION_PREFIX }}-openai" "${{ env.SOLUTION_PREFIX }}-cogser")
171
+ echo "List of resources to check: ${resources_to_check[@]}"
172
+
173
+ # Get the list of resources in YAML format
174
+ resource_list=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --output yaml)
175
+
176
+ # Maximum number of retries
177
+ max_retries=3
178
+ # Retry intervals in seconds (30, 60, 120)
179
+ retry_intervals=(30 60 120)
180
+
181
+ # Retry mechanism to check resources
182
+ retries=0
183
+ while true; do
184
+ resource_found=false
185
+ # Iterate through the resources to check
186
+ for resource in "${resources_to_check[@]}"; do
187
+ echo "Checking resource: $resource"
188
+ if echo "$resource_list" | grep -q "name: $resource"; then
189
+ echo "Resource '$resource' exists in the resource group."
190
+ resource_found=true
191
+ else
192
+ echo "Resource '$resource' does not exist in the resource group."
193
+ fi
194
+ done
195
+
196
+ # If any resource exists, retry
197
+ if [ "$resource_found" = true ]; then
198
+ retries=$((retries + 1))
199
+ if [ "$retries" -ge "$max_retries" ]; then
200
+ echo "Maximum retry attempts reached. Exiting."
201
+ break
202
+ else
203
+ # Wait for the appropriate interval for the current retry
204
+ echo "Waiting for ${retry_intervals[$retries-1]} seconds before retrying..."
205
+ sleep ${retry_intervals[$retries-1]}
206
+ fi
206
207
else
207
- echo "Resource '$resource' does not exist in the resource group."
208
- fi
209
- done
210
-
211
- # If any resource exists, retry
212
- if [ "$resource_found" = true ]; then
213
- retries=$((retries + 1))
214
- if [ "$retries" -ge "$max_retries" ]; then
215
- echo "Maximum retry attempts reached. Exiting."
208
+ echo "No resources found. Exiting."
216
209
break
217
- else
218
- # Wait for the appropriate interval for the current retry
219
- echo "Waiting for ${retry_intervals[$retries-1]} seconds before retrying..."
220
- sleep ${retry_intervals[$retries-1]}
221
210
fi
222
- else
223
- echo "No resources found. Exiting."
224
- break
225
- fi
226
- done
227
-
211
+ done
212
+ else
213
+ echo "Resource group '${{ env.RESOURCE_GROUP_NAME }}' does not exist. Skipping resource listing."
214
+ fi
228
215
- name : Purging the Resources
229
- if : success ()
216
+ if : always ()
230
217
run : |
231
-
232
218
set -e
233
219
# Define variables
234
220
OPENAI_COMMON_PART="-openai"
235
221
openai_name="${{ env.SOLUTION_PREFIX }}${OPENAI_COMMON_PART}"
236
222
echo "Azure OpenAI: $openai_name"
237
-
238
223
MULTISERVICE_COMMON_PART="-cogser"
239
224
multiservice_account_name="${{ env.SOLUTION_PREFIX }}${MULTISERVICE_COMMON_PART}"
240
225
echo "Azure MultiService Account: $multiservice_account_name"
241
-
242
226
# Purge OpenAI Resource
243
227
echo "Purging the OpenAI Resource..."
244
228
if ! az resource delete --ids /subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/providers/Microsoft.CognitiveServices/locations/eastus2/resourceGroups/${{ env.RESOURCE_GROUP_NAME }}/deletedAccounts/$openai_name --verbose; then
0 commit comments