diff --git a/.github/workflows/deploy-Parameterized.yml b/.github/workflows/deploy-Parameterized.yml index 6028c8f61..a1c83d71a 100644 --- a/.github/workflows/deploy-Parameterized.yml +++ b/.github/workflows/deploy-Parameterized.yml @@ -1,4 +1,4 @@ -name: Deploy-Test-Cleanup-v2 +name: Deploy-Test-Cleanup (v2) on: pull_request: branches: @@ -211,6 +211,7 @@ jobs: AZURE_LOCATION: ${{ steps.set_region.outputs.AZURE_LOCATION }} AZURE_ENV_OPENAI_LOCATION: ${{ steps.set_region.outputs.AZURE_ENV_OPENAI_LOCATION }} IMAGE_TAG: ${{ steps.determine_image_tag.outputs.IMAGE_TAG }} + QUOTA_FAILED: ${{ steps.quota_failure_output.outputs.QUOTA_FAILED }} env: # For automatic triggers: force Non-WAF + Non-EXP, for manual dispatch: use inputs WAF_ENABLED: ${{ github.event_name == 'workflow_dispatch' && (github.event.inputs.waf_enabled || false) || false }} @@ -303,21 +304,15 @@ jobs: fi - - name: Send Notification on Quota Failure - if: env.QUOTA_FAILED == 'true' - run: | - RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" - EMAIL_BODY=$(cat <Dear Team,

The quota check has failed, and the pipeline cannot proceed.

Build URL: ${RUN_URL}

Please take necessary action.

Best regards,
Your Automation Team

" - } - EOF - ) - curl -X POST "${{ secrets.LOGIC_APP_URL }}" \ - -H "Content-Type: application/json" \ - -d "$EMAIL_BODY" || echo "Failed to send notification" + - name: Set Quota Failure Output + id: quota_failure_output + if: env.QUOTA_FAILED == 'true' + run: | + echo "QUOTA_FAILED=true" >> $GITHUB_OUTPUT + echo "Quota check failed - will notify via separate notification job" + - name: Fail Pipeline if Quota Check Fails if: env.QUOTA_FAILED == 'true' run: exit 1 @@ -596,37 +591,7 @@ jobs: az logout echo "Logged out from Azure." - - name: Send Notification - if: always() - run: | - RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" - WEBAPP_URL="${{ steps.get_output.outputs.WEBAPP_URL }}" - RESOURCE_GROUP="${{ steps.check_create_rg.outputs.RESOURCE_GROUP_NAME }}" - IMAGE_TAG="${{ steps.determine_image_tag.outputs.IMAGE_TAG }}" - IS_SUCCESS=${{ job.status == 'success' }} - - # Construct the email body based on deployment result - if [ "$IS_SUCCESS" = "true" ]; then - EMAIL_BODY=$(cat <Dear Team,

We would like to inform you that the DocGen deployment process has completed successfully.

Deployment Details:
• Resource Group: ${RESOURCE_GROUP}
• Web App URL: ${WEBAPP_URL}

Run URL: ${RUN_URL}

The application is now ready for use.

Best regards,
Your Automation Team

", - "subject": "DocGen Deployment - Success" - } - EOF - ) - else - EMAIL_BODY=$(cat <Dear Team,

We would like to inform you that the DocGen deployment process has encountered an issue and has failed to complete successfully.

Deployment Details:
• Resource Group: ${RESOURCE_GROUP}

Run URL: ${RUN_URL}

Please investigate the matter at your earliest convenience.

Best regards,
Your Automation Team

", - "subject": "DocGen Deployment - Failure" - } - EOF - ) - fi - # Send the notification - curl -X POST "${{ secrets.LOGIC_APP_URL }}" \ - -H "Content-Type: application/json" \ - -d "$EMAIL_BODY" || echo "Failed to send notification" + - name: Generate Deploy Job Summary if: always() @@ -781,28 +746,7 @@ jobs: azd down --purge --force --no-prompt echo "Deployment deleted successfully." - - name: Send Notification on Failure - if: always() && (failure() || needs.deploy.result == 'failure') - run: | - RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" - - # Get deployment configuration for notification - WAF_STATUS="${{ github.event.inputs.waf_enabled || true }}" - EXP_STATUS="${{ env.EXP || false }}" - CLEANUP_STATUS="${{ github.event.inputs.cleanup_resources || true }}" - - # Construct the email body - EMAIL_BODY=$(cat <Dear Team,

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.

