|
| 1 | +name: Test Automation ClientAdvisor |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - dev |
| 8 | + |
| 9 | + paths: |
| 10 | + - 'tests/e2e-test/**' |
| 11 | + schedule: |
| 12 | + - cron: '0 13 * * *' # Runs at 1 PM UTC |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +env: |
| 16 | + url: ${{ vars.CLIENT_ADVISOR_URL }} |
| 17 | + accelerator_name: "Client Advisor" |
| 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: Run tests(1) |
| 40 | + id: test1 |
| 41 | + run: | |
| 42 | + xvfb-run pytest --headed --html=report/report.html --self-contained-html |
| 43 | + working-directory: tests/e2e-test |
| 44 | + continue-on-error: true |
| 45 | + |
| 46 | + - name: Sleep for 30 seconds |
| 47 | + if: ${{ steps.test1.outcome == 'failure' }} |
| 48 | + run: sleep 30s |
| 49 | + shell: bash |
| 50 | + |
| 51 | + - name: Run tests(2) |
| 52 | + if: ${{ steps.test1.outcome == 'failure' }} |
| 53 | + id: test2 |
| 54 | + run: | |
| 55 | + xvfb-run pytest --headed --html=report/report.html --self-contained-html |
| 56 | + working-directory: tests/e2e-test |
| 57 | + continue-on-error: true |
| 58 | + |
| 59 | + - name: Sleep for 60 seconds |
| 60 | + if: ${{ steps.test2.outcome == 'failure' }} |
| 61 | + run: sleep 60s |
| 62 | + shell: bash |
| 63 | + |
| 64 | + - name: Run tests(3) |
| 65 | + if: ${{ steps.test2.outcome == 'failure' }} |
| 66 | + id: test3 |
| 67 | + run: | |
| 68 | + xvfb-run pytest --headed --html=report/report.html --self-contained-html |
| 69 | + working-directory: tests/e2e-test |
| 70 | + |
| 71 | + - name: Upload test report |
| 72 | + id: upload_report |
| 73 | + uses: actions/upload-artifact@v4 |
| 74 | + if: ${{ !cancelled() }} |
| 75 | + with: |
| 76 | + name: test-report |
| 77 | + path: tests/e2e-test/report/* |
| 78 | + |
| 79 | + - name: Send Notification |
| 80 | + if: always() |
| 81 | + run: | |
| 82 | + RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 83 | + REPORT_URL=${{ steps.upload_report.outputs.artifact-url }} |
| 84 | + IS_SUCCESS=${{ steps.test1.outcome == 'success' || steps.test2.outcome == 'success' || steps.test3.outcome == 'success' }} |
| 85 | + # Construct the email body |
| 86 | + if [ "$IS_SUCCESS" = "true" ]; then |
| 87 | + EMAIL_BODY=$(cat <<EOF |
| 88 | + { |
| 89 | + "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> |
| 90 | + </p><p><strong>Test Report:</strong> <a href=\"${REPORT_URL}\">${REPORT_URL}</a></p><p>Best regards, |
| 91 | + Your Automation Team</p>", |
| 92 | + "subject": "${{ env.accelerator_name }} Test Automation - Success" |
| 93 | + } |
| 94 | + EOF |
| 95 | + ) |
| 96 | + else |
| 97 | + EMAIL_BODY=$(cat <<EOF |
| 98 | + { |
| 99 | + "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> |
| 100 | + ${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, |
| 101 | + Your Automation Team</p>", |
| 102 | + "subject": "${{ env.accelerator_name }} Test Automation - Failure" |
| 103 | + } |
| 104 | + EOF |
| 105 | + ) |
| 106 | + fi |
| 107 | + |
| 108 | + # Send the notification |
| 109 | + curl -X POST "${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA}}" \ |
| 110 | + -H "Content-Type: application/json" \ |
| 111 | + -d "$EMAIL_BODY" || echo "Failed to send notification" |
0 commit comments