Skip to content

Commit 7af83c4

Browse files
authored
experiment for updating dashboard checks status to in progress (#5128)
flutter/flutter#191005
1 parent 75b7d9c commit 7af83c4

8 files changed

Lines changed: 220 additions & 54 deletions

File tree

‎app_dart/lib/src/foundation/github_checks_util.dart‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:convert';
56
import 'dart:core';
67

78
import 'package:cocoon_server/logging.dart';
@@ -96,6 +97,59 @@ class GithubChecksUtil {
9697
);
9798
}
9899

100+
/// Sends a request to github checks api to reset a [CheckRun] to in_progress.
101+
Future<void> resetCheckRun(
102+
Config config,
103+
github.RepositorySlug slug,
104+
github.CheckRun checkRun, {
105+
github.CheckRunStatus status = github.CheckRunStatus.inProgress,
106+
String? detailsUrl,
107+
github.CheckRunOutput? output,
108+
List<github.CheckRunAction>? actions,
109+
}) async {
110+
const r = RetryOptions(maxAttempts: 3, delayFactor: Duration(seconds: 2));
111+
return r.retry(
112+
() async {
113+
final gitHubClient = await config.createGitHubClient(slug: slug);
114+
await _resetCheckRun(
115+
gitHubClient,
116+
slug,
117+
checkRun,
118+
status: status,
119+
detailsUrl: detailsUrl,
120+
output: output,
121+
);
122+
},
123+
retryIf: (Exception e) => e is github.GitHubError || e is SocketException,
124+
);
125+
}
126+
127+
Future<github.CheckRun> _resetCheckRun(
128+
github.GitHub gitHubClient,
129+
github.RepositorySlug slug,
130+
github.CheckRun checkRunToUpdate, {
131+
String? name,
132+
String? detailsUrl,
133+
github.CheckRunStatus status = github.CheckRunStatus.inProgress,
134+
github.CheckRunOutput? output,
135+
}) async {
136+
return gitHubClient.requestJson<Map<String, dynamic>, github.CheckRun>(
137+
'PATCH',
138+
'/repos/${slug.fullName}/check-runs/${checkRunToUpdate.id}',
139+
statusCode: github.StatusCodes.OK,
140+
preview: 'application/vnd.github.antiope-preview+json',
141+
body: jsonEncode(<String, dynamic>{
142+
'name': name,
143+
'details_url': detailsUrl,
144+
'status': status,
145+
'conclusion': null,
146+
'completed_at': null,
147+
'output': output,
148+
}),
149+
convert: github.CheckRun.fromJson,
150+
);
151+
}
152+
99153
Future<github.CheckRun> getCheckRun(
100154
Config config,
101155
github.RepositorySlug slug,

‎app_dart/lib/src/service/luci_build_service.dart‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,9 @@ class LuciBuildService {
463463
);
464464
final guard = PresubmitGuard.fromDocument(presubmitGuardDoc);
465465
if (guard.failedJobs == 0) {
466-
log.info('Re-requesting dashboard checks for Guard $guard');
466+
log.info(
467+
'Re-requesting dashboard checks id ${dashboardChecks.id} for Guard $guard',
468+
);
467469
final githubClient = await _config.createGitHubClient(slug: slug);
468470
await githubClient.checks.checkRuns.reRequestCheckRun(
469471
slug,
@@ -483,16 +485,24 @@ class LuciBuildService {
483485

484486
if (shouldUpdateCheckRun) {
485487
try {
486-
await _githubChecksUtil.updateCheckRun(
488+
log.info(
489+
'Resetting dashboard checks ${dashboardChecks.id} to in progress',
490+
);
491+
await _githubChecksUtil.resetCheckRun(
487492
_config,
488493
slug,
489494
dashboardChecks,
490-
status: CheckRunStatus.inProgress,
495+
output: const CheckRunOutput(
496+
title: Config.kDashboardCheckName,
497+
summary: Scheduler.kDashboardChecksDescription,
498+
),
499+
detailsUrl:
500+
'https://flutter-dashboard.appspot.com/#/presubmit?repo=${slug.name}&sha=$commitSha',
491501
);
492502
} catch (e, s) {
493503
// We are not going to block on this error.
494504
log.warn(
495-
'Failed to update dashboard checks for PR# ${pullRequest.number} to in progress',
505+
'Failed to reset dashboard checks for PR# ${pullRequest.number} to in progress',
496506
e,
497507
s,
498508
);

‎app_dart/lib/src/service/luci_build_service/user_data.g.dart‎

Lines changed: 10 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright 2020 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:convert';
6+
7+
import 'package:cocoon_integration_test/testing.dart';
8+
import 'package:cocoon_server_test/mocks.dart';
9+
import 'package:cocoon_server_test/test_logging.dart';
10+
import 'package:cocoon_service/src/foundation/github_checks_util.dart';
11+
import 'package:github/github.dart' as github;
12+
import 'package:mockito/mockito.dart';
13+
import 'package:test/test.dart';
14+
15+
void main() {
16+
useTestLoggerPerTest();
17+
18+
group('GithubChecksUtil', () {
19+
late GithubChecksUtil githubChecksUtil;
20+
late MockGitHub mockGitHub;
21+
late FakeConfig config;
22+
late github.RepositorySlug slug;
23+
24+
setUp(() {
25+
githubChecksUtil = const GithubChecksUtil();
26+
mockGitHub = MockGitHub();
27+
config = FakeConfig(githubClient: mockGitHub);
28+
slug = github.RepositorySlug('flutter', 'flutter');
29+
});
30+
31+
test(
32+
'resetCheckRun sends PATCH request with null conclusion and completed_at',
33+
() async {
34+
final checkRun = github.CheckRun.fromJson(
35+
jsonDecode(
36+
'{"name": "Guard", "id": 1234, "status": "completed", "conclusion": "failure", "started_at": "2020-05-10T02:49:31Z", "head_sha": "the_sha", "check_suite": {"id": 1}}',
37+
)
38+
as Map<String, dynamic>,
39+
);
40+
41+
when(
42+
// ignore: discarded_futures
43+
mockGitHub.requestJson<Map<String, dynamic>, github.CheckRun>(
44+
'PATCH',
45+
'/repos/flutter/flutter/check-runs/1234',
46+
statusCode: github.StatusCodes.OK,
47+
preview: 'application/vnd.github.antiope-preview+json',
48+
body: anyNamed('body'),
49+
convert: anyNamed('convert'),
50+
),
51+
).thenAnswer((_) async {
52+
return github.CheckRun.fromJson(
53+
jsonDecode(
54+
'{"name": "Guard", "id": 1234, "status": "in_progress", "conclusion": null, "started_at": "2020-05-10T02:49:31Z", "head_sha": "the_sha", "check_suite": {"id": 1}}',
55+
)
56+
as Map<String, dynamic>,
57+
);
58+
});
59+
60+
await githubChecksUtil.resetCheckRun(
61+
config,
62+
slug,
63+
checkRun,
64+
status: github.CheckRunStatus.inProgress,
65+
detailsUrl: 'https://example.com/details',
66+
);
67+
68+
final captured = verify(
69+
mockGitHub.requestJson<Map<String, dynamic>, github.CheckRun>(
70+
'PATCH',
71+
'/repos/flutter/flutter/check-runs/1234',
72+
statusCode: github.StatusCodes.OK,
73+
preview: 'application/vnd.github.antiope-preview+json',
74+
body: captureAnyNamed('body'),
75+
convert: anyNamed('convert'),
76+
),
77+
).captured;
78+
79+
final body =
80+
jsonDecode(captured.single as String) as Map<String, dynamic>;
81+
expect(body['status'], 'in_progress');
82+
expect(body['details_url'], 'https://example.com/details');
83+
expect(body['conclusion'], isNull);
84+
expect(body['completed_at'], isNull);
85+
},
86+
);
87+
});
88+
}

‎app_dart/test/request_handlers/scheduler/backfill_grid_test.dart‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,9 @@ void main() {
100100
reason: 'Target 1 is marked backfill: false, so it is not eligible',
101101
);
102102

103-
expect(
104-
grid.skippableTasks,
105-
[isSkippableTask.hasTask(t1c2)],
106-
reason: 'Target 1 is marked backfill: false, so it is skipped',
107-
);
103+
expect(grid.skippableTasks, [
104+
isSkippableTask.hasTask(t1c2),
105+
], reason: 'Target 1 is marked backfill: false, so it is skipped');
108106
});
109107

110108
test('filters out tasks that are missing from ToT', () {

‎app_dart/test/service/luci_build_service/schedule_try_builds_test.dart‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,13 @@ void main() {
452452
verifyNever(mockGithubChecksUtil.createCheckRun(any, any, any, any));
453453

454454
verify(
455-
mockGithubChecksUtil.updateCheckRun(
455+
mockGithubChecksUtil.resetCheckRun(
456456
any,
457457
RepositorySlug.full('flutter/flutter'),
458458
checkRunGuard,
459459
status: CheckRunStatus.inProgress,
460+
output: anyNamed('output'),
461+
detailsUrl: anyNamed('detailsUrl'),
460462
),
461463
).called(1);
462464

@@ -541,7 +543,7 @@ void main() {
541543
).called(1);
542544

543545
verifyNever(
544-
mockGithubChecksUtil.updateCheckRun(
546+
mockGithubChecksUtil.resetCheckRun(
545547
any,
546548
any,
547549
any,
@@ -614,7 +616,7 @@ void main() {
614616

615617
// Should NOT update dashboard checks
616618
verifyNever(
617-
mockGithubChecksUtil.updateCheckRun(
619+
mockGithubChecksUtil.resetCheckRun(
618620
any,
619621
any,
620622
any,
@@ -710,11 +712,13 @@ void main() {
710712
).called(1);
711713

712714
verify(
713-
mockGithubChecksUtil.updateCheckRun(
715+
mockGithubChecksUtil.resetCheckRun(
714716
any,
715717
any,
716718
checkRunGuard,
717719
status: CheckRunStatus.inProgress,
720+
output: anyNamed('output'),
721+
detailsUrl: anyNamed('detailsUrl'),
718722
),
719723
).called(1);
720724
},
@@ -796,7 +800,7 @@ void main() {
796800
);
797801

798802
verifyNever(
799-
mockGithubChecksUtil.updateCheckRun(
803+
mockGithubChecksUtil.resetCheckRun(
800804
any,
801805
any,
802806
any,

‎app_dart/test/service/scheduler_test.dart‎

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4192,11 +4192,9 @@ targets:
41924192
final pullRequest = generatePullRequest(authorLogin: 'joe-flutter');
41934193

41944194
await scheduler.triggerPresubmitTargets(pullRequest: pullRequest);
4195-
expect(
4196-
fakeLuciBuildService.scheduledTryBuilds.map((t) => t.name),
4197-
['Linux engine_build'],
4198-
reason: 'Should still run engine phase',
4199-
);
4195+
expect(fakeLuciBuildService.scheduledTryBuilds.map((t) => t.name), [
4196+
'Linux engine_build',
4197+
], reason: 'Should still run engine phase');
42004198
});
42014199

42024200
test('still runs engine builds (engine/**)', () async {
@@ -4207,11 +4205,9 @@ targets:
42074205
final pullRequest = generatePullRequest(authorLogin: 'joe-flutter');
42084206

42094207
await scheduler.triggerPresubmitTargets(pullRequest: pullRequest);
4210-
expect(
4211-
fakeLuciBuildService.scheduledTryBuilds.map((t) => t.name),
4212-
['Linux engine_build'],
4213-
reason: 'Should still run engine phase',
4214-
);
4208+
expect(fakeLuciBuildService.scheduledTryBuilds.map((t) => t.name), [
4209+
'Linux engine_build',
4210+
], reason: 'Should still run engine phase');
42154211
});
42164212

42174213
test(
@@ -4228,11 +4224,9 @@ targets:
42284224
);
42294225

42304226
await scheduler.triggerPresubmitTargets(pullRequest: pullRequest);
4231-
expect(
4232-
fakeLuciBuildService.scheduledTryBuilds.map((t) => t.name),
4233-
['Linux engine_build'],
4234-
reason: 'Should still run engine phase',
4235-
);
4227+
expect(fakeLuciBuildService.scheduledTryBuilds.map((t) => t.name), [
4228+
'Linux engine_build',
4229+
], reason: 'Should still run engine phase');
42364230
},
42374231
);
42384232

@@ -4248,11 +4242,10 @@ targets:
42484242
),
42494243
reason: 'Should use the base ref for the engine artifacts',
42504244
);
4251-
expect(
4252-
fakeLuciBuildService.scheduledTryBuilds.map((t) => t.name),
4253-
['Linux A', 'Linux analyze'],
4254-
reason: 'Should skip Linux engine_build',
4255-
);
4245+
expect(fakeLuciBuildService.scheduledTryBuilds.map((t) => t.name), [
4246+
'Linux A',
4247+
'Linux analyze',
4248+
], reason: 'Should skip Linux engine_build');
42564249

42574250
expect(
42584251
firestore,
@@ -4281,11 +4274,9 @@ targets:
42814274
),
42824275
reason: 'Should use the base ref for the engine artifacts',
42834276
);
4284-
expect(
4285-
fakeLuciBuildService.scheduledTryBuilds.map((t) => t.name),
4286-
['Linux analyze'],
4287-
reason: 'Only scheduled a special-cased build',
4288-
);
4277+
expect(fakeLuciBuildService.scheduledTryBuilds.map((t) => t.name), [
4278+
'Linux analyze',
4279+
], reason: 'Only scheduled a special-cased build');
42894280
});
42904281
});
42914282
group('process unified check run', () {

0 commit comments

Comments
 (0)