Configuration:
- WAF Enabled: ${WAF_STATUS}
- EXP: ${EXP_STATUS}
- Cleanup: ${CLEANUP_STATUS}

Build URL: ${RUN_URL}

Please investigate the matter at your earliest convenience.

Best regards,
Your Automation Team

" - } - EOF - ) - # Send the notification - curl -X POST "${{ secrets.LOGIC_APP_URL }}" \ - -H "Content-Type: application/json" \ - -d "$EMAIL_BODY" || echo "Failed to send notification" - name: Logout from Azure if: always() @@ -841,3 +785,159 @@ jobs: echo "- Some resources may still exist in Azure" >> $GITHUB_STEP_SUMMARY echo "- Manual cleanup may be required" >> $GITHUB_STEP_SUMMARY fi + + send-notification: + # ============================================================================ + # NOTIFICATION JOB + # ============================================================================ + # Condition: Always runs to send appropriate notifications based on job results + # Sends notifications for: + # 1. Quota check failures (when deploy job fails due to quota issues) + # 2. Deployment failures (when deploy job fails for other reasons) + # 3. Success notifications (when deploy succeeds and e2e tests succeed) + # 4. Test failure notifications (when deploy succeeds but e2e tests fail) + # ============================================================================ + if: always() + needs: [docker-build, deploy, e2e-test] + runs-on: ubuntu-latest + steps: + - name: Send Quota Failure Notification + if: needs.deploy.result == 'failure' && needs.deploy.outputs.QUOTA_FAILED == 'true' + run: | + RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + EMAIL_BODY=$(cat <Dear Team,

We would like to inform you that the DocGen deployment has failed due to insufficient quota in the requested regions.

Issue Details:
• Quota check failed for GPT and Text Embedding models
• Required GPT Capacity: ${{ env.GPT_MIN_CAPACITY }}
• Required Text Embedding Capacity: ${{ env.TEXT_EMBEDDING_MIN_CAPACITY }}
• Checked Regions: ${{ vars.AZURE_REGIONS }}

Action Required:
• Increase quota limits in Azure portal
• Or select a different region with available quota

Build URL: ${RUN_URL}

Please resolve the quota issue and retry the deployment.

Best regards,
Your Automation Team

", + "subject": "DocGen Pipeline - Failed (Insufficient Quota)" + } + EOF + ) + + echo "===== DEBUG: Quota Failure EMAIL_BODY (raw JSON) =====" + printf '%s\n' "$EMAIL_BODY" + echo "=====================================================" + + curl -X POST "${{ secrets.LOGIC_APP_URL }}" \ + -H "Content-Type: application/json" \ + -d "$EMAIL_BODY" || echo "Failed to send quota failure notification" + + - name: Send Deployment Failure Notification + if: needs.deploy.result == 'failure' && needs.deploy.outputs.QUOTA_FAILED != 'true' + run: | + RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + RESOURCE_GROUP="${{ needs.deploy.outputs.RESOURCE_GROUP_NAME }}" + + EMAIL_BODY=$(cat <Dear Team,

We would like to inform you that the DocGen deployment process has encountered an issue and has failed to complete successfully.

Deployment Details:
• Resource Group: ${RESOURCE_GROUP}
• WAF Enabled: ${{ env.WAF_ENABLED }}
• EXP Enabled: ${{ env.EXP }}

Build URL: ${RUN_URL}

Please investigate the deployment failure at your earliest convenience.

Best regards,
Your Automation Team

