Skip to content

Commit 0badaac

Browse files
Merge pull request #462 from microsoft/dev
fix: merging dev changes to main
2 parents 4107495 + 0c8dd4b commit 0badaac

32 files changed

+903
-76
lines changed

.github/workflows/deploy.yml

Lines changed: 105 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
name: Validate Deployment
1+
name: DocGen Deploy-Test-Cleanup Pipeline
22

33
on:
4-
push:
4+
workflow_run:
5+
workflows: ["Build Docker and Optional Push"]
6+
types:
7+
- completed
58
branches:
69
- main
10+
- dev
11+
- demo
712
schedule:
813
- cron: '0 9,21 * * *' # Runs at 9:00 AM and 9:00 PM GMT
914

1015
env:
11-
GPT_MIN_CAPACITY: 10
12-
TEXT_EMBEDDING_MIN_CAPACITY: 10
16+
GPT_MIN_CAPACITY: 250
17+
TEXT_EMBEDDING_MIN_CAPACITY: 40
18+
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
1319

1420
jobs:
1521
deploy:
1622
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 }}
1726
steps:
1827
- name: Checkout Code
1928
uses: actions/checkout@v3
@@ -54,7 +63,7 @@ jobs:
5463
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
5564
EMAIL_BODY=$(cat <<EOF
5665
{
57-
"body": "<p>Dear Team,</p><p>The quota check has failed, and the 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>"
66+
"body": "<p>Dear Team,</p><p>The quota check has failed, and the pipeline cannot proceed.</p><p><strong>Build URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a></p><p>Please take necessary action.</p><p>Best regards,<br>Your Automation Team</p>"
5867
}
5968
EOF
6069
)
@@ -97,14 +106,15 @@ jobs:
97106
else
98107
echo "Resource group already exists."
99108
fi
109+
echo "RESOURCE_GROUP_NAME=${{ env.RESOURCE_GROUP_NAME }}" >> $GITHUB_OUTPUT
100110
101111
- name: Generate Unique Solution Prefix
102112
id: generate_solution_prefix
103113
run: |
104114
set -e
105-
COMMON_PART="pslr"
115+
COMMON_PART="psldg"
106116
TIMESTAMP=$(date +%s)
107-
UPDATED_TIMESTAMP=$(echo $TIMESTAMP | tail -c 3)
117+
UPDATED_TIMESTAMP=$(echo $TIMESTAMP | tail -c 6)
108118
UNIQUE_SOLUTION_PREFIX="${COMMON_PART}${UPDATED_TIMESTAMP}"
109119
echo "SOLUTION_PREFIX=${UNIQUE_SOLUTION_PREFIX}" >> $GITHUB_ENV
110120
echo "Generated SOLUTION_PREFIX: ${UNIQUE_SOLUTION_PREFIX}"
@@ -113,7 +123,19 @@ jobs:
113123
id: deploy
114124
run: |
115125
set -e
126+
# set image tag based on branch
127+
if [[ "${{ env.BRANCH_NAME }}" == "main" ]]; then
128+
IMAGE_TAG="latest"
129+
elif [[ "${{ env.BRANCH_NAME }}" == "dev" ]]; then
130+
IMAGE_TAG="dev"
131+
elif [[ "${{ env.BRANCH_NAME }}" == "demo" ]]; then
132+
IMAGE_TAG="demo"
133+
else
134+
IMAGE_TAG="latest"
135+
fi
136+
116137
az deployment group create \
138+
--name ${{ env.SOLUTION_PREFIX }}-deployment \
117139
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
118140
--template-file infra/main.json \
119141
--parameters \
@@ -125,10 +147,75 @@ jobs:
125147
gptDeploymentCapacity=${{ env.GPT_MIN_CAPACITY }} \
126148
embeddingModel="text-embedding-ada-002" \
127149
embeddingDeploymentCapacity=${{ env.TEXT_EMBEDDING_MIN_CAPACITY }} \
128-
imageTag="latest"
129-
150+
imageTag="${IMAGE_TAG}"
151+
152+
- name: Get Deployment Output and extract Values
153+
id: get_output
154+
run: |
155+
set -e
156+
echo "Fetching deployment output..."
157+
BICEP_OUTPUT=$(az deployment group show --name ${{ env.SOLUTION_PREFIX }}-deployment --resource-group ${{ env.RESOURCE_GROUP_NAME }} --query "properties.outputs" -o json)
158+
echo "Extracting deployment output..."
159+
WEBAPP_URL=$(echo $BICEP_OUTPUT | jq -r '.weB_APP_URL.value')
160+
echo "WEBAPP_URL=$WEBAPP_URL" >> $GITHUB_OUTPUT
161+
STORAGE_ACCOUNT_NAME=$(echo $BICEP_OUTPUT | jq -r '.storagE_ACCOUNT_NAME.value')
162+
echo "STORAGE_ACCOUNT_NAME=$STORAGE_ACCOUNT_NAME" >> $GITHUB_ENV
163+
STORAGE_CONTAINER_NAME=$(echo $BICEP_OUTPUT | jq -r '.storagE_CONTAINER_NAME.value')
164+
echo "STORAGE_CONTAINER_NAME=$STORAGE_CONTAINER_NAME" >> $GITHUB_ENV
165+
KEY_VAULT_NAME=$(echo $BICEP_OUTPUT | jq -r '.keY_VAULT_NAME.value')
166+
echo "KEY_VAULT_NAME=$KEY_VAULT_NAME" >> $GITHUB_ENV
167+
COSMOSDB_ACCOUNT_NAME=$(echo $BICEP_OUTPUT | jq -r '.cosmosdB_ACCOUNT_NAME.value')
168+
echo "COSMOSDB_ACCOUNT_NAME=$COSMOSDB_ACCOUNT_NAME" >> $GITHUB_ENV
169+
echo "Deployment output: $BICEP_OUTPUT"
170+
171+
- name: Run Post-Deployment Script
172+
id: post_deploy
173+
run: |
174+
set -e
175+
az account set --subscription "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
176+
177+
echo "Running post-deployment script..."
178+
bash ./infra/scripts/copy_kb_files.sh \
179+
"${{ env.STORAGE_ACCOUNT_NAME }}" \
180+
"${{ env.STORAGE_CONTAINER_NAME }}" \
181+
"${{ secrets.AZURE_CLIENT_ID }}"
182+
bash ./infra/scripts/run_create_index_scripts.sh \
183+
"${{ env.KEY_VAULT_NAME }}" \
184+
"${{ secrets.AZURE_CLIENT_ID }}"
185+
186+
- name: Logout from Azure
187+
if: always()
188+
run: |
189+
az logout
190+
echo "Logged out from Azure."
191+
192+
193+
e2e-test:
194+
needs: deploy
195+
uses: ./.github/workflows/test-automation.yml
196+
with:
197+
DOCGEN_URL: ${{ needs.deploy.outputs.WEBAPP_URL }}
198+
secrets: inherit
199+
200+
cleanup-deployment:
201+
if: always() && needs.deploy.outputs.RESOURCE_GROUP_NAME != ''
202+
needs: [deploy, e2e-test]
203+
runs-on: ubuntu-latest
204+
env:
205+
RESOURCE_GROUP_NAME: ${{ needs.deploy.outputs.RESOURCE_GROUP_NAME }}
206+
steps:
207+
- name: Setup Azure CLI
208+
run: |
209+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
210+
az --version # Verify installation
211+
212+
- name: Login to Azure
213+
run: |
214+
az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
215+
az account set --subscription "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
216+
130217
- name: Extract AI Services and Key Vault Names
131-
if: always() && steps.check_create_rg.outcome == 'success'
218+
if: always()
132219
run: |
133220
echo "Fetching AI Services and Key Vault names before deletion..."
134221
@@ -288,17 +375,23 @@ jobs:
288375
289376
290377
- name: Send Notification on Failure
291-
if: failure()
378+
if: failure() || needs.deploy.result == 'failure'
292379
run: |
293380
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
294381
295382
EMAIL_BODY=$(cat <<EOF
296383
{
297-
"body": "<p>Dear Team,</p><p>We would like to inform you that the DocGen 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>"
384+
"body": "<p>Dear Team,</p><p>We would like to inform you that the DocGen Deployment Automation process has encountered an issue and has failed to complete successfully.</p><p><strong>Build URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a><br></p><p>Please investigate the matter at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>"
298385
}
299386
EOF
300387
)
301388
302389
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
303390
-H "Content-Type: application/json" \
304391
-d "$EMAIL_BODY" || echo "Failed to send notification"
392+
393+
- name: Logout from Azure
394+
if: always()
395+
run: |
396+
az logout
397+
echo "Logged out from Azure."

