Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow base image update when check re-runs succeed #163

Merged
merged 2 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 92 additions & 9 deletions backend/allNonVisualChecksHavePassed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ describe('allNonVisualChecksHavePassed', () => {
check_runs: [
{
name: 'unit tests',
conclusion: 'success'
conclusion: 'success',
completed_at: '2023-05-02T19:11:02Z'
},
{
name: 'visual tests',
conclusion: 'failure'
conclusion: 'failure',
completed_at: '2023-05-02T19:11:02Z'
},
{
name: 'other tests',
conclusion: 'success'
conclusion: 'success',
completed_at: '2023-05-02T19:11:02Z'
}
]
}
Expand All @@ -42,15 +45,18 @@ describe('allNonVisualChecksHavePassed', () => {
check_runs: [
{
name: 'unit tests',
conclusion: 'success'
conclusion: 'success',
completed_at: '2023-05-02T19:11:02Z'
},
{
name: 'visual tests',
conclusion: 'failure'
conclusion: 'failure',
completed_at: '2023-05-02T19:11:02Z'
},
{
name: 'other tests',
conclusion: 'failure'
conclusion: 'failure',
completed_at: '2023-05-02T19:11:02Z'
}
]
}
Expand All @@ -71,15 +77,18 @@ describe('allNonVisualChecksHavePassed', () => {
check_runs: [
{
name: 'unit tests',
conclusion: 'success'
conclusion: 'success',
completed_at: '2023-05-02T19:11:02Z'
},
{
name: 'visual tests',
conclusion: 'failure'
conclusion: 'failure',
completed_at: '2023-05-02T19:11:02Z'
},
{
name: 'other tests',
conclusion: 'skipped'
conclusion: 'skipped',
completed_at: '2023-05-02T19:11:02Z'
}
]
}
Expand All @@ -90,4 +99,78 @@ describe('allNonVisualChecksHavePassed', () => {
const result = await allNonVisualChecksHavePassed('github-owner', 'github-repo', 'sha');
expect(result).toBe(true);
});

it('should return true when a non-visual check failed on an early run but passed on the latest run', async () => {
(getOctokit as jest.Mock).mockImplementation(() => ({
rest: {
checks: {
listForRef: jest.fn().mockReturnValue({
data: {
check_runs: [
{
name: 'unit tests',
conclusion: 'failure',
completed_at: '2023-05-02T19:10:02Z'
},
{
name: 'unit tests',
conclusion: 'success',
completed_at: '2023-05-02T19:11:02Z'
},
{
name: 'visual tests',
conclusion: 'failure',
completed_at: '2023-05-02T19:11:02Z'
},
{
name: 'other tests',
conclusion: 'skipped',
completed_at: '2023-05-02T19:11:02Z'
}
]
}
})
}
}
}));
const result = await allNonVisualChecksHavePassed('github-owner', 'github-repo', 'sha');
expect(result).toBe(true);
});

it('should return false when a non-visual check fails on multiple runs and never passed', async () => {
(getOctokit as jest.Mock).mockImplementation(() => ({
rest: {
checks: {
listForRef: jest.fn().mockReturnValue({
data: {
check_runs: [
{
name: 'unit tests',
conclusion: 'failure',
completed_at: '2023-05-02T19:11:02Z'
},
{
name: 'unit tests',
conclusion: 'failure',
completed_at: '2023-05-02T19:10:02Z'
},
{
name: 'visual tests',
conclusion: 'failure',
completed_at: '2023-05-02T19:11:02Z'
},
{
name: 'other tests',
conclusion: 'skipped',
completed_at: '2023-05-02T19:11:02Z'
}
]
}
})
}
}
}));
const result = await allNonVisualChecksHavePassed('github-owner', 'github-repo', 'sha');
expect(result).toBe(false);
});
});
9 changes: 8 additions & 1 deletion backend/allNonVisualChecksHavePassed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getOctokit } from './getOctokit';
import { RestEndpointMethodTypes } from '@octokit/rest';
import { groupBy, isEqual, sortBy } from 'lodash';

type CheckRunConclusion = RestEndpointMethodTypes['checks']['listForRef']['response']['data']['check_runs'][number]['conclusion'];

Expand All @@ -15,5 +16,11 @@ export const allNonVisualChecksHavePassed = async (owner: string, repo: string,
repo,
ref: sha
});
return data.check_runs.filter(({ name }) => !isVisualTest(name)).every(checkRun => allowedConclusions.includes(checkRun.conclusion));
const nonVisualChecks = data.check_runs.filter(({ name }) => !isVisualTest(name));
const groupedChecks = groupBy(nonVisualChecks, 'name');
const mostRecentChecks = nonVisualChecks.filter(check => {
const checksSortedByDescTime = sortBy(groupedChecks[check.name], 'completed_at').reverse();
return isEqual(check, checksSortedByDescTime[0]);
});
return mostRecentChecks.every(({ conclusion }) => allowedConclusions.includes(conclusion));
};