-
Notifications
You must be signed in to change notification settings - Fork 196
157 lines (139 loc) · 5.5 KB
/
rerun.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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@v4
- 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