.github/workflows/python-app.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Test with pytest
3030
run: |
3131
export PYTHONPATH=$(pwd)/src
32-
pytest -v --show-capture=stdout -k "not integration"
32+
pytest -v --show-capture=stdout -k "not integration" ./src/tests
3333
3434
test_windows:
3535
runs-on:
@@ -47,4 +47,4 @@ jobs:
4747
- name: Test with pytest
4848
run: |
4949
$env:PYTHONPATH="$pwd\src"
50-
pytest -v --show-capture=stdout -k "not integration"
50+
pytest -v --show-capture=stdout -k "not integration" ./src/tests
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Test Automation DocGen
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
DOCGEN_URL:
7+
required: true
8+
type: string
9+
description: "Web URL for DocGen"
10+
secrets:
11+
EMAILNOTIFICATION_LOGICAPP_URL_TA:
12+
required: false
13+
description: "Logic App URL for email notifications"
14+
15+
env:
16+
url: ${{ inputs.DOCGEN_URL }}
17+
accelerator_name: "DocGen"
18+
19+
jobs:
20+
test:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v4
28+
with:
29+
python-version: '3.13'
30+
31+
- name: Install dependencies
32+
run: |
33+
python -m pip install --upgrade pip
34+
pip install -r tests/e2e-test/requirements.txt
35+
36+
- name: Ensure browsers are installed
37+
run: python -m playwright install --with-deps chromium
38+
39+
- name: Open URL
40+
run: |
41+
echo "Opening URL: ${{ env.url }}"
42+
python -m webbrowser "${{ env.url }}"
43+
44+
- name: Sleep for 30 seconds
45+
run: sleep 30s
46+
shell: bash
47+
48+
- name: Run tests(1)
49+
id: test1
50+
run: |
51+
xvfb-run pytest --headed --html=report/report.html --self-contained-html
52+
working-directory: tests/e2e-test
53+
continue-on-error: true
54+
55+
- name: Sleep for 30 seconds
56+
if: ${{ steps.test1.outcome == 'failure' }}
57+
run: sleep 30s
58+
shell: bash
59+
60+
- name: Run tests(2)
61+
if: ${{ steps.test1.outcome == 'failure' }}
62+
id: test2
63+
run: |
64+
xvfb-run pytest --headed --html=report/report.html --self-contained-html
65+
working-directory: tests/e2e-test
66+
continue-on-error: true
67+
68+
- name: Sleep for 60 seconds
69+
if: ${{ steps.test2.outcome == 'failure' }}
70+
run: sleep 60s
71+
shell: bash
72+
73+
- name: Run tests(3)
74+
if: ${{ steps.test2.outcome == 'failure' }}
75+
id: test3
76+
run: |
77+
xvfb-run pytest --headed --html=report/report.html --self-contained-html
78+
working-directory: tests/e2e-test
79+
80+
- name: Upload test report
81+
id: upload_report
82+
uses: actions/upload-artifact@v4
83+
if: ${{ !cancelled() }}
84+
with:
85+
name: test-report
86+
path: tests/e2e-test/report/*
87+
88+
- name: Send Notification
89+
if: always()
90+
run: |
91+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
92+
REPORT_URL=${{ steps.upload_report.outputs.artifact-url }}
93+
IS_SUCCESS=${{ steps.test1.outcome == 'success' || steps.test2.outcome == 'success' || steps.test3.outcome == 'success' }}
94+
# Construct the email body
95+
if [ "$IS_SUCCESS" = "true" ]; then
96+
EMAIL_BODY=$(cat <<EOF
97+
{
98+
"body": "<p>Dear Team,</p><p>We would like to inform you that the ${{ env.accelerator_name }} Test Automation process has completed successfully.</p><p><strong>Run URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a><br></p><p><strong>Test Report:</strong> <a href=\"${REPORT_URL}\">${REPORT_URL}</a></p><p>Best regards,<br>Your Automation Team</p>",
99+
"subject": "${{ env.accelerator_name }} Test Automation - Success"
100+
}
101+
EOF
102+
)
103+
else
104+
EMAIL_BODY=$(cat <<EOF
105+
{
106+
"body": "<p>Dear Team,</p><p>We would like to inform you that the ${{ env.accelerator_name }} Test Automation process has encountered an issue and has failed to complete successfully.</p><p><strong>Run URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a><br> ${OUTPUT}</p><p><strong>Test Report:</strong> <a href=\"${REPORT_URL}\">${REPORT_URL}</a></p><p>Please investigate the matter at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>",
107+
"subject": "${{ env.accelerator_name }} Test Automation - Failure"
108+
}
109+
EOF
110+
)
111+
fi
112+
113+
# Send the notification
114+
curl -X POST "${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}" \
115+
-H "Content-Type: application/json" \
116+
-d "$EMAIL_BODY" || echo "Failed to send notification"

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
3636
- name: Run Backend Tests with Coverage
3737
run: |
38-
if python -m pytest --cov=. --cov-report=xml --cov-report=html --cov-report=term-missing --junitxml=coverage-junit.xml; then
38+
if python -m pytest --cov=. --cov-report=xml --cov-report=html --cov-report=term-missing --junitxml=coverage-junit.xml ./src/tests; then
3939
echo "Tests completed, checking coverage."
4040
# Only fail if coverage does not meet criteria
4141
if [ -f coverage.xml ]; then

0 commit comments

Comments
 (0)