", + "subject": "DocGen Deployment - Failed" + } + EOF + ) + echo "===== DEBUG: Deployment Failure EMAIL_BODY (raw JSON) =====" + printf '%s\n' "$EMAIL_BODY" + echo "==========================================================" + + curl -X POST "${{ secrets.LOGIC_APP_URL }}" \ + -H "Content-Type: application/json" \ + -d "$EMAIL_BODY" || echo "Failed to send deployment failure notification" + + - name: Send Success Notification + if: needs.deploy.result == 'success' && (needs.e2e-test.result == 'skipped' || needs.e2e-test.outputs.TEST_SUCCESS == 'true') + run: | + RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + WEBAPP_URL="${{ needs.deploy.outputs.WEBAPP_URL || github.event.inputs.existing_webapp_url }}" + RESOURCE_GROUP="${{ needs.deploy.outputs.RESOURCE_GROUP_NAME }}" + TEST_REPORT_URL="${{ needs.e2e-test.outputs.TEST_REPORT_URL }}" + + # Determine test status message + if [ "${{ needs.e2e-test.result }}" = "skipped" ]; then + TEST_STATUS_MSG="• E2E Tests: Skipped (as configured)" + else + TEST_STATUS_MSG="• E2E Tests: Passed
• Test Report: View Report" + fi + + EMAIL_BODY=$(cat <Dear Team,

We would like to inform you that the DocGen deployment and testing process has completed successfully.

Deployment Details:
• Resource Group: ${RESOURCE_GROUP}
• Web App URL: ${WEBAPP_URL}
${TEST_STATUS_MSG}

Configuration:
• WAF Enabled: ${{ env.WAF_ENABLED }}
• EXP Enabled: ${{ env.EXP }}

Build URL: ${RUN_URL}

The application is now ready for use.

Best regards,
Your Automation Team

", + "subject": "DocGen Pipeline - Success" + } + EOF + ) + echo "===== DEBUG: Success EMAIL_BODY (raw JSON) =====" + printf '%s\n' "$EMAIL_BODY" + echo "===============================================" + + curl -X POST "${{ secrets.LOGIC_APP_URL }}" \ + -H "Content-Type: application/json" \ + -d "$EMAIL_BODY" || echo "Failed to send success notification" + + - name: Send Test Failure Notification + if: needs.deploy.result == 'success' && needs.e2e-test.result != 'skipped' && needs.e2e-test.outputs.TEST_SUCCESS != 'true' + run: | + RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + TEST_REPORT_URL="${{ needs.e2e-test.outputs.TEST_REPORT_URL }}" + WEBAPP_URL="${{ needs.deploy.outputs.WEBAPP_URL || github.event.inputs.existing_webapp_url }}" + RESOURCE_GROUP="${{ needs.deploy.outputs.RESOURCE_GROUP_NAME }}" + + EMAIL_BODY=$(cat <Dear Team,

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.

Deployment Details:
• Resource Group: ${RESOURCE_GROUP}
• Web App URL: ${WEBAPP_URL}
• Deployment Status: ✅ Success
• E2E Tests: ❌ Failed

Test Details:
• Test Report: View Report

Build URL: ${RUN_URL}

The application has been deployed successfully, but please investigate the test failures to ensure functionality.

Best regards,
Your Automation Team

", + "subject": "DocGen Pipeline - Deployment Success, Tests Failed" + } + EOF + ) + + echo "===== DEBUG: Test Failure EMAIL_BODY (raw JSON) =====" + printf '%s\n' "$EMAIL_BODY" + echo "====================================================" + + curl -X POST "${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}" \ + -H "Content-Type: application/json" \ + -d "$EMAIL_BODY" || echo "Failed to send test failure notification" + + - name: Send Existing URL Success Notification + # Scenario: Deployment skipped (existing URL provided) AND e2e tests passed + 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 == '') + run: | + RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + EXISTING_URL="${{ github.event.inputs.existing_webapp_url }}" + TEST_REPORT_URL="${{ needs.e2e-test.outputs.TEST_REPORT_URL }}" + EMAIL_BODY=$(cat <Dear Team,

The DocGen pipeline executed against the existing WebApp URL you supplied and the E2E tests completed successfully.

Test Results:
• Status: ✅ Passed
${TEST_REPORT_URL:+• Test Report: View Report}
• Target URL: ${EXISTING_URL}

Deployment: Skipped (existing URL reuse)

Build URL: ${RUN_URL}

No infrastructure changes were made.

Best regards,
Your Automation Team

