-
Notifications
You must be signed in to change notification settings - Fork 21
157 lines (142 loc) · 5.8 KB
/
NightlyDispatcher.yml
File metadata and controls
157 lines (142 loc) · 5.8 KB
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: Nightly Dispatcher
on:
schedule:
# Run main branch at 10:00 PM (22:00 UTC)
- cron: '0 22 * * *'
# Run version/mx/10 branch at 4:00 AM UTC
- cron: '0 4 * * *'
jobs:
dispatch-main:
if: github.event.schedule == '0 22 * * *'
runs-on: ubuntu-latest
outputs:
run-id: ${{ steps.trigger.outputs.run-id }}
steps:
- name: "Trigger Native Pipeline on main"
id: trigger
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7
with:
script: |
const response = await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'NativePipeline.yml',
ref: 'main',
inputs: {
run_name: 'Nightly Main Branch Pipeline',
workspace: '*-native'
}
});
// Wait a moment then get the latest run
await new Promise(resolve => setTimeout(resolve, 5000));
const runs = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'NativePipeline.yml',
branch: 'main',
per_page: 1
});
const runId = runs.data.workflow_runs[0]?.id;
core.setOutput('run-id', runId);
return runId;
dispatch-version-mx-10:
if: github.event.schedule == '0 4 * * *'
runs-on: ubuntu-latest
outputs:
run-id: ${{ steps.trigger.outputs.run-id }}
steps:
- name: "Trigger Native Pipeline on version/mx/10"
id: trigger
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7
with:
script: |
const response = await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'NativePipeline.yml',
ref: 'version/mx/10',
inputs: {
run_name: 'Nightly version/mx/10 Branch Pipeline',
workspace: '*-native'
}
});
// Wait a moment then get the latest run
await new Promise(resolve => setTimeout(resolve, 5000));
const runs = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'NativePipeline.yml',
branch: 'version/mx/10',
per_page: 1
});
const runId = runs.data.workflow_runs[0]?.id;
core.setOutput('run-id', runId);
return runId;
auto-retry-main:
needs: dispatch-main
if: always() && needs.dispatch-main.result == 'success' && github.event.schedule == '0 22 * * *'
runs-on: ubuntu-latest
steps:
- name: "Monitor and retry failed jobs"
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7
with:
script: |
const runId = '${{ needs.dispatch-main.outputs.run-id }}';
if (!runId || runId === 'null') {
core.setFailed('No run ID available from dispatch job');
return;
}
// Poll for completion
let run;
do {
await new Promise(resolve => setTimeout(resolve, 60000)); // Wait 1 minute
run = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId
});
console.log(`Run status: ${run.data.status}, conclusion: ${run.data.conclusion}`);
} while (run.data.status === 'in_progress' || run.data.status === 'queued');
// If there are failures, rerun failed jobs
if (run.data.conclusion === 'failure') {
console.log('Pipeline failed, triggering rerun of failed jobs...');
await github.rest.actions.reRunWorkflowFailedJobs({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId
});
}
auto-retry-version-mx-10:
needs: dispatch-version-mx-10
if: always() && needs.dispatch-version-mx-10.result == 'success' && github.event.schedule == '0 4 * * *'
runs-on: ubuntu-latest
steps:
- name: "Monitor and retry failed jobs"
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7
with:
script: |
const runId = '${{ needs.dispatch-version-mx-10.outputs.run-id }}';
if (!runId || runId === 'null') {
core.setFailed('No run ID available from dispatch job');
return;
}
// Poll for completion
let run;
do {
await new Promise(resolve => setTimeout(resolve, 60000)); // Wait 1 minute
run = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId
});
console.log(`Run status: ${run.data.status}, conclusion: ${run.data.conclusion}`);
} while (run.data.status === 'in_progress' || run.data.status === 'queued');
// If there are failures, rerun failed jobs
if (run.data.conclusion === 'failure') {
console.log('Pipeline failed, triggering rerun of failed jobs...');
await github.rest.actions.reRunWorkflowFailedJobs({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId
});
}