Skip to content

Commit

Permalink
ci: fix flakiness in update-check in Manage integration check workf…
Browse files Browse the repository at this point in the history
…low (#9787)

refs: #8937 

## Description

Addresses the issue with flake in the `manage-integration-check.yml` workflow. This is due to a race condition where the workflow is executed 3 times in quick succession and is expected to run in order of execution. 

The "Integration tests" workflow triggers `manage-integration-check.yml`  3 times. once for `requested`, `in_progress`, and `completed` statuses of the calling workflow. 
In cases where the `completed` status might happen at the same time as the other two (such as when the "Integration tests" workflow is skipped), the 3 calls of the `manage-integration-check.yml` workflow might run simultaneously and cause a race condition.

the race condition occurs because the final call of `manage-integration-check.yml` (the one triggered by the `completed` status of "Integration tests") expects a github check run to already exist. since this might not be the case in a race condition, it fails

To fix this two things have been done:
- instead of crashing, the job now creates a new github check run with a `completed` status
- since the previous two jobs will run after the final job, they might accidentally overwrite the github check run with the `completed` status and accidentally create a check run with `in_progess` status.   their  filter check has been removed entirely so that they consider `completed` check runs as well.


### Security Considerations


### Scaling Considerations


### Documentation Considerations


### Testing Considerations


### Upgrade Considerations
  • Loading branch information
mergify[bot] authored Aug 2, 2024
2 parents ae69fbd + f6b26a3 commit d12673b
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions .github/workflows/manage-integration-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
if: ${{ github.event.action == 'requested' || github.event.action == 'in_progress' }}
with:
script: |
const external_id = context.payload.workflow_run.html_url;
const external_id = context.payload.workflow_run.html_url + "-" + context.payload.workflow_run.run_attempt;
const head_sha = context.payload.workflow_run.head_sha;
const runs = await github.paginate(github.rest.checks.listForRef, {
...context.repo,
Expand All @@ -25,7 +25,7 @@ jobs:
external_id,
})
core.debug(`integration-test-result check runs: ${JSON.stringify(runs, null, 2)}`);
const filtRuns = runs.filter(run => run.status !== 'completed');
const filtRuns = runs.filter(run => run.external_id === external_id);
const descRuns = filtRuns.sort((a, b) => Date.parse(b.started_at) - Date.parse(a.started_at));
const run = descRuns[0];
Expand All @@ -42,7 +42,7 @@ jobs:
external_id,
output: {
title: "Integration Test Aggregate Result",
summary: `Synthetic check capturing the result of the <a href="${context.payload.workflow_run.html_url}">integration-test workflow run</a>`,
summary: `Synthetic check capturing the result of the <a href="${context.payload.workflow_run.html_url}">integration-test workflow run</a> (attempt ${context.payload.workflow_run.run_attempt})`,
}
});
return check.data.id;
Expand All @@ -56,7 +56,7 @@ jobs:
result-encoding: string
script: |
// Update the check run
const external_id = context.payload.workflow_run.html_url;
const external_id = context.payload.workflow_run.html_url + "-" + context.payload.workflow_run.run_attempt;
const head_sha = context.payload.workflow_run.head_sha;
const runs = await github.paginate(github.rest.checks.listForRef, {
...context.repo,
Expand All @@ -65,12 +65,23 @@ jobs:
external_id,
})
core.debug(`integration-test-result check runs: ${JSON.stringify(runs, null, 2)}`);
const filtRuns = runs.filter(run => run.status !== 'completed');
const filtRuns = runs.filter(run => run.status !== 'completed' && run.external_id === external_id);
const descRuns = filtRuns.sort((a, b) => Date.parse(b.started_at) - Date.parse(a.started_at));
const run = descRuns[0];
if (!run) {
core.setFailed(`No integration-test-result check found for commit ${head_sha} ${external_id}`);
const check = await github.rest.checks.create({
...context.repo,
head_sha,
name: "integration-test-result",
status: "completed",
conclusion: context.payload.workflow_run.conclusion,
external_id,
output: {
title: "Integration Test Aggregate Result",
summary: `Synthetic check capturing the result of the <a href="${context.payload.workflow_run.html_url}">integration-test workflow run</a> (attempt ${context.payload.workflow_run.run_attempt})`,
}
});
return;
}
Expand Down

0 comments on commit d12673b

Please sign in to comment.