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
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 }}
1019
1120jobs :
1221 deploy :
1322 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 }}
1426 steps :
1527 - name : Checkout Code
1628 uses : actions/checkout@v3
3648 UNIQUE_RG_NAME="arg-${ACCL_NAME}-${SHORT_UUID}"
3749 echo "RESOURCE_GROUP_NAME=${UNIQUE_RG_NAME}" >> $GITHUB_ENV
3850 echo "Generated RESOURCE_GROUP_NAME: ${UNIQUE_RG_NAME}"
39-
4051
4152 - name : Check and Create Resource Group
4253 id : check_create_rg
5061 else
5162 echo "Resource group already exists."
5263 fi
64+ echo "RESOURCE_GROUP_NAME=${{ env.RESOURCE_GROUP_NAME }}" >> $GITHUB_OUTPUT
5365
54-
5566 - name : Generate Unique Solution Prefix
5667 id : generate_solution_prefix
5768 run : |
@@ -63,17 +74,42 @@ jobs:
6374 echo "SOLUTION_PREFIX=${UNIQUE_SOLUTION_PREFIX}" >> $GITHUB_ENV
6475 echo "Generated SOLUTION_PREFIX: ${UNIQUE_SOLUTION_PREFIX}"
6576
66-
6777 - name : Deploy Bicep Template
6878 id : deploy
6979 run : |
7080 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+
7192 az deployment group create \
93+ --name ${{ env.SOLUTION_PREFIX }}-deployment \
7294 --resource-group ${{ env.RESOURCE_GROUP_NAME }} \
7395 --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}"\
75101 --debug
76102
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"
77113
78114 - name : Send Notification on Failure
79115 if : failure()
@@ -93,6 +129,34 @@ jobs:
93129 -H "Content-Type : application/json" \
94130 -d "$EMAIL_BODY" || echo "Failed to send notification"
95131
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 }}
96160
97161 - name : Get Log Analytics Workspace and OpenAI from Resource Group
98162 if : always()
@@ -126,7 +190,6 @@ jobs:
126190 echo "OpenAI resource name : ${openai_resource_name}"
127191 fi
128192
129-
130193 - name : List KeyVaults and Store in Array
131194 if : always()
132195 id : list_keyvaults
@@ -177,7 +240,6 @@ jobs:
177240
178241 echo "Log analytics workspace resource purging completed successfully"
179242
180-
181243 - name : Delete Bicep Deployment
182244 if : always()
183245 run : |
@@ -195,7 +257,6 @@ jobs:
195257 echo "Resource group does not exists."
196258 fi
197259
198-
199260 - name : Wait for resource deletion to complete
200261 if : always()
201262 run : |
@@ -255,7 +316,6 @@ jobs:
255316 break
256317 fi
257318 done
258-
259319
260320 - name : Purging the Resources
261321 if : always()
@@ -302,3 +362,9 @@ jobs:
302362 fi
303363 done
304364 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