Skip to content

rerun failed jobs #3962

rerun failed jobs

rerun failed jobs #3962

Workflow file for this run

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
schedule:
- cron: "0 16 * * *"
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' }}
defaults:
run:
working-directory: packages/tests
env:
M365_ACCOUNT_NAME: "[email protected]"
M365_ACCOUNT_PASSWORD: ${{ secrets.TEST_M365_PASSWORD }}
M365_DISPLAY_NAME: "ttktest"
M365_USERNAME_2: "[email protected]"
M365_USERNAME_3: "[email protected]"
M365_USERNAME_4: "[email protected]"
CLEAN_CLIENT_ID: ${{ secrets.TEST_CLEAN_CLIENT_ID }}
CLEAN_CLIENT_SECRET: ${{ secrets.CLEAN_CLIENT_SECRET }}
CLEAN_TENANT_ID: ${{ secrets.TEST_CLEAN_TENANT_ID }}
AZURE_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 }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup project
working-directory: ./
run: |
npm run setup
- name: Clean resource
if: always()
run: |
npx ts-node src/scripts/clean.ts
- name: Switch M365 account
run: |
username='${{ env.M365_USERNAME_2 }}'
echo "M365_ACCOUNT_NAME=$username" >> $GITHUB_ENV
- name: Clean resource
if: always()
run: |
npx ts-node src/scripts/clean.ts
- name: Switch M365 account
run: |
username='${{ env.M365_USERNAME_3 }}'
echo "M365_ACCOUNT_NAME=$username" >> $GITHUB_ENV
- name: Clean resource
if: always()
run: |
npx ts-node src/scripts/clean.ts
- name: Switch M365 account
run: |
username='${{ env.M365_USERNAME_4 }}'
echo "M365_ACCOUNT_NAME=$username" >> $GITHUB_ENV
- name: Clean resource
if: always()
run: |
npx ts-node src/scripts/clean.ts