Skip to content

Commit b72c288

Browse files
Integration of deploy & test automation
1 parent 90f97be commit b72c288

2 files changed

Lines changed: 103 additions & 29 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 91 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
name: Validate Deployment
1+
name: Deploy-Test-Cleanup Pipeline
22

33
on:
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+
- PSL-US-18922
13+
schedule:
14+
- cron: '0 5,17 * * *' # Runs at 5:00 AM and 5:00 PM GMT
15+
workflow_dispatch:
16+
17+
env:
18+
GPT_MIN_CAPACITY: 200
19+
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
920

1021
jobs:
1122
deploy:
1223
runs-on: ubuntu-latest
24+
outputs:
25+
RESOURCE_GROUP_NAME: ${{ steps.check_create_rg.outputs.RESOURCE_GROUP_NAME }}
26+
WEBAPP_URL: ${{ steps.get_output.outputs.WEBAPP_URL }}
1327
steps:
1428
- name: Checkout Code
1529
uses: actions/checkout@v3
@@ -35,7 +49,6 @@ jobs:
3549
UNIQUE_RG_NAME="arg-${ACCL_NAME}-${SHORT_UUID}"
3650
echo "RESOURCE_GROUP_NAME=${UNIQUE_RG_NAME}" >> $GITHUB_ENV
3751
echo "Generated RESOURCE_GROUP_NAME: ${UNIQUE_RG_NAME}"
38-
3952
4053
- name: Check and Create Resource Group
4154
id: check_create_rg
@@ -50,7 +63,6 @@ jobs:
5063
echo "Resource group already exists."
5164
fi
5265
53-
5466
- name: Generate Unique Solution Prefix
5567
id: generate_solution_prefix
5668
run: |
@@ -62,16 +74,44 @@ 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 \
7193
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
7294
--template-file infra/main.bicep \
73-
--parameters AzureAiServiceLocation=northcentralus Prefix=${{ env.SOLUTION_PREFIX }}
74-
95+
--parameters \
96+
Prefix="${{ env.SOLUTION_PREFIX }}" \
97+
AzureAiServiceLocation="swedencentral" \
98+
deploymentType="GlobalStandard" \
99+
llmModel="gpt-4o" \
100+
gptModelVersion="2024-08-06" \
101+
capacity=${{ env.GPT_MIN_CAPACITY }} \
102+
imageVersion="${IMAGE_TAG}"\
103+
--debug
104+
105+
- name: Get Deployment Output and extract Values
106+
id: get_output
107+
run: |
108+
set -e
109+
echo "Fetching deployment output..."
110+
BICEP_OUTPUT=$(az deployment group show --name ${{ env.SOLUTION_PREFIX }}-deployment --resource-group ${{ env.RESOURCE_GROUP_NAME }} --query "properties.outputs" -o json)
111+
echo "Extracting deployment output..."
112+
WEBAPP_URL=$(echo $BICEP_OUTPUT | jq -r '.weB_APP_URL.value')
113+
echo "WEBAPP_URL=$WEBAPP_URL" >> $GITHUB_OUTPUT
114+
echo "Deployment output: $BICEP_OUTPUT"
75115
76116
- name: Send Notification on Failure
77117
if: failure()
@@ -91,8 +131,37 @@ jobs:
91131
-H "Content-Type: application/json" \
92132
-d "$EMAIL_BODY" || echo "Failed to send notification"
93133

134+
- name: Logout from Azure
135+
if: always()
136+
run: |
137+
az logout
138+
echo "Logged out from Azure."
139+
140+
e2e-test:
141+
needs: deploy
142+
uses: ./.github/workflows/test-automation.yml
143+
with:
144+
CODEMOD_WEB_URL: ${{ needs.deploy.outputs.WEBAPP_URL }}
145+
secrets: inherit
146+
147+
cleanup-deployment:
148+
if: always() && needs.deploy.outputs.RESOURCE_GROUP_NAME != ''
149+
needs: [deploy, e2e-test]
150+
runs-on: ubuntu-latest
151+
env:
152+
RESOURCE_GROUP_NAME: ${{ needs.deploy.outputs.RESOURCE_GROUP_NAME }}
153+
steps:
154+
- name: Setup Azure CLI
155+
run: |
156+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
157+
az --version # Verify installation
158+
159+
- name: Login to Azure
160+
run: |
161+
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
94162
95163
- name: Get Log Analytics Workspace and OpenAI from Resource Group
164+
if: always()
96165
id: get_azure_resources
97166
run: |
98167
@@ -123,8 +192,8 @@ jobs:
123192
echo "OpenAI resource name: ${openai_resource_name}"
124193
fi
125194

126-
127195
- name: List KeyVaults and Store in Array
196+
if: always()
128197
id: list_keyvaults
129198
run: |
130199
@@ -158,6 +227,7 @@ jobs:
158227
fi
159228
160229
- name: Purge log analytics workspace
230+
if: always()
161231
id: log_analytics_workspace
162232
run: |
163233
@@ -172,9 +242,8 @@ jobs:
172242
173243
echo "Log analytics workspace resource purging completed successfully"
174244
175-
176245
- name: Delete Bicep Deployment
177-
if: success()
246+
if: always()
178247
run: |
179248
set -e
180249
echo "Checking if resource group exists..."
@@ -190,8 +259,8 @@ jobs:
190259
echo "Resource group does not exists."
191260
fi
192261
193-
194262
- name: Wait for resource deletion to complete
263+
if: always()
195264
run: |
196265
197266
# List of keyvaults
@@ -249,10 +318,9 @@ jobs:
249318
break
250319
fi
251320
done
252-
253321
254322
- name: Purging the Resources
255-
if: success()
323+
if: always()
256324
run: |
257325
258326
set -e
@@ -296,3 +364,9 @@ jobs:
296364
fi
297365
done
298366
echo "Resource purging completed successfully"
367+
368+
- name: Logout from Azure
369+
if: always()
370+
run: |
371+
az logout
372+
echo "Logged out from Azure."

.github/workflows/test-automation.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
name: Test Automation Code Modernization
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
- dev
8-
paths:
9-
- 'tests/e2e-test/**'
10-
schedule:
11-
- cron: '0 13 * * *' # Runs at 1 PM UTC
12-
workflow_dispatch:
4+
workflow_call:
5+
inputs:
6+
CODEMOD_WEB_URL:
7+
required: true
8+
type: string
9+
description: "Web URL for Code Modernization"
10+
secrets:
11+
EMAILNOTIFICATION_LOGICAPP_URL_TA:
12+
required: false
13+
description: "Logic App URL for email notifications"
1314

1415
env:
15-
url: ${{ vars.CODEMOD_WEB_URL }}
16-
accelerator_name: "Code Modernization"
16+
url: ${{ inputs.CODEMOD_WEB_URL }}
17+
accelerator_name: "Code Modernization"
1718

1819
jobs:
1920
test:
20-
2121
runs-on: ubuntu-latest
2222
steps:
2323
- name: Checkout repository

0 commit comments

Comments
 (0)