Skip to content

Commit 9ca374e

Browse files
authored
fix failed state processing (#4921)
Fix failed state processing Fixes: flutter/flutter#176982
1 parent 14f835f commit 9ca374e

File tree

4 files changed

+43
-27
lines changed

4 files changed

+43
-27
lines changed

app_dart/lib/src/service/firestore/unified_check_run.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,21 +230,22 @@ final class UnifiedCheckRun {
230230
}
231231
valid = true;
232232
} else {
233-
// "remaining" should go down if buildSuccessed of any attempt
234-
// or buildFailed a first attempt.
233+
// "remaining" should go down if build is succeeded or failed.
235234
// "failed_count" can go up or down depending on:
236235
// attemptNumber > 1 && buildSuccessed: down (-1)
237236
// attemptNumber = 1 && buildFailed: up (+1)
238237
// So if the test existed and either remaining or failed_count is changed;
239238
// the response is valid.
240239
status = state.status;
241-
if (status.isBuildSuccessed) {
240+
if (status.isBuildCompleted) {
242241
// Guard against going negative and log enough info so we can debug.
243242
if (remaining == 0) {
244243
throw '$logCrumb: field "${PresubmitGuard.fieldRemainingBuilds}" is already zero for $transaction / ${presubmitGuardDocument.fields}';
245244
}
246245
remaining = remaining - 1;
246+
}
247247

248+
if (status.isBuildSuccessed) {
248249
// Only rollback the "failed" counter if this is a successful test run,
249250
// i.e. the test failed, the user requested a rerun, and now it passes.
250251
if (state.attemptNumber > 1) {

app_dart/lib/src/service/scheduler.dart

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,30 @@ $s
877877
);
878878
}
879879

880+
Future<void> _requireActionForGuard({
881+
required RepositorySlug slug,
882+
required CheckRun lock,
883+
required String headSha,
884+
required String summary,
885+
required String details,
886+
String? detailsUrl,
887+
}) async {
888+
log.info('Failing merge group guard for merge group $headSha in $slug');
889+
await _githubChecksService.githubChecksUtil.updateCheckRun(
890+
_config,
891+
slug,
892+
lock,
893+
status: CheckRunStatus.completed,
894+
conclusion: CheckRunConclusion.actionRequired,
895+
output: CheckRunOutput(
896+
title: Config.kCiYamlCheckName,
897+
summary: summary,
898+
text: details,
899+
),
900+
detailsUrl: detailsUrl,
901+
);
902+
}
903+
880904
/// If [builderTriggerList] is specificed, return only builders that are contained in [presubmitTarget].
881905
/// Otherwise, return [presubmitTarget].
882906
List<Target> filterTargets(
@@ -1030,24 +1054,6 @@ $s
10301054
return false;
10311055
}
10321056

1033-
// If the number of failed checks is equal to the number of remaining checks, then all remaining checks have failed.
1034-
if (check.isUnifiedCheckRun &&
1035-
stagingConclusion.failed > 0 &&
1036-
stagingConclusion.failed == stagingConclusion.remaining) {
1037-
final guard = checkRunFromString(stagingConclusion.checkRunGuard!);
1038-
await failGuardForMergeGroup(
1039-
slug: check.slug,
1040-
lock: guard,
1041-
headSha: check.sha,
1042-
summary: kMergeQueueLockDescription,
1043-
details:
1044-
'For CI stage ${check.stage} ${stagingConclusion.failed} checks failed',
1045-
detailsUrl:
1046-
'https://flutter-dashboard.appspot.com/repo/${check.slug.name}/checkrun/${check.guardId}',
1047-
);
1048-
return true;
1049-
}
1050-
10511057
// Are there tests remaining? Keep waiting.
10521058
if (stagingConclusion.isPending) {
10531059
log.info(
@@ -1063,6 +1069,7 @@ $s
10631069
// to the next stage. Let the author sort out what's up.
10641070
// * If this is a merge group: kick the pull request out of the queue, and
10651071
// let the author sort it out.
1072+
// If its a unified check run we need to require action on the guard.
10661073
if (check.isMergeGroup) {
10671074
await _completeArtifacts(check.sha, false);
10681075
final guard = checkRunFromString(stagingConclusion.checkRunGuard!);
@@ -1073,6 +1080,18 @@ $s
10731080
summary: stagingConclusion.summary,
10741081
details: stagingConclusion.details,
10751082
);
1083+
} else if (check.isUnifiedCheckRun) {
1084+
final guard = checkRunFromString(stagingConclusion.checkRunGuard!);
1085+
await _requireActionForGuard(
1086+
slug: check.slug,
1087+
lock: guard,
1088+
headSha: check.sha,
1089+
summary: kMergeQueueLockDescription,
1090+
details:
1091+
'For CI stage ${check.stage} ${stagingConclusion.failed} checks failed',
1092+
detailsUrl:
1093+
'https://flutter-dashboard.appspot.com/repo/${check.slug.name}/checkrun/${check.guardId}',
1094+
);
10761095
}
10771096
return true;
10781097
}

app_dart/test/service/firestore/unified_check_run_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ void main() {
267267
);
268268

269269
expect(result.result, PresubmitGuardConclusionResult.ok);
270-
expect(result.remaining, 2);
270+
expect(result.remaining, 1);
271271
expect(result.failed, 1);
272272
});
273273

packages/cocoon_common/lib/task_status.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ enum TaskStatus {
8181
this == TaskStatus.cancelled;
8282

8383
/// Returns true if the build succeeded or some kind of failure occurred.
84-
bool get isBuildCompleted =>
85-
this == TaskStatus.succeeded ||
86-
this == TaskStatus.failed ||
87-
this == TaskStatus.infraFailure ||
88-
this == TaskStatus.cancelled;
84+
bool get isBuildCompleted => isBuildSuccessed || isBuildFailed;
8985

9086
/// Returns the JSON representation of `this`.
9187
Object? toJson() => _schemaValue;

0 commit comments

Comments
 (0)