1
- name : Validate Deployment
1
+ name : Deploy-Test-Cleanup Pipeline
2
2
3
3
on :
4
- push :
5
- branches :
6
- - main
7
- schedule :
8
- - cron : ' 0 5,17 * * *' # Runs at 5:00 AM and 5:00 PM GMT
9
- workflow_dispatch :
4
+ workflow_run :
5
+ workflows : ["Build Docker and Optional Push"]
6
+ types :
7
+ - completed
8
+ branches :
9
+ - main
10
+ - dev
11
+ - demo
12
+ schedule :
13
+ - cron : ' 0 5,17 * * *' # Runs at 5:00 AM and 5:00 PM GMT
14
+ workflow_dispatch :
15
+
16
+ env :
17
+ GPT_MIN_CAPACITY : 200
18
+ BRANCH_NAME : ${{ github.head_ref || github.ref_name }}
10
19
11
20
jobs :
12
21
deploy :
13
22
runs-on : ubuntu-latest
23
+ outputs :
24
+ RESOURCE_GROUP_NAME : ${{ steps.check_create_rg.outputs.RESOURCE_GROUP_NAME }}
25
+ WEBAPP_URL : ${{ steps.get_output.outputs.WEBAPP_URL }}
14
26
steps :
15
27
- name : Checkout Code
16
28
uses : actions/checkout@v3
36
48
UNIQUE_RG_NAME="arg-${ACCL_NAME}-${SHORT_UUID}"
37
49
echo "RESOURCE_GROUP_NAME=${UNIQUE_RG_NAME}" >> $GITHUB_ENV
38
50
echo "Generated RESOURCE_GROUP_NAME: ${UNIQUE_RG_NAME}"
39
-
40
51
41
52
- name : Check and Create Resource Group
42
53
id : check_create_rg
50
61
else
51
62
echo "Resource group already exists."
52
63
fi
64
+ echo "RESOURCE_GROUP_NAME=${{ env.RESOURCE_GROUP_NAME }}" >> $GITHUB_OUTPUT
53
65
54
-
55
66
- name : Generate Unique Solution Prefix
56
67
id : generate_solution_prefix
57
68
run : |
@@ -63,17 +74,42 @@ jobs:
63
74
echo "SOLUTION_PREFIX=${UNIQUE_SOLUTION_PREFIX}" >> $GITHUB_ENV
64
75
echo "Generated SOLUTION_PREFIX: ${UNIQUE_SOLUTION_PREFIX}"
65
76
66
-
67
77
- name : Deploy Bicep Template
68
78
id : deploy
69
79
run : |
70
80
set -e
81
+ # set image tag based on branch
82
+ if [[ "${{ env.BRANCH_NAME }}" == "main" ]]; then
83
+ IMAGE_TAG="latest"
84
+ elif [[ "${{ env.BRANCH_NAME }}" == "dev" ]]; then
85
+ IMAGE_TAG="dev"
86
+ elif [[ "${{ env.BRANCH_NAME }}" == "demo" ]]; then
87
+ IMAGE_TAG="demo"
88
+ else
89
+ IMAGE_TAG="latest"
90
+ fi
91
+
71
92
az deployment group create \
93
+ --name ${{ env.SOLUTION_PREFIX }}-deployment \
72
94
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
73
95
--template-file infra/main.bicep \
74
- --parameters AzureAiServiceLocation=swedencentral Prefix=${{ env.SOLUTION_PREFIX }}\
96
+ --parameters \
97
+ Prefix="${{ env.SOLUTION_PREFIX }}" \
98
+ AzureAiServiceLocation="eastus" \
99
+ capacity=${{ env.GPT_MIN_CAPACITY }} \
100
+ imageVersion="${IMAGE_TAG}"\
75
101
--debug
76
102
103
+ - name : Get Deployment Output and extract Values
104
+ id : get_output
105
+ run : |
106
+ set -e
107
+ echo "Fetching deployment output..."
108
+ BICEP_OUTPUT=$(az deployment group show --name ${{ env.SOLUTION_PREFIX }}-deployment --resource-group ${{ env.RESOURCE_GROUP_NAME }} --query "properties.outputs" -o json)
109
+ echo "Extracting deployment output..."
110
+ WEBAPP_URL=$(echo $BICEP_OUTPUT | jq -r '.weB_APP_URL.value')
111
+ echo "WEBAPP_URL=$WEBAPP_URL" >> $GITHUB_OUTPUT
112
+ echo "Deployment output: $BICEP_OUTPUT"
77
113
78
114
- name : Send Notification on Failure
79
115
if : failure()
@@ -93,6 +129,34 @@ jobs:
93
129
-H "Content-Type : application/json" \
94
130
-d "$EMAIL_BODY" || echo "Failed to send notification"
95
131
132
+ - name : Logout from Azure
133
+ if : always()
134
+ run : |
135
+ az logout
136
+ echo "Logged out from Azure."
137
+
138
+ e2e-test :
139
+ needs : deploy
140
+ uses : ./.github/workflows/test-automation.yml
141
+ with :
142
+ CODEMOD_WEB_URL : ${{ needs.deploy.outputs.WEBAPP_URL }}
143
+ secrets : inherit
144
+
145
+ cleanup-deployment :
146
+ if : always() && needs.deploy.outputs.RESOURCE_GROUP_NAME != ''
147
+ needs : [deploy, e2e-test]
148
+ runs-on : ubuntu-latest
149
+ env :
150
+ RESOURCE_GROUP_NAME : ${{ needs.deploy.outputs.RESOURCE_GROUP_NAME }}
151
+ steps :
152
+ - name : Setup Azure CLI
153
+ run : |
154
+ curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
155
+ az --version # Verify installation
156
+
157
+ - name : Login to Azure
158
+ run : |
159
+ az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
96
160
97
161
- name : Get Log Analytics Workspace and OpenAI from Resource Group
98
162
if : always()
@@ -126,7 +190,6 @@ jobs:
126
190
echo "OpenAI resource name : ${openai_resource_name}"
127
191
fi
128
192
129
-
130
193
- name : List KeyVaults and Store in Array
131
194
if : always()
132
195
id : list_keyvaults
@@ -177,7 +240,6 @@ jobs:
177
240
178
241
echo "Log analytics workspace resource purging completed successfully"
179
242
180
-
181
243
- name : Delete Bicep Deployment
182
244
if : always()
183
245
run : |
@@ -195,7 +257,6 @@ jobs:
195
257
echo "Resource group does not exists."
196
258
fi
197
259
198
-
199
260
- name : Wait for resource deletion to complete
200
261
if : always()
201
262
run : |
@@ -255,7 +316,6 @@ jobs:
255
316
break
256
317
fi
257
318
done
258
-
259
319
260
320
- name : Purging the Resources
261
321
if : always()
@@ -302,3 +362,9 @@ jobs:
302
362
fi
303
363
done
304
364
echo "Resource purging completed successfully"
365
+
366
+ - name : Logout from Azure
367
+ if : always()
368
+ run : |
369
+ az logout
370
+ echo "Logged out from Azure."
0 commit comments