Skip to content

Commit b1ae0f7

Browse files
Merge pull request #8 from Vamshi-Microsoft/vk-Notification
feat: Added Notification
2 parents 74b53e1 + 1926e4c commit b1ae0f7

2 files changed

Lines changed: 176 additions & 94 deletions

File tree

.github/workflows/deploy-Parameterized.yml

Lines changed: 166 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy-Test-Cleanup-v2
1+
name: Deploy-Test-Cleanup (v2)
22
on:
33
pull_request:
44
branches:
@@ -211,6 +211,7 @@ jobs:
211211
AZURE_LOCATION: ${{ steps.set_region.outputs.AZURE_LOCATION }}
212212
AZURE_ENV_OPENAI_LOCATION: ${{ steps.set_region.outputs.AZURE_ENV_OPENAI_LOCATION }}
213213
IMAGE_TAG: ${{ steps.determine_image_tag.outputs.IMAGE_TAG }}
214+
QUOTA_FAILED: ${{ steps.quota_failure_output.outputs.QUOTA_FAILED }}
214215
env:
215216
# For automatic triggers: force Non-WAF + Non-EXP, for manual dispatch: use inputs
216217
WAF_ENABLED: ${{ github.event_name == 'workflow_dispatch' && (github.event.inputs.waf_enabled || false) || false }}
@@ -303,21 +304,15 @@ jobs:
303304
fi
304305
305306
306-
- name: Send Notification on Quota Failure
307-
if: env.QUOTA_FAILED == 'true'
308-
run: |
309-
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
310-
EMAIL_BODY=$(cat <<EOF
311-
{
312-
"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>"
313-
}
314-
EOF
315-
)
316307
317-
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
318-
-H "Content-Type: application/json" \
319-
-d "$EMAIL_BODY" || echo "Failed to send notification"
320308
309+
- name: Set Quota Failure Output
310+
id: quota_failure_output
311+
if: env.QUOTA_FAILED == 'true'
312+
run: |
313+
echo "QUOTA_FAILED=true" >> $GITHUB_OUTPUT
314+
echo "Quota check failed - will notify via separate notification job"
315+
321316
- name: Fail Pipeline if Quota Check Fails
322317
if: env.QUOTA_FAILED == 'true'
323318
run: exit 1
@@ -596,37 +591,7 @@ jobs:
596591
az logout
597592
echo "Logged out from Azure."
598593
599-
- name: Send Notification
600-
if: always()
601-
run: |
602-
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
603-
WEBAPP_URL="${{ steps.get_output.outputs.WEBAPP_URL }}"
604-
RESOURCE_GROUP="${{ steps.check_create_rg.outputs.RESOURCE_GROUP_NAME }}"
605-
IMAGE_TAG="${{ steps.determine_image_tag.outputs.IMAGE_TAG }}"
606-
IS_SUCCESS=${{ job.status == 'success' }}
607-
608-
# Construct the email body based on deployment result
609-
if [ "$IS_SUCCESS" = "true" ]; then
610-
EMAIL_BODY=$(cat <<EOF
611-
{
612-
"body": "<p>Dear Team,</p><p>We would like to inform you that the DocGen deployment process has completed successfully.</p><p><strong>Deployment Details:</strong><br>• Resource Group: ${RESOURCE_GROUP}<br>• Web App URL: <a href=\"${WEBAPP_URL}\">${WEBAPP_URL}</a></p><p><strong>Run URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a></p><p>The application is now ready for use.</p><p>Best regards,<br>Your Automation Team</p>",
613-
"subject": "DocGen Deployment - Success"
614-
}
615-
EOF
616-
)
617-
else
618-
EMAIL_BODY=$(cat <<EOF
619-
{
620-
"body": "<p>Dear Team,</p><p>We would like to inform you that the DocGen deployment process has encountered an issue and has failed to complete successfully.</p><p><strong>Deployment Details:</strong><br>• Resource Group: ${RESOURCE_GROUP}</p><p><strong>Run URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a></p><p>Please investigate the matter at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>",
621-
"subject": "DocGen Deployment - Failure"
622-
}
623-
EOF
624-
)
625-
fi
626-
# Send the notification
627-
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
628-
-H "Content-Type: application/json" \
629-
-d "$EMAIL_BODY" || echo "Failed to send notification"
594+
630595
631596
- name: Generate Deploy Job Summary
632597
if: always()
@@ -781,28 +746,7 @@ jobs:
781746
azd down --purge --force --no-prompt
782747
echo "Deployment deleted successfully."
783748
784-
- name: Send Notification on Failure
785-
if: always() && (failure() || needs.deploy.result == 'failure')
786-
run: |
787-
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
788-
789-
# Get deployment configuration for notification
790-
WAF_STATUS="${{ github.event.inputs.waf_enabled || true }}"
791-
EXP_STATUS="${{ env.EXP || false }}"
792-
CLEANUP_STATUS="${{ github.event.inputs.cleanup_resources || true }}"
793-
794-
# Construct the email body
795-
EMAIL_BODY=$(cat <<EOF
796-
{
797-
"body": "<p>Dear Team,</p><p>We would like to inform you that the document-generation-solution-accelerator Unified Deployment process has encountered an issue and has failed to complete successfully.</p><p><strong>Configuration:</strong><br>- WAF Enabled: ${WAF_STATUS}<br>- EXP: ${EXP_STATUS}<br>- Cleanup: ${CLEANUP_STATUS}</p><p><strong>Build URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a></p><p>Please investigate the matter at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>"
798-
}
799-
EOF
800-
)
801749
802-
# Send the notification
803-
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
804-
-H "Content-Type: application/json" \
805-
-d "$EMAIL_BODY" || echo "Failed to send notification"
806750
807751
- name: Logout from Azure
808752
if: always()
@@ -841,3 +785,159 @@ jobs:
841785
echo "- Some resources may still exist in Azure" >> $GITHUB_STEP_SUMMARY
842786
echo "- Manual cleanup may be required" >> $GITHUB_STEP_SUMMARY
843787
fi
788+
789+
send-notification:
790+
# ============================================================================
791+
# NOTIFICATION JOB
792+
# ============================================================================
793+
# Condition: Always runs to send appropriate notifications based on job results
794+
# Sends notifications for:
795+
# 1. Quota check failures (when deploy job fails due to quota issues)
796+
# 2. Deployment failures (when deploy job fails for other reasons)
797+
# 3. Success notifications (when deploy succeeds and e2e tests succeed)
798+
# 4. Test failure notifications (when deploy succeeds but e2e tests fail)
799+
# ============================================================================
800+
if: always()
801+
needs: [docker-build, deploy, e2e-test]
802+
runs-on: ubuntu-latest
803+
steps:
804+
- name: Send Quota Failure Notification
805+
if: needs.deploy.result == 'failure' && needs.deploy.outputs.QUOTA_FAILED == 'true'
806+
run: |
807+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
808+
EMAIL_BODY=$(cat <<EOF
809+
{
810+
"body": "<p>Dear Team,</p><p>We would like to inform you that the DocGen deployment has failed due to insufficient quota in the requested regions.</p><p><strong>Issue Details:</strong><br>• Quota check failed for GPT and Text Embedding models<br>• Required GPT Capacity: ${{ env.GPT_MIN_CAPACITY }}<br>• Required Text Embedding Capacity: ${{ env.TEXT_EMBEDDING_MIN_CAPACITY }}<br>• Checked Regions: ${{ vars.AZURE_REGIONS }}</p><p><strong>Action Required:</strong><br>• Increase quota limits in Azure portal<br>• Or select a different region with available quota</p><p><strong>Build URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a></p><p>Please resolve the quota issue and retry the deployment.</p><p>Best regards,<br>Your Automation Team</p>",
811+
"subject": "DocGen Pipeline - Failed (Insufficient Quota)"
812+
}
813+
EOF
814+
)
815+
816+
echo "===== DEBUG: Quota Failure EMAIL_BODY (raw JSON) ====="
817+
printf '%s\n' "$EMAIL_BODY"
818+
echo "====================================================="
819+
820+
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
821+
-H "Content-Type: application/json" \
822+
-d "$EMAIL_BODY" || echo "Failed to send quota failure notification"
823+
824+
- name: Send Deployment Failure Notification
825+
if: needs.deploy.result == 'failure' && needs.deploy.outputs.QUOTA_FAILED != 'true'
826+
run: |
827+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
828+
RESOURCE_GROUP="${{ needs.deploy.outputs.RESOURCE_GROUP_NAME }}"
829+
830+
EMAIL_BODY=$(cat <<EOF
831+
{
832+
"body": "<p>Dear Team,</p><p>We would like to inform you that the DocGen deployment process has encountered an issue and has failed to complete successfully.</p><p><strong>Deployment Details:</strong><br>• Resource Group: ${RESOURCE_GROUP}<br>• WAF Enabled: ${{ env.WAF_ENABLED }}<br>• EXP Enabled: ${{ env.EXP }}</p><p><strong>Build URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a></p><p>Please investigate the deployment failure at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>",
833+
"subject": "DocGen Deployment - Failed"
834+
}
835+
EOF
836+
)
837+
echo "===== DEBUG: Deployment Failure EMAIL_BODY (raw JSON) ====="
838+
printf '%s\n' "$EMAIL_BODY"
839+
echo "=========================================================="
840+
841+
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
842+
-H "Content-Type: application/json" \
843+
-d "$EMAIL_BODY" || echo "Failed to send deployment failure notification"
844+
845+
- name: Send Success Notification
846+
if: needs.deploy.result == 'success' && (needs.e2e-test.result == 'skipped' || needs.e2e-test.outputs.TEST_SUCCESS == 'true')
847+
run: |
848+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
849+
WEBAPP_URL="${{ needs.deploy.outputs.WEBAPP_URL || github.event.inputs.existing_webapp_url }}"
850+
RESOURCE_GROUP="${{ needs.deploy.outputs.RESOURCE_GROUP_NAME }}"
851+
TEST_REPORT_URL="${{ needs.e2e-test.outputs.TEST_REPORT_URL }}"
852+
853+
# Determine test status message
854+
if [ "${{ needs.e2e-test.result }}" = "skipped" ]; then
855+
TEST_STATUS_MSG="• E2E Tests: Skipped (as configured)"
856+
else
857+
TEST_STATUS_MSG="• E2E Tests: Passed<br>• Test Report: <a href=\"${TEST_REPORT_URL}\">View Report</a>"
858+
fi
859+
860+
EMAIL_BODY=$(cat <<EOF
861+
{
862+
"body": "<p>Dear Team,</p><p>We would like to inform you that the DocGen deployment and testing process has completed successfully.</p><p><strong>Deployment Details:</strong><br>• Resource Group: ${RESOURCE_GROUP}<br>• Web App URL: <a href=\"${WEBAPP_URL}\">${WEBAPP_URL}</a><br>${TEST_STATUS_MSG}</p><p><strong>Configuration:</strong><br>• WAF Enabled: ${{ env.WAF_ENABLED }}<br>• EXP Enabled: ${{ env.EXP }}</p><p><strong>Build URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a></p><p>The application is now ready for use.</p><p>Best regards,<br>Your Automation Team</p>",
863+
"subject": "DocGen Pipeline - Success"
864+
}
865+
EOF
866+
)
867+
echo "===== DEBUG: Success EMAIL_BODY (raw JSON) ====="
868+
printf '%s\n' "$EMAIL_BODY"
869+
echo "==============================================="
870+
871+
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
872+
-H "Content-Type: application/json" \
873+
-d "$EMAIL_BODY" || echo "Failed to send success notification"
874+
875+
- name: Send Test Failure Notification
876+
if: needs.deploy.result == 'success' && needs.e2e-test.result != 'skipped' && needs.e2e-test.outputs.TEST_SUCCESS != 'true'
877+
run: |
878+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
879+
TEST_REPORT_URL="${{ needs.e2e-test.outputs.TEST_REPORT_URL }}"
880+
WEBAPP_URL="${{ needs.deploy.outputs.WEBAPP_URL || github.event.inputs.existing_webapp_url }}"
881+
RESOURCE_GROUP="${{ needs.deploy.outputs.RESOURCE_GROUP_NAME }}"
882+
883+
EMAIL_BODY=$(cat <<EOF
884+
{
885+
"body": "<p>Dear Team,</p><p>We would like to inform you that while the DocGen deployment was successful, the E2E test automation process has encountered issues and failed to complete successfully.</p><p><strong>Deployment Details:</strong><br>• Resource Group: ${RESOURCE_GROUP}<br>• Web App URL: <a href=\"${WEBAPP_URL}\">${WEBAPP_URL}</a><br>• Deployment Status: ✅ Success<br>• E2E Tests: ❌ Failed</p><p><strong>Test Details:</strong><br>• Test Report: <a href=\"${TEST_REPORT_URL}\">View Report</a></p><p><strong>Build URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a></p><p>The application has been deployed successfully, but please investigate the test failures to ensure functionality.</p><p>Best regards,<br>Your Automation Team</p>",
886+
"subject": "DocGen Pipeline - Deployment Success, Tests Failed"
887+
}
888+
EOF
889+
)
890+
891+
echo "===== DEBUG: Test Failure EMAIL_BODY (raw JSON) ====="
892+
printf '%s\n' "$EMAIL_BODY"
893+
echo "===================================================="
894+
895+
curl -X POST "${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}" \
896+
-H "Content-Type: application/json" \
897+
-d "$EMAIL_BODY" || echo "Failed to send test failure notification"
898+
899+
- name: Send Existing URL Success Notification
900+
# Scenario: Deployment skipped (existing URL provided) AND e2e tests passed
901+
if: needs.deploy.result == 'skipped' && github.event.inputs.existing_webapp_url != '' && needs.e2e-test.result == 'success' && (needs.e2e-test.outputs.TEST_SUCCESS == 'true' || needs.e2e-test.outputs.TEST_SUCCESS == '')
902+
run: |
903+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
904+
EXISTING_URL="${{ github.event.inputs.existing_webapp_url }}"
905+
TEST_REPORT_URL="${{ needs.e2e-test.outputs.TEST_REPORT_URL }}"
906+
EMAIL_BODY=$(cat <<EOF
907+
{
908+
"body": "<p>Dear Team,</p><p>The DocGen pipeline executed against the <strong>existing WebApp URL</strong> you supplied and the E2E tests completed successfully.</p><p><strong>Test Results:</strong><br>• Status: ✅ Passed<br>${TEST_REPORT_URL:+• Test Report: <a href=\"${TEST_REPORT_URL}\">View Report</a>}<br>• Target URL: <a href=\"${EXISTING_URL}\">${EXISTING_URL}</a></p><p><strong>Deployment:</strong> Skipped (existing URL reuse)</p><p><strong>Build URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a></p><p>No infrastructure changes were made.</p><p>Best regards,<br>Your Automation Team</p>",
909+
"subject": "DocGen Pipeline - Existing URL Tests Passed"
910+
}
911+
EOF
912+
)
913+
914+
echo "===== DEBUG: Existing URL Success EMAIL_BODY (raw JSON) ====="
915+
printf '%s\n' "$EMAIL_BODY"
916+
echo "==========================================================="
917+
918+
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
919+
-H "Content-Type: application/json" \
920+
-d "$EMAIL_BODY" || echo "Failed to send existing URL success notification"
921+
922+
- name: Send Existing URL Test Failure Notification
923+
# Scenario: Deployment skipped (existing URL provided) AND e2e tests failed
924+
if: needs.deploy.result == 'skipped' && github.event.inputs.existing_webapp_url != '' && needs.e2e-test.result == 'failure'
925+
run: |
926+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
927+
EXISTING_URL="${{ github.event.inputs.existing_webapp_url }}"
928+
TEST_REPORT_URL="${{ needs.e2e-test.outputs.TEST_REPORT_URL }}"
929+
EMAIL_BODY=$(cat <<EOF
930+
{
931+
"body": "<p>Dear Team,</p><p>The DocGen pipeline targeted the <strong>existing WebApp URL</strong> you supplied. Deployment was intentionally skipped, but the E2E tests have <strong>failed</strong>.</p><p><strong>Failure Details:</strong><br>• Target URL: <a href=\"${EXISTING_URL}\">${EXISTING_URL}</a><br>${TEST_REPORT_URL:+• Test Report: <a href=\"${TEST_REPORT_URL}\">View Report</a>}<br>• Deployment: Skipped (existing URL reuse)</p><p><strong>Recommended Actions:</strong><br>• Inspect the failing test cases<br>• Verify application availability and recent changes<br>• Re-run tests after fixes</p><p><strong>Build URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a></p><p>Best regards,<br>Your Automation Team</p>",
932+
"subject": "DocGen Pipeline - Existing URL Tests Failed"
933+
}
934+
EOF
935+
)
936+
937+
echo "===== DEBUG: Existing URL Failure EMAIL_BODY (raw JSON) ====="
938+
printf '%s\n' "$EMAIL_BODY"
939+
echo "==========================================================="
940+
941+
curl -X POST "${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}" \
942+
-H "Content-Type: application/json" \
943+
-d "$EMAIL_BODY" || echo "Failed to send existing URL test failure notification"

