Skip to content

Commit b4cdaad

Browse files
add deploy workflow for EXP deployment and add a input parameter in test automation workflow
1 parent 53d5947 commit b4cdaad

File tree

4 files changed

+300
-7
lines changed

4 files changed

+300
-7
lines changed

.github/workflows/deploy-exp.yml

Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
name: Deploy-Test-Cleanup (EXP)
2+
3+
on:
4+
push:
5+
branches:
6+
- deploy-wf-w-azd
7+
workflow_run:
8+
workflows: ["Build Docker and Optional Push"]
9+
types:
10+
- completed
11+
branches:
12+
- main
13+
- hotfix
14+
- dev
15+
- demo
16+
schedule:
17+
- cron: "20 11,23 * * *" # Runs at 11:20 AM and 11:20 PM GMT
18+
19+
env:
20+
GPT_MIN_CAPACITY: 150
21+
BRANCH_NAME: ${{ github.event.workflow_run.head_branch || github.head_ref || github.ref_name }}
22+
23+
jobs:
24+
deploy:
25+
runs-on: ubuntu-latest
26+
outputs:
27+
RESOURCE_GROUP_NAME: ${{ steps.check_create_rg.outputs.RESOURCE_GROUP_NAME }}
28+
AZURE_LOCATION: ${{ steps.set_region.outputs.AZURE_LOCATION }}
29+
ENV_NAME: ${{ steps.generate_env_name.outputs.ENV_NAME }}
30+
WEBAPP_URL: ${{ steps.get_output.outputs.WEBAPP_URL }}
31+
MACAE_URL_API: ${{ steps.get_backend_url.outputs.MACAE_URL_API }}
32+
steps:
33+
- name: Checkout Code
34+
uses: actions/checkout@v3
35+
36+
- name: Run Quota Check
37+
id: quota-check
38+
run: |
39+
export AZURE_CLIENT_ID=${{ secrets.AZURE_CLIENT_ID }}
40+
export AZURE_TENANT_ID=${{ secrets.AZURE_TENANT_ID }}
41+
export AZURE_CLIENT_SECRET=${{ secrets.AZURE_CLIENT_SECRET }}
42+
export AZURE_SUBSCRIPTION_ID="${{ secrets.AZURE_SUBSCRIPTION_ID }}"
43+
export GPT_MIN_CAPACITY="150"
44+
export AZURE_REGIONS="${{ vars.AZURE_REGIONS }}"
45+
46+
chmod +x infra/scripts/checkquota.sh
47+
if ! infra/scripts/checkquota.sh; then
48+
# If quota check fails due to insufficient quota, set the flag
49+
if grep -q "No region with sufficient quota found" infra/scripts/checkquota.sh; then
50+
echo "QUOTA_FAILED=true" >> $GITHUB_ENV
51+
fi
52+
exit 1 # Fail the pipeline if any other failure occurs
53+
fi
54+
55+
- name: Send Notification on Quota Failure
56+
if: env.QUOTA_FAILED == 'true'
57+
run: |
58+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
59+
EMAIL_BODY=$(cat <<EOF
60+
{
61+
"body": "<p>Dear Team,</p><p>The quota check has failed, and the MACAE WAF pipeline cannot proceed.</p><p><strong>Build URL:</strong> ${RUN_URL}</p><p>Please take necessary action.</p><p>Best regards,<br>Your Automation Team</p>"
62+
}
63+
EOF
64+
)
65+
66+
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
67+
-H "Content-Type: application/json" \
68+
-d "$EMAIL_BODY" || echo "Failed to send notification"
69+
70+
- name: Fail Pipeline if Quota Check Fails
71+
if: env.QUOTA_FAILED == 'true'
72+
run: exit 1
73+
74+
- name: Set Deployment Region
75+
id: set_region
76+
run: |
77+
echo "Selected Region: $VALID_REGION"
78+
echo "AZURE_LOCATION=$VALID_REGION" >> $GITHUB_ENV
79+
echo "AZURE_LOCATION=$VALID_REGION" >> $GITHUB_OUTPUT
80+
81+
- name: Setup Azure CLI
82+
run: |
83+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
84+
az --version # Verify installation
85+
86+
- name: Setup Azure Developer CLI
87+
run: |
88+
curl -fsSL https://aka.ms/install-azd.sh | sudo bash
89+
azd version
90+
91+
- name: Login to Azure
92+
id: login-azure
93+
run: |
94+
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
95+
azd auth login --client-id ${{ secrets.AZURE_CLIENT_ID }} --client-secret ${{ secrets.AZURE_CLIENT_SECRET }} --tenant-id ${{ secrets.AZURE_TENANT_ID }}
96+
97+
- name: Install Bicep CLI
98+
run: az bicep install
99+
100+
- name: Generate Resource Group Name
101+
id: generate_rg_name
102+
run: |
103+
echo "Generating a unique resource group name..."
104+
ACCL_NAME="macae" # Account name as specified
105+
SHORT_UUID=$(uuidgen | cut -d'-' -f1)
106+
UNIQUE_RG_NAME="arg-${ACCL_NAME}-${SHORT_UUID}"
107+
echo "RESOURCE_GROUP_NAME=${UNIQUE_RG_NAME}" >> $GITHUB_ENV
108+
echo "Generated Resource_GROUP_PREFIX: ${UNIQUE_RG_NAME}"
109+
110+
- name: Check and Create Resource Group
111+
id: check_create_rg
112+
run: |
113+
set -e
114+
echo "Checking if resource group exists..."
115+
rg_exists=$(az group exists --name ${{ env.RESOURCE_GROUP_NAME }})
116+
if [ "$rg_exists" = "false" ]; then
117+
echo "Resource group does not exist. Creating..."
118+
az group create --name ${{ env.RESOURCE_GROUP_NAME }} --location ${{ env.AZURE_LOCATION }} || { echo "Error creating resource group"; exit 1; }
119+
else
120+
echo "Resource group already exists."
121+
fi
122+
echo "RESOURCE_GROUP_NAME=${{ env.RESOURCE_GROUP_NAME }}" >> $GITHUB_OUTPUT
123+
124+
- name: Generate Unique Environment Name
125+
id: generate_env_name
126+
run: |
127+
COMMON_PART="macae"
128+
TIMESTAMP=$(date +%s)
129+
UPDATED_TIMESTAMP=$(echo $TIMESTAMP | tail -c 6)
130+
UNIQUE_ENV_NAME="${COMMON_PART}${UPDATED_TIMESTAMP}"
131+
echo "ENV_NAME=${UNIQUE_ENV_NAME}" >> $GITHUB_ENV
132+
echo "Generated Environment Name: ${UNIQUE_ENV_NAME}"
133+
echo "ENV_NAME=${UNIQUE_ENV_NAME}" >> $GITHUB_OUTPUT
134+
135+
- name: Create Environment and set Variables
136+
id: create_env
137+
run: |
138+
set -e
139+
140+
echo "Creating environment..."
141+
azd env new ${{ env.ENV_NAME }} --no-prompt
142+
echo "Environment created: ${{ env.ENV_NAME }}"
143+
144+
# set image tag based on branch
145+
if [[ "${{ env.BRANCH_NAME }}" == "main" ]]; then
146+
IMAGE_TAG="latest"
147+
elif [[ "${{ env.BRANCH_NAME }}" == "dev" ]]; then
148+
IMAGE_TAG="dev"
149+
elif [[ "${{ env.BRANCH_NAME }}" == "demo" ]]; then
150+
IMAGE_TAG="demo"
151+
elif [[ "${{ env.BRANCH_NAME }}" == "hotfix" ]]; then
152+
IMAGE_TAG="hotfix"
153+
else
154+
IMAGE_TAG="latest"
155+
fi
156+
echo "Using IMAGE_TAG: ${IMAGE_TAG}"
157+
158+
echo "Setting default subscription..."
159+
azd config set defaults.subscription ${{ secrets.AZURE_SUBSCRIPTION_ID }}
160+
161+
echo "Setting environment variables..."
162+
azd env set AZURE_RESOURCE_GROUP="${{ env.RESOURCE_GROUP_NAME }}"
163+
azd env set AZURE_SUBSCRIPTION_ID="${{ secrets.AZURE_SUBSCRIPTION_ID }}"
164+
azd env set AZURE_ENV_OPENAI_LOCATION="${{ env.AZURE_LOCATION }}"
165+
azd env set AZURE_ENV_MODEL_CAPACITY="${{ env.GPT_MIN_CAPACITY }}"
166+
azd env set AZURE_ENV_USE_WAF_ALIGNED_ARCHITECTURE=false
167+
azd env set AZURE_ENV_IMAGETAG="${IMAGE_TAG}"
168+
azd env set AZURE_ENV_LOG_ANALYTICS_WORKSPACE_ID="${{ secrets.EXP_LOG_WORKSPACE_RID }}"
169+
azd env set AZURE_ENV_FOUNDRY_PROJECT_ID="${{ secrets.EXP_AIF_PROJ_RID }}"
170+
echo "Environment variables set successfully:"
171+
azd env get-values
172+
173+
- name: Deploy using azd
174+
id: deploy
175+
run: |
176+
set -e
177+
azd up --no-prompt
178+
echo "Deployment completed successfully."
179+
180+
- name: Extract Web App and API App URLs
181+
id: get_output
182+
run: |
183+
WEBAPP_NAMES=$(az webapp list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --query "[].name" -o tsv)
184+
for NAME in $WEBAPP_NAMES; do
185+
if [[ $NAME == app-* ]]; then
186+
WEBAPP_URL="https://${NAME}.azurewebsites.net"
187+
echo "WEBAPP_URL=$WEBAPP_URL" >> $GITHUB_OUTPUT
188+
fi
189+
done
190+
191+
- name: Get Container App Backend URL
192+
id: get_backend_url
193+
run: |
194+
CONTAINER_APP_NAME=$(az containerapp list \
195+
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
196+
--query "[0].name" -o tsv)
197+
MACAE_URL_API=$(az containerapp show \
198+
--name "$CONTAINER_APP_NAME" \
199+
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
200+
--query "properties.configuration.ingress.fqdn" -o tsv)
201+
echo "MACAE_URL_API=https://${MACAE_URL_API}" >> $GITHUB_OUTPUT
202+
echo "CONTAINER_APP=${CONTAINER_APP_NAME}" >> $GITHUB_OUTPUT
203+
204+
- name: Logout from Azure
205+
if: always() && steps.login-azure.outcome == 'success'
206+
run: |
207+
az logout
208+
azd auth logout
209+
210+
e2e-test:
211+
needs: deploy
212+
uses: ./.github/workflows/test-automation.yml
213+
with:
214+
MACAE_WEB_URL: ${{ needs.deploy.outputs.WEBAPP_URL }}
215+
MACAE_URL_API: ${{ needs.deploy.outputs.MACAE_URL_API }}
216+
ACCELERATOR_NAME: "MACAE (EXP)"
217+
secrets: inherit
218+
219+
cleanup-deployment:
220+
if: always() && needs.deploy.outputs.RESOURCE_GROUP_NAME != ''
221+
needs: [deploy, e2e-test]
222+
runs-on: ubuntu-latest
223+
env:
224+
RESOURCE_GROUP_NAME: ${{ needs.deploy.outputs.RESOURCE_GROUP_NAME }}
225+
AZURE_LOCATION: ${{ needs.deploy.outputs.AZURE_LOCATION }}
226+
ENV_NAME: ${{ needs.deploy.outputs.ENV_NAME }}
227+
steps:
228+
- name: Checkout Code
229+
uses: actions/checkout@v4
230+
231+
- name: Setup Azure Developer CLI
232+
run: |
233+
curl -fsSL https://aka.ms/install-azd.sh | sudo bash
234+
azd version
235+
236+
- name: Login to Azure
237+
run: |
238+
azd auth login --client-id ${{ secrets.AZURE_CLIENT_ID }} --client-secret ${{ secrets.AZURE_CLIENT_SECRET }} --tenant-id ${{ secrets.AZURE_TENANT_ID }}
239+
azd config set defaults.subscription ${{ secrets.AZURE_SUBSCRIPTION_ID }}
240+
241+
- name: Select Environment
242+
run: |
243+
# Try to select the environment if it exists, otherwise create a minimal environment for cleanup
244+
azd env list
245+
if azd env list | grep -q "${{ env.ENV_NAME }}"; then
246+
echo "Environment ${{ env.ENV_NAME }} found, selecting it..."
247+
azd env select ${{ env.ENV_NAME }}
248+
else
249+
echo "Environment ${{ env.ENV_NAME }} not found, creating minimal environment for cleanup..."
250+
azd env new ${{ env.ENV_NAME }} --no-prompt
251+
azd env set AZURE_RESOURCE_GROUP "${{ env.RESOURCE_GROUP_NAME }}"
252+
azd env set AZURE_SUBSCRIPTION_ID "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
253+
azd env set AZURE_ENV_OPENAI_LOCATION="${{ env.AZURE_LOCATION }}"
254+
azd env set AZURE_ENV_USE_WAF_ALIGNED_ARCHITECTURE=false
255+
256+
fi
257+
258+
- name: Delete deployment using azd
259+
run: |
260+
set -e
261+
echo "Deleting deployment..."
262+
azd down --purge --force --no-prompt
263+
echo "Deployment deleted successfully."
264+
265+
- name: Send Notification on Failure
266+
if: always() && (failure() || needs.deploy.result == 'failure')
267+
run: |
268+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
269+
270+
# Construct the email body
271+
EMAIL_BODY=$(cat <<EOF
272+
{
273+
"body": "<p>Dear Team,</p><p>We would like to inform you that the Multi-Agent-Custom-Automation-Engine-Solution-Accelerator (EXP) Automation process has encountered an issue and has failed to complete successfully.</p><p><strong>Build URL:</strong> ${RUN_URL}<br> ${OUTPUT}</p><p>Please investigate the matter at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>"
274+
}
275+
EOF
276+
)
277+
278+
# Send the notification
279+
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
280+
-H "Content-Type: application/json" \
281+
-d "$EMAIL_BODY" || echo "Failed to send notification"
282+
283+
- name: Logout from Azure
284+
if: always()
285+
run: |
286+
azd auth logout
287+
echo "Logged out from Azure."

