@@ -11,12 +11,15 @@ jobs:
1111 dispatch-main :
1212 if : github.event.schedule == '0 0 * * *'
1313 runs-on : ubuntu-latest
14+ outputs :
15+ run-id : ${{ steps.trigger.outputs.run-id }}
1416 steps :
1517 - name : " Trigger Native Pipeline on main"
18+ id : trigger
1619 uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
1720 with :
1821 script : |
19- await github.rest.actions.createWorkflowDispatch({
22+ const response = await github.rest.actions.createWorkflowDispatch({
2023 owner: context.repo.owner,
2124 repo: context.repo.repo,
2225 workflow_id: 'NativePipeline.yml',
@@ -26,16 +29,33 @@ jobs:
2629 workspace: '*-native'
2730 }
2831 });
32+
33+ // Wait a moment then get the latest run
34+ await new Promise(resolve => setTimeout(resolve, 5000));
35+ const runs = await github.rest.actions.listWorkflowRuns({
36+ owner: context.repo.owner,
37+ repo: context.repo.repo,
38+ workflow_id: 'NativePipeline.yml',
39+ branch: 'main',
40+ per_page: 1
41+ });
42+
43+ const runId = runs.data.workflow_runs[0]?.id;
44+ core.setOutput('run-id', runId);
45+ return runId;
2946
3047 dispatch-version-mx-10 :
3148 if : github.event.schedule == '0 4 * * *'
3249 runs-on : ubuntu-latest
50+ outputs :
51+ run-id : ${{ steps.trigger.outputs.run-id }}
3352 steps :
3453 - name : " Trigger Native Pipeline on version/mx/10"
54+ id : trigger
3555 uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
3656 with :
3757 script : |
38- await github.rest.actions.createWorkflowDispatch({
58+ const response = await github.rest.actions.createWorkflowDispatch({
3959 owner: context.repo.owner,
4060 repo: context.repo.repo,
4161 workflow_id: 'NativePipeline.yml',
4464 run_name: 'Nightly version/mx/10 Branch Pipeline',
4565 workspace: '*-native'
4666 }
47- });
67+ });
68+
69+ // Wait a moment then get the latest run
70+ await new Promise(resolve => setTimeout(resolve, 5000));
71+ const runs = await github.rest.actions.listWorkflowRuns({
72+ owner: context.repo.owner,
73+ repo: context.repo.repo,
74+ workflow_id: 'NativePipeline.yml',
75+ branch: 'version/mx/10',
76+ per_page: 1
77+ });
78+
79+ const runId = runs.data.workflow_runs[0]?.id;
80+ core.setOutput('run-id', runId);
81+ return runId;
82+
83+ auto-retry-main :
84+ needs : dispatch-main
85+ if : always() && needs.dispatch-main.result == 'success' && github.event.schedule == '0 0 * * *'
86+ runs-on : ubuntu-latest
87+ steps :
88+ - name : " Monitor and retry failed jobs"
89+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
90+ with :
91+ script : |
92+ const runId = '${{ needs.dispatch-main.outputs.run-id }}';
93+
94+ if (!runId || runId === 'null') {
95+ core.setFailed('No run ID available from dispatch job');
96+ return;
97+ }
98+
99+ // Poll for completion
100+ let run;
101+ do {
102+ await new Promise(resolve => setTimeout(resolve, 60000)); // Wait 1 minute
103+ run = await github.rest.actions.getWorkflowRun({
104+ owner: context.repo.owner,
105+ repo: context.repo.repo,
106+ run_id: runId
107+ });
108+ console.log(`Run status: ${run.data.status}, conclusion: ${run.data.conclusion}`);
109+ } while (run.data.status === 'in_progress' || run.data.status === 'queued');
110+
111+ // If there are failures, rerun failed jobs
112+ if (run.data.conclusion === 'failure') {
113+ console.log('Pipeline failed, triggering rerun of failed jobs...');
114+ await github.rest.actions.reRunWorkflowFailedJobs({
115+ owner: context.repo.owner,
116+ repo: context.repo.repo,
117+ run_id: runId
118+ });
119+ }
120+
121+ auto-retry-version-mx-10 :
122+ needs : dispatch-version-mx-10
123+ if : always() && needs.dispatch-version-mx-10.result == 'success' && github.event.schedule == '0 4 * * *'
124+ runs-on : ubuntu-latest
125+ steps :
126+ - name : " Monitor and retry failed jobs"
127+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
128+ with :
129+ script : |
130+ const runId = '${{ needs.dispatch-version-mx-10.outputs.run-id }}';
131+
132+ if (!runId || runId === 'null') {
133+ core.setFailed('No run ID available from dispatch job');
134+ return;
135+ }
136+
137+ // Poll for completion
138+ let run;
139+ do {
140+ await new Promise(resolve => setTimeout(resolve, 60000)); // Wait 1 minute
141+ run = await github.rest.actions.getWorkflowRun({
142+ owner: context.repo.owner,
143+ repo: context.repo.repo,
144+ run_id: runId
145+ });
146+ console.log(`Run status: ${run.data.status}, conclusion: ${run.data.conclusion}`);
147+ } while (run.data.status === 'in_progress' || run.data.status === 'queued');
148+
149+ // If there are failures, rerun failed jobs
150+ if (run.data.conclusion === 'failure') {
151+ console.log('Pipeline failed, triggering rerun of failed jobs...');
152+ await github.rest.actions.reRunWorkflowFailedJobs({
153+ owner: context.repo.owner,
154+ repo: context.repo.repo,
155+ run_id: runId
156+ });
157+ }
0 commit comments