Skip to content

Commit 1033d8f

Browse files
authored
chore(ci): retry flaky tasks (#3697)
1 parent 6c93526 commit 1033d8f

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

.github/workflows/check.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,14 @@ jobs:
430430
type: minimal
431431
language: kotlin
432432

433-
- name: remove previous build from linux
434-
run: |
435-
rm -rf clients/algoliasearch-client-kotlin/build || true
436-
rm -rf clients/algoliasearch-client-kotlin/.kotlin || true
437-
rm -rf clients/algoliasearch-client-kotlin/.gradle || true
433+
- name: Build clients for macOS
434+
id: build
435+
continue-on-error: true
436+
run: yarn cli build clients kotlin
438437

439-
- run: yarn cli build clients kotlin
438+
- name: Retry build
439+
if: ${{ steps.build.outcome == 'failure' }}
440+
run: yarn cli build clients kotlin
440441

441442
- name: Set output
442443
id: setoutput
@@ -478,7 +479,14 @@ jobs:
478479
language: swift
479480
version: ${{ fromJSON(needs.setup.outputs.SWIFT_DATA).version }}
480481

481-
- run: yarn cli cts run swift ${{ fromJSON(needs.setup.outputs.SWIFT_DATA).toRun }} -v ${{ !contains(format('{0} {1}', github.event.pull_request.title, github.event.head_commit.message), '[skip-e2e]') && '--no-e2e' || '' }}
482+
- name: Run tests on macOS
483+
id: run-test
484+
continue-on-error: true
485+
run: yarn cli cts run swift ${{ fromJSON(needs.setup.outputs.SWIFT_DATA).toRun }} -v ${{ !contains(format('{0} {1}', github.event.pull_request.title, github.event.head_commit.message), '[skip-e2e]') && '--no-e2e' || '' }}
486+
487+
- name: Retry tests
488+
if: ${{ steps.run-test.outcome == 'failure' }}
489+
run: yarn cli cts run swift ${{ fromJSON(needs.setup.outputs.SWIFT_DATA).toRun }} -v ${{ !contains(format('{0} {1}', github.event.pull_request.title, github.event.head_commit.message), '[skip-e2e]') && '--no-e2e' || '' }}
482490

483491
- name: Set output
484492
id: setoutput
@@ -622,7 +630,7 @@ jobs:
622630
623631
push_and_release:
624632
runs-on: ubuntu-22.04
625-
timeout-minutes: 15
633+
timeout-minutes: 30
626634
needs:
627635
- codegen
628636
- check_green

scripts/ci/codegen/waitForAllReleases.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Run = {
1212
language: Language;
1313
run?: components['schemas']['workflow-run'];
1414
finished: boolean;
15+
retried: boolean;
1516
};
1617

1718
async function fetchAllRuns(runs: Run[]): Promise<void> {
@@ -34,8 +35,8 @@ async function fetchAllRuns(runs: Run[]): Promise<void> {
3435
return;
3536
}
3637

37-
// check that the run was created less than 10 minutes ago
38-
if (Date.now() - Date.parse(workflowRun.data.workflow_runs[0].created_at) > 15 * 60 * 1000) {
38+
// check that the run was created less than 20 minutes ago
39+
if (Date.now() - Date.parse(workflowRun.data.workflow_runs[0].created_at) > 20 * 60 * 1000) {
3940
return;
4041
}
4142

@@ -44,6 +45,12 @@ async function fetchAllRuns(runs: Run[]): Promise<void> {
4445
);
4546
}
4647

48+
function sleep(ms: number): Promise<void> {
49+
return new Promise((resolve) => {
50+
setTimeout(resolve, ms);
51+
});
52+
}
53+
4754
async function waitForAllReleases(languagesReleased: Language[]): Promise<void> {
4855
const lastCommitMessage = await run('git log -1 --format="%s"');
4956

@@ -62,7 +69,7 @@ async function waitForAllReleases(languagesReleased: Language[]): Promise<void>
6269
)
6370
)
6471
.filter((lang) => lang.available)
65-
.map((lang) => ({ language: lang.lang, run: undefined, finished: false }));
72+
.map((lang) => ({ language: lang.lang, run: undefined, finished: false, retried: false }));
6673

6774
console.log(
6875
`Waiting for all releases CI to finish for the following languages: ${runs.map((l) => l.language).join(', ')}`,
@@ -72,7 +79,7 @@ async function waitForAllReleases(languagesReleased: Language[]): Promise<void>
7279

7380
const start = Date.now();
7481
// kotlin release can take a long time
75-
while (Date.now() - start < 1000 * 60 * 12) {
82+
while (Date.now() - start < 1000 * 60 * 20) {
7683
await fetchAllRuns(runs);
7784
for (const ciRun of runs) {
7885
if (ciRun.finished) {
@@ -86,6 +93,22 @@ async function waitForAllReleases(languagesReleased: Language[]): Promise<void>
8693

8794
if (ciRun.run.status === 'completed') {
8895
const success = ciRun.run.conclusion === 'success';
96+
if (!success && !ciRun.retried) {
97+
// retry once
98+
console.log(`❌ ${ciRun.language} CI failed, retrying once`);
99+
await getOctokit().actions.reRunWorkflowFailedJobs({
100+
owner: 'algolia',
101+
repo: getClientsConfigField(ciRun.language, 'gitRepoId'),
102+
run_id: ciRun.run.id,
103+
});
104+
105+
// sleep for a bit to let the CI start
106+
await sleep(15000);
107+
108+
ciRun.retried = true;
109+
110+
continue;
111+
}
89112
console.log(`${success ? '✅' : '❌'} ${ciRun.language} CI finished with conclusion: ${ciRun.run.conclusion}`);
90113
if (!success) {
91114
failures.push(ciRun.language);
@@ -99,9 +122,7 @@ async function waitForAllReleases(languagesReleased: Language[]): Promise<void>
99122
break;
100123
}
101124

102-
await new Promise((resolve) => {
103-
setTimeout(resolve, 15000);
104-
});
125+
await sleep(15000);
105126
}
106127

107128
if (failures.length > 0) {

0 commit comments

Comments
 (0)