|
1 | | -name: Deploy-Test-Cleanup-v2 |
| 1 | +name: Deploy-Test-Cleanup (v2) |
2 | 2 | on: |
3 | 3 | pull_request: |
4 | 4 | branches: |
@@ -211,6 +211,7 @@ jobs: |
211 | 211 | AZURE_LOCATION: ${{ steps.set_region.outputs.AZURE_LOCATION }} |
212 | 212 | AZURE_ENV_OPENAI_LOCATION: ${{ steps.set_region.outputs.AZURE_ENV_OPENAI_LOCATION }} |
213 | 213 | IMAGE_TAG: ${{ steps.determine_image_tag.outputs.IMAGE_TAG }} |
| 214 | + QUOTA_FAILED: ${{ steps.quota_failure_output.outputs.QUOTA_FAILED }} |
214 | 215 | env: |
215 | 216 | # For automatic triggers: force Non-WAF + Non-EXP, for manual dispatch: use inputs |
216 | 217 | WAF_ENABLED: ${{ github.event_name == 'workflow_dispatch' && (github.event.inputs.waf_enabled || false) || false }} |
@@ -303,21 +304,15 @@ jobs: |
303 | 304 | fi |
304 | 305 |
|
305 | 306 |
|
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 | | - ) |
316 | 307 |
|
317 | | - curl -X POST "${{ secrets.LOGIC_APP_URL }}" \ |
318 | | - -H "Content-Type: application/json" \ |
319 | | - -d "$EMAIL_BODY" || echo "Failed to send notification" |
320 | 308 |
|
| 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 | + |
321 | 316 | - name: Fail Pipeline if Quota Check Fails |
322 | 317 | if: env.QUOTA_FAILED == 'true' |
323 | 318 | run: exit 1 |
@@ -596,37 +591,7 @@ jobs: |
596 | 591 | az logout |
597 | 592 | echo "Logged out from Azure." |
598 | 593 |
|
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 | +
|
630 | 595 |
|
631 | 596 | - name: Generate Deploy Job Summary |
632 | 597 | if: always() |
@@ -781,28 +746,7 @@ jobs: |
781 | 746 | azd down --purge --force --no-prompt |
782 | 747 | echo "Deployment deleted successfully." |
783 | 748 |
|
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 | | - ) |
801 | 749 |
|
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" |
806 | 750 |
|
807 | 751 | - name: Logout from Azure |
808 | 752 | if: always() |
@@ -841,3 +785,159 @@ jobs: |
841 | 785 | echo "- Some resources may still exist in Azure" >> $GITHUB_STEP_SUMMARY |
842 | 786 | echo "- Manual cleanup may be required" >> $GITHUB_STEP_SUMMARY |
843 | 787 | 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" |
0 commit comments