.github/workflows/deploy-waf.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ jobs:
211211
with:
212212
MACAE_WEB_URL: ${{ needs.deploy.outputs.WEBAPP_URL }}
213213
MACAE_URL_API: ${{ needs.deploy.outputs.MACAE_URL_API }}
214+
ACCELERATOR_NAME: "MACAE (WAF)"
214215
secrets: inherit
215216

216217
cleanup-deployment:
@@ -248,7 +249,7 @@ jobs:
248249
azd env set AZURE_RESOURCE_GROUP "${{ env.RESOURCE_GROUP_NAME }}"
249250
azd env set AZURE_SUBSCRIPTION_ID "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
250251
azd env set AZURE_ENV_OPENAI_LOCATION="${{ env.AZURE_LOCATION }}"
251-
azd env set AZURE_ENV_USE_WAF_ALIGNED_ARCHITECTURE=false
252+
azd env set AZURE_ENV_USE_WAF_ALIGNED_ARCHITECTURE=true
252253
253254
fi
254255

.github/workflows/test-automation.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ on:
55
workflow_call:
66
inputs:
77
MACAE_WEB_URL:
8-
required: false
8+
required: true
99
type: string
10-
description: "Web URL for MACAE (overrides environment variable)"
10+
description: "Web URL for MACAE"
1111
MACAE_URL_API:
12+
required: true
13+
type: string
14+
description: "API URL for MACAE"
15+
ACCELERATOR_NAME:
1216
required: false
1317
type: string
14-
description: "API URL for MACAE (overrides environment variable)"
18+
description: "Name of the accelerator"
19+
default: "MACAE"
1520
secrets:
1621
EMAILNOTIFICATION_LOGICAPP_URL_TA:
1722
required: false
@@ -23,7 +28,7 @@ jobs:
2328
env:
2429
MACAE_WEB_URL: ${{ inputs.MACAE_WEB_URL }}
2530
MACAE_URL_API: ${{ inputs.MACAE_URL_API }}
26-
accelerator_name: "MACAE"
31+
accelerator_name: ${{ inputs.ACCELERATOR_NAME }}
2732

2833
steps:
2934
- name: Checkout repository

tests/e2e-test/sample_dotenv_file.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
url = 'web app url'
2-
api_url = 'api_url_for_response_status'
1+
MACAE_WEB_URL = 'web app url'
2+
MACAE_URL_API = 'api_url_for_response_status'

0 commit comments

Comments
 (0)