", + "subject": "DocGen Pipeline - Existing URL Tests Passed" + } + EOF + ) + + echo "===== DEBUG: Existing URL Success EMAIL_BODY (raw JSON) =====" + printf '%s\n' "$EMAIL_BODY" + echo "===========================================================" + + curl -X POST "${{ secrets.LOGIC_APP_URL }}" \ + -H "Content-Type: application/json" \ + -d "$EMAIL_BODY" || echo "Failed to send existing URL success notification" + + - name: Send Existing URL Test Failure Notification + # Scenario: Deployment skipped (existing URL provided) AND e2e tests failed + if: needs.deploy.result == 'skipped' && github.event.inputs.existing_webapp_url != '' && needs.e2e-test.result == 'failure' + run: | + RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + EXISTING_URL="${{ github.event.inputs.existing_webapp_url }}" + TEST_REPORT_URL="${{ needs.e2e-test.outputs.TEST_REPORT_URL }}" + EMAIL_BODY=$(cat <Dear Team,

The DocGen pipeline targeted the existing WebApp URL you supplied. Deployment was intentionally skipped, but the E2E tests have failed.

Failure Details:
• Target URL: ${EXISTING_URL}
${TEST_REPORT_URL:+• Test Report: View Report}
• Deployment: Skipped (existing URL reuse)

Recommended Actions:
• Inspect the failing test cases
• Verify application availability and recent changes
• Re-run tests after fixes

Build URL: ${RUN_URL}

Best regards,
Your Automation Team

", + "subject": "DocGen Pipeline - Existing URL Tests Failed" + } + EOF + ) + + echo "===== DEBUG: Existing URL Failure EMAIL_BODY (raw JSON) =====" + printf '%s\n' "$EMAIL_BODY" + echo "===========================================================" + + curl -X POST "${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}" \ + -H "Content-Type: application/json" \ + -d "$EMAIL_BODY" || echo "Failed to send existing URL test failure notification" diff --git a/.github/workflows/test-automation.yml b/.github/workflows/test-automation.yml index 40c99b508..c47c2ed0f 100644 --- a/.github/workflows/test-automation.yml +++ b/.github/workflows/test-automation.yml @@ -11,6 +11,13 @@ on: EMAILNOTIFICATION_LOGICAPP_URL_TA: required: false description: "Logic App URL for email notifications" + outputs: + TEST_SUCCESS: + description: "Whether tests passed" + value: ${{ jobs.test.outputs.TEST_SUCCESS }} + TEST_REPORT_URL: + description: "URL to test report artifact" + value: ${{ jobs.test.outputs.TEST_REPORT_URL }} env: url: ${{ inputs.DOCGEN_URL }} @@ -19,6 +26,9 @@ env: jobs: test: runs-on: ubuntu-latest + outputs: + TEST_SUCCESS: ${{ steps.test1.outcome == 'success' || steps.test2.outcome == 'success' || steps.test3.outcome == 'success' }} + TEST_REPORT_URL: ${{ steps.upload_report.outputs.artifact-url }} steps: - name: Checkout repository uses: actions/checkout@v5 @@ -85,35 +95,7 @@ jobs: name: test-report path: tests/e2e-test/report/* - - name: Send Notification - if: always() - run: | - RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" - REPORT_URL=${{ steps.upload_report.outputs.artifact-url }} - IS_SUCCESS=${{ steps.test1.outcome == 'success' || steps.test2.outcome == 'success' || steps.test3.outcome == 'success' }} - # Construct the email body - if [ "$IS_SUCCESS" = "true" ]; then - EMAIL_BODY=$(cat <Dear Team,

We would like to inform you that the ${{ env.accelerator_name }} Test Automation process has completed successfully.

Run URL: ${RUN_URL}

Test Report: ${REPORT_URL}

Best regards,
Your Automation Team

", - "subject": "${{ env.accelerator_name }} Test Automation - Success" - } - EOF - ) - else - EMAIL_BODY=$(cat <Dear Team,

We would like to inform you that the ${{ env.accelerator_name }} Test Automation process has encountered an issue and has failed to complete successfully.

Run URL: ${RUN_URL}
${OUTPUT}

Test Report: ${REPORT_URL}

Please investigate the matter at your earliest convenience.

Best regards,
Your Automation Team

", - "subject": "${{ env.accelerator_name }} Test Automation - Failure" - } - EOF - ) - fi - # Send the notification - curl -X POST "${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}" \ - -H "Content-Type: application/json" \ - -d "$EMAIL_BODY" || echo "Failed to send notification" - name: Generate E2E Test Summary if: always()