Skip to content

Commit dd59cbb

Browse files
authored
Conditionally lock MQG on flutter/flutter+master only. (#4685)
Closes flutter/flutter#168867.
1 parent eea3c28 commit dd59cbb

2 files changed

Lines changed: 29 additions & 37 deletions

File tree

app_dart/lib/src/service/scheduler.dart

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -325,27 +325,35 @@ class Scheduler {
325325
await cancelPreSubmitTargets(pullRequest: pullRequest, reason: reason);
326326

327327
final slug = pullRequest.base!.repo!.slug();
328+
final isFusion = slug == Config.flutterSlug;
328329

329330
// The MQ only waits for "required status checks" before deciding whether to
330331
// merge the PR into the target branch. This required check added to both
331332
// the PR and to the merge group, and so it must be completed in both cases.
332-
final lock = await lockMergeGroupChecks(slug, pullRequest.head!.sha!);
333+
final CheckRun? lock;
334+
{
335+
final prBranch = pullRequest.head!.ref;
336+
if (isFusion && Config.defaultBranch(slug) == prBranch) {
337+
lock = await _lockMergeGroupChecks(slug, pullRequest.head!.sha!);
338+
} else {
339+
lock = null;
340+
log.debug('Skipping merge queue guard: $slug/$prBranch');
341+
}
342+
}
333343

334-
// Track if we should unlock the merge group lock in case of non-fusion or
335-
// revert bots.
344+
// Track if we should unlock the merge group lock in case of rever bots.
345+
// This is different than simply not having a lock - because flutter/flutter
346+
// master requires to see the lock existing and have been passed (versus
347+
// non-existence).
336348
var unlockMergeGroup = false;
337349

338350
final ciValidationCheckRun = await _createCiYamlCheckRun(pullRequest, slug);
339351

340352
log.info('Creating presubmit targets for ${pullRequest.number}');
341353
Object? exception;
342-
final isFusion = slug == Config.flutterSlug;
343354
do {
344355
try {
345356
final sha = pullRequest.head!.sha!;
346-
if (!isFusion) {
347-
unlockMergeGroup = true;
348-
}
349357

350358
// Both the author and label should be checked to make sure that no one is
351359
// attempting to get a pull request without check through.
@@ -381,7 +389,7 @@ class Scheduler {
381389

382390
await _runCiTestingStage(
383391
pullRequest: pullRequest,
384-
checkRunGuard: '$lock',
392+
checkRunGuard: lock?.toString() ?? '',
385393
logCrumb: logCrumb,
386394

387395
// The if-branch already skips the engine build phase.
@@ -470,8 +478,8 @@ class Scheduler {
470478
// Normally the lock stays pending until the PR is ready to be enqueued, but
471479
// there are situations (see code above) when it needs to be unlocked
472480
// immediately.
473-
if (unlockMergeGroup) {
474-
await unlockMergeQueueGuard(slug, pullRequest.head!.sha!, lock);
481+
if (lock != null && unlockMergeGroup) {
482+
await _unlockMergeQueueGuard(slug, pullRequest.head!.sha!, lock);
475483
}
476484
log.info(
477485
'Finished triggering builds for: pr ${pullRequest.number}, commit ${pullRequest.base!.sha}, branch ${pullRequest.head!.ref} and slug $slug}',
@@ -561,12 +569,12 @@ class Scheduler {
561569
}
562570
log.info('$logCrumb: scheduling merge group checks');
563571

564-
final lock = await lockMergeGroupChecks(slug, headSha);
572+
final lock = await _lockMergeGroupChecks(slug, headSha);
565573

566574
// If the repo is not fusion, it doesn't run anything in the MQ, so just
567575
// close the merge group guard.
568576
if (!isFusion) {
569-
await unlockMergeQueueGuard(slug, headSha, lock);
577+
await _unlockMergeQueueGuard(slug, headSha, lock);
570578
return;
571579
}
572580

@@ -730,7 +738,7 @@ $s
730738
/// While this check is still in progress, the merge queue will not merge the
731739
/// respective PR onto the target branch (e.g. main or master), because this
732740
/// check is "required".
733-
Future<CheckRun> lockMergeGroupChecks(
741+
Future<CheckRun> _lockMergeGroupChecks(
734742
RepositorySlug slug,
735743
String headSha,
736744
) async {
@@ -754,7 +762,7 @@ $s
754762
///
755763
/// If the guard is guarding a pull request, this immediately makes the pull
756764
/// request eligible for enqueuing into the merge queue.
757-
Future<void> unlockMergeQueueGuard(
765+
Future<void> _unlockMergeQueueGuard(
758766
RepositorySlug slug,
759767
String headSha,
760768
CheckRun lock,
@@ -1113,7 +1121,11 @@ $s
11131121
required String logCrumb,
11141122
}) async {
11151123
log.info('$logCrumb: Stage completed: ${CiStage.fusionTests}');
1116-
await unlockMergeQueueGuard(slug, sha, checkRunFromString(mergeQueueGuard));
1124+
await _unlockMergeQueueGuard(
1125+
slug,
1126+
sha,
1127+
checkRunFromString(mergeQueueGuard),
1128+
);
11171129
}
11181130

11191131
/// Returns the presubmit targets for the fusion repo [pullRequest] that should run for the given [stage].
@@ -1146,7 +1158,7 @@ $s
11461158

11471159
// Unlock the guarding check_run.
11481160
final checkRunGuard = checkRunFromString(mergeQueueGuard);
1149-
await unlockMergeQueueGuard(slug, sha, checkRunGuard);
1161+
await _unlockMergeQueueGuard(slug, sha, checkRunGuard);
11501162
}
11511163

11521164
/// Schedules post-engine build tests (i.e. engine tests, and framework tests).

app_dart/test/service/scheduler_test.dart

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,11 +2392,6 @@ targets:
23922392
),
23932393
).captured,
23942394
<Object?>[
2395-
Config.kMergeQueueLockName,
2396-
const CheckRunOutput(
2397-
title: Config.kMergeQueueLockName,
2398-
summary: Scheduler.kMergeQueueLockDescription,
2399-
),
24002395
Config.kCiYamlCheckName,
24012396
const CheckRunOutput(
24022397
title: Config.kCiYamlCheckName,
@@ -2578,11 +2573,6 @@ targets:
25782573
),
25792574
).captured,
25802575
<Object?>[
2581-
Config.kMergeQueueLockName,
2582-
const CheckRunOutput(
2583-
title: Config.kMergeQueueLockName,
2584-
summary: Scheduler.kMergeQueueLockDescription,
2585-
),
25862576
Config.kCiYamlCheckName,
25872577
const CheckRunOutput(
25882578
title: Config.kCiYamlCheckName,
@@ -2619,11 +2609,6 @@ targets:
26192609
),
26202610
).captured,
26212611
<Object?>[
2622-
Config.kMergeQueueLockName,
2623-
const CheckRunOutput(
2624-
title: Config.kMergeQueueLockName,
2625-
summary: Scheduler.kMergeQueueLockDescription,
2626-
),
26272612
Config.kCiYamlCheckName,
26282613
const CheckRunOutput(
26292614
title: Config.kCiYamlCheckName,
@@ -2654,12 +2639,7 @@ targets:
26542639
output: anyNamed('output'),
26552640
),
26562641
).captured,
2657-
<Object?>[
2658-
CheckRunStatus.completed,
2659-
CheckRunConclusion.success,
2660-
CheckRunStatus.completed,
2661-
CheckRunConclusion.success,
2662-
],
2642+
<Object?>[CheckRunStatus.completed, CheckRunConclusion.success],
26632643
);
26642644
});
26652645

0 commit comments

Comments
 (0)