.github/workflows/test-automation.yml

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ on:
1111
EMAILNOTIFICATION_LOGICAPP_URL_TA:
1212
required: false
1313
description: "Logic App URL for email notifications"
14+
outputs:
15+
TEST_SUCCESS:
16+
description: "Whether tests passed"
17+
value: ${{ jobs.test.outputs.TEST_SUCCESS }}
18+
TEST_REPORT_URL:
19+
description: "URL to test report artifact"
20+
value: ${{ jobs.test.outputs.TEST_REPORT_URL }}
1421

1522
env:
1623
url: ${{ inputs.DOCGEN_URL }}
@@ -19,6 +26,9 @@ env:
1926
jobs:
2027
test:
2128
runs-on: ubuntu-latest
29+
outputs:
30+
TEST_SUCCESS: ${{ steps.test1.outcome == 'success' || steps.test2.outcome == 'success' || steps.test3.outcome == 'success' }}
31+
TEST_REPORT_URL: ${{ steps.upload_report.outputs.artifact-url }}
2232
steps:
2333
- name: Checkout repository
2434
uses: actions/checkout@v5
@@ -85,35 +95,7 @@ jobs:
8595
name: test-report
8696
path: tests/e2e-test/report/*
8797

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
11298

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"
11799

118100
- name: Generate E2E Test Summary
119101
if: always()

0 commit comments

Comments
 (0)