rerun failed jobs #11500
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: rerun failed jobs | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| run_id: | |
| description: "run id" | |
| required: true | |
| type: string | |
| max_attempts: | |
| description: "max attempts, default is 3" | |
| required: false | |
| default: "3" | |
| type: string | |
| clean_up: | |
| description: "if true, clean up resources" | |
| required: false | |
| default: 'false' | |
| type: choice | |
| options: | |
| - 'true' | |
| - 'false' | |
| schedule: | |
| - cron: "0 11 * * *" # UTC+8 19:00 before any auto pipeline run, to clear all the resources | |
| - cron: "0 1 * * *" # UTC+8 09:00 after the uitest done, to clear all the resources | |
| permissions: | |
| actions: read | |
| jobs: | |
| rerun: | |
| permissions: | |
| actions: write | |
| if: ${{ github.event_name == 'workflow_dispatch' }} | |
| runs-on: ubuntu-latest | |
| env: | |
| DEVTUNNEL_CLIENT_ID: ${{ secrets.TEST_CLEAN_CLIENT_ID }} | |
| DEVTUNNEL_CLIENT_SECRET: ${{ secrets.TEST_CLEAN_CLIENT_SECRET }} | |
| DEVTUNNEL_TENANT_ID: ${{ secrets.TEST_CLEAN_TENANT_ID }} | |
| steps: | |
| - name: wait for 60s | |
| run: | | |
| sleep 60 | |
| echo "wait for 60s" | |
| - name: clean devtunnel | |
| run: | | |
| wget https://tunnelsassetsprod.blob.core.windows.net/cli/1.0.1249+67b1cd300c/linux-x64-devtunnel -O ./devtunnel | |
| chmod 777 ./devtunnel | |
| ./devtunnel user login --sp-tenant-id ${{env.DEVTUNNEL_TENANT_ID}} --sp-client-id ${{env.DEVTUNNEL_CLIENT_ID}} --sp-secret ${{env.DEVTUNNEL_CLIENT_SECRET}} | |
| ./devtunnel delete-all -f | |
| - name: re-run failed jobs | |
| run: | | |
| run=`curl \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.event.inputs.run_id }}` | |
| status=`jq -r '.conclusion' <<< "$run"` | |
| run_attempt=`jq -r '.run_attempt' <<< "$run"` | |
| echo "status: $status" | |
| echo "run_attempt: $run_attempt" | |
| if [[ "$status" == "failure" && "$run_attempt" -lt ${{ github.event.inputs.max_attempts }} ]]; then | |
| echo "[start] rerun failed jobs ${{ github.event.inputs.run_id }} $status $run_attempt..." | |
| curl \ | |
| -X POST \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.event.inputs.run_id }}/rerun-failed-jobs | |
| echo "[finish] rerun failed jobs ${{ github.event.inputs.run_id }}" | |
| fi | |
| sleep 60 | |
| run=`curl \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.event.inputs.run_id }}` | |
| runningStatus=`jq -r '.status' <<< "$run"` | |
| echo "runningStatus: $runningStatus" | |
| if [[ "$runningStatus" != "queued" && "$runningStatus" != "in_progress" && "$run_attempt" -lt ${{ github.event.inputs.max_attempts }} ]]; then | |
| echo "[start] rerun check..." | |
| curl \ | |
| -X POST \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.event.inputs.run_id }}/rerun-failed-jobs | |
| echo "[finish] rerun again..." | |
| fi | |
| clean: | |
| name: Clean resource | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.event.inputs.clean_up == 'true') }} | |
| defaults: | |
| run: | |
| working-directory: packages/tests | |
| env: | |
| M365_ACCOUNT_PASSWORD: ${{ matrix.m365_user.name == 'M365_USERNAME_With_Copilot' && secrets.TEST_TENANT_M365_ACCOUNT_PASSWORD || secrets.TEST_M365_PASSWORD }} | |
| M365_DISPLAY_NAME: "test" | |
| CLEAN_CLIENT_ID: ${{ secrets.TEST_CLEAN_CLIENT_ID }} | |
| CLEAN_CLIENT_SECRET: ${{ secrets.TEST_CLEAN_CLIENT_SECRET }} | |
| CLEAN_TENANT_ID: ${{ secrets.TEST_CLEAN_TENANT_ID }} | |
| AZURE_TENANT_ID: ${{ matrix.m365_user.name == 'M365_USERNAME_With_Copilot' && secrets.TEST_TENANT_TENANT_ID || secrets.TEST_TENANT_ID }} | |
| AZURE_SUBSCRIPTION_ID: ${{ secrets.TEST_SUBSCRIPTION_ID }} | |
| AZURE_ACCOUNT_NAME: ${{ secrets.TEST_USER_NAME }} | |
| AZURE_ACCOUNT_PASSWORD: ${{ secrets.TEST_USER_PASSWORD }} | |
| MAIL_API_KEY: ${{ secrets.MAIL_API_KEY }} | |
| TEST_TENANT_M365_ACCOUNT_NAME: ${{ secrets.TEST_TENANT_M365_ACCOUNT_NAME }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| m365_user: | |
| - { name: "M365_USERNAME_1", value: "[email protected]" } | |
| - { name: "M365_USERNAME_2", value: "[email protected]" } | |
| - { name: "M365_USERNAME_3", value: "[email protected]" } | |
| - { name: "M365_USERNAME_4", value: "[email protected]" } | |
| - { name: "M365_USERNAME_5", value: "[email protected]" } | |
| - { name: "M365_USERNAME_6", value: "[email protected]" } | |
| - { name: "M365_USERNAME_7", value: "[email protected]" } | |
| - { name: "M365_USERNAME_8", value: "[email protected]" } | |
| - { name: "M365_USERNAME_9", value: "[email protected]" } | |
| - { name: "M365_USERNAME_10", value: "[email protected]" } | |
| - { name: "M365_USERNAME_11", value: "[email protected]" } | |
| - { name: "M365_USERNAME_12", value: "[email protected]" } | |
| - { name: "M365_USERNAME_13", value: "[email protected]" } | |
| - { name: "M365_USERNAME_14", value: "[email protected]" } | |
| - { name: "M365_USERNAME_15", value: "[email protected]" } | |
| - { name: "M365_USERNAME_16", value: "[email protected]" } | |
| - { name: "M365_USERNAME_17", value: "[email protected]" } | |
| - { name: "M365_USERNAME_admin_14", value: "[email protected]"} | |
| - { name: "M365_USERNAME_admin_15", value: "[email protected]"} | |
| - { name: "M365_USERNAME_admin_16", value: "[email protected]"} | |
| - { name: "M365_USERNAME_admin_17", value: "[email protected]"} | |
| - { name: "M365_USERNAME_With_Copilot", value: "[email protected]"} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref_name }} | |
| - name: Setup node | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 22 | |
| - uses: pnpm/action-setup@v4 | |
| - name: Setup project | |
| working-directory: ./ | |
| run: | | |
| npm run setup:e2e | |
| - name: Set M365_ACCOUNT_NAME | |
| run: | | |
| echo "M365_ACCOUNT_NAME=${{ matrix.m365_user.value }}" >> $GITHUB_ENV | |
| - name: Clean resource with ${{ matrix.m365_user.name }} | |
| run: | | |
| npx ts-node src/scripts/clean.ts |