1- name : Validate Deployment
1+ name : Deploy-Test-Cleanup Pipeline
22
33on :
4- push :
5- branches :
6- - main
7- schedule :
8- - cron : ' 0 5,17 * * *' # Runs at 5:00 AM and 5:00 PM GMT
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 }}
919
1020jobs :
1121 deploy :
1222 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 }}
1326 steps :
1427 - name : Checkout Code
1528 uses : actions/checkout@v3
3548 UNIQUE_RG_NAME="arg-${ACCL_NAME}-${SHORT_UUID}"
3649 echo "RESOURCE_GROUP_NAME=${UNIQUE_RG_NAME}" >> $GITHUB_ENV
3750 echo "Generated RESOURCE_GROUP_NAME: ${UNIQUE_RG_NAME}"
38-
3951
4052 - name : Check and Create Resource Group
4153 id : check_create_rg
4961 else
5062 echo "Resource group already exists."
5163 fi
64+ echo "RESOURCE_GROUP_NAME=${{ env.RESOURCE_GROUP_NAME }}" >> $GITHUB_OUTPUT
5265
53-
5466 - name : Generate Unique Solution Prefix
5567 id : generate_solution_prefix
5668 run : |
@@ -62,16 +74,42 @@ jobs:
6274 echo "SOLUTION_PREFIX=${UNIQUE_SOLUTION_PREFIX}" >> $GITHUB_ENV
6375 echo "Generated SOLUTION_PREFIX: ${UNIQUE_SOLUTION_PREFIX}"
6476
65-
6677 - name : Deploy Bicep Template
6778 id : deploy
6879 run : |
6980 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+
7092 az deployment group create \
93+ --name ${{ env.SOLUTION_PREFIX }}-deployment \
7194 --resource-group ${{ env.RESOURCE_GROUP_NAME }} \
7295 --template-file infra/main.bicep \
73- --parameters AzureAiServiceLocation=northcentralus Prefix=${{ env.SOLUTION_PREFIX }}
74-
96+ --parameters \
97+ Prefix="${{ env.SOLUTION_PREFIX }}" \
98+ AzureAiServiceLocation="eastus" \
99+ capacity=${{ env.GPT_MIN_CAPACITY }} \
100+ imageVersion="${IMAGE_TAG}"\
101+ --debug
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"
75113
76114 - name : Send Notification on Failure
77115 if : failure()
@@ -91,8 +129,37 @@ jobs:
91129 -H "Content-Type : application/json" \
92130 -d "$EMAIL_BODY" || echo "Failed to send notification"
93131
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 }}
94160
95161 - name : Get Log Analytics Workspace and OpenAI from Resource Group
162+ if : always()
96163 id : get_azure_resources
97164 run : |
98165
@@ -123,8 +190,8 @@ jobs:
123190 echo "OpenAI resource name : ${openai_resource_name}"
124191 fi
125192
126-
127193 - name : List KeyVaults and Store in Array
194+ if : always()
128195 id : list_keyvaults
129196 run : |
130197
@@ -158,6 +225,7 @@ jobs:
158225 fi
159226
160227 - name : Purge log analytics workspace
228+ if : always()
161229 id : log_analytics_workspace
162230 run : |
163231
@@ -172,9 +240,8 @@ jobs:
172240
173241 echo "Log analytics workspace resource purging completed successfully"
174242
175-
176243 - name : Delete Bicep Deployment
177- if : success ()
244+ if : always ()
178245 run : |
179246 set -e
180247 echo "Checking if resource group exists..."
@@ -190,8 +257,8 @@ jobs:
190257 echo "Resource group does not exists."
191258 fi
192259
193-
194260 - name : Wait for resource deletion to complete
261+ if : always()
195262 run : |
196263
197264 # List of keyvaults
@@ -249,10 +316,9 @@ jobs:
249316 break
250317 fi
251318 done
252-
253319
254320 - name : Purging the Resources
255- if : success ()
321+ if : always ()
256322 run : |
257323
258324 set -e
@@ -296,3 +362,9 @@ jobs:
296362 fi
297363 done
298364 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