Skip to content
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
10 changes: 5 additions & 5 deletions app_dart/lib/src/model/common/failed_presubmit_jobs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import '../firestore/base.dart';
///
/// See: [UnifiedCheckRun.reInitializeFailedJobs]
class FailedJobsForRerun {
final CheckRun checkRunGuard;
final CheckRun dashboardChecks;
final CiStage stage;
final Map<String, int> jobRetries;

const FailedJobsForRerun({
required this.checkRunGuard,
required this.dashboardChecks,
required this.stage,
required this.jobRetries,
});
Expand All @@ -29,19 +29,19 @@ class FailedJobsForRerun {
bool operator ==(Object other) =>
identical(this, other) ||
(other is FailedJobsForRerun &&
other.checkRunGuard == checkRunGuard &&
other.dashboardChecks == dashboardChecks &&
other.stage == stage &&
const DeepCollectionEquality().equals(other.jobRetries, jobRetries));

@override
int get hashCode => Object.hashAll([
checkRunGuard,
dashboardChecks,
stage,
...jobRetries.keys,
...jobRetries.values,
]);

@override
String toString() =>
'FailedChecksForRerun("$checkRunGuard", "$stage", "$jobRetries")';
'FailedChecksForRerun("$dashboardChecks", "$stage", "$jobRetries")';
}
14 changes: 9 additions & 5 deletions app_dart/lib/src/model/common/presubmit_guard_conclusion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ enum PresubmitGuardConclusionResult {
class PresubmitGuardConclusion {
final PresubmitGuardConclusionResult result;
final int remaining;
final String? checkRunGuard;
final String? dashboardChecks;
final String? mergeQueueGuard;
final int failed;
final List<String> failedJobNames;
final String summary;
Expand All @@ -49,7 +50,8 @@ class PresubmitGuardConclusion {
const PresubmitGuardConclusion({
required this.result,
required this.remaining,
required this.checkRunGuard,
this.dashboardChecks,
required this.mergeQueueGuard,
required this.failed,
this.failedJobNames = const [],
required this.summary,
Expand All @@ -70,7 +72,8 @@ class PresubmitGuardConclusion {
(other is PresubmitGuardConclusion &&
other.result == result &&
other.remaining == remaining &&
other.checkRunGuard == checkRunGuard &&
other.dashboardChecks == dashboardChecks &&
other.mergeQueueGuard == mergeQueueGuard &&
other.failed == failed &&
const ListEquality<String>().equals(
other.failedJobNames,
Expand All @@ -83,7 +86,8 @@ class PresubmitGuardConclusion {
int get hashCode => Object.hashAll([
result,
remaining,
checkRunGuard,
dashboardChecks,
mergeQueueGuard,
failed,
Object.hashAll(failedJobNames),
summary,
Expand All @@ -92,5 +96,5 @@ class PresubmitGuardConclusion {

@override
String toString() =>
'BuildConclusion("$result", "$remaining", "$failed", "$failedJobNames", "$summary", "$details", "$checkRunGuard")';
'BuildConclusion("$result", "$remaining", "$failed", "$failedJobNames", "$summary", "$details", "$dashboardChecks", "$mergeQueueGuard")';
}
6 changes: 3 additions & 3 deletions app_dart/lib/src/model/firestore/ci_staging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ final class CiStaging extends AppDocument<CiStaging> {
return PresubmitGuardConclusion(
result: PresubmitGuardConclusionResult.missing,
remaining: remaining,
checkRunGuard: null,
mergeQueueGuard: null,
failed: failed,
summary: 'Check run "$checkRun" not present in $stage CI stage',
details: 'Change $changeCrumb',
Expand Down Expand Up @@ -353,7 +353,7 @@ final class CiStaging extends AppDocument<CiStaging> {
return PresubmitGuardConclusion(
result: PresubmitGuardConclusionResult.internalError,
remaining: -1,
checkRunGuard: null,
mergeQueueGuard: null,
failed: failed,
summary: 'Internal server error',
details:
Expand Down Expand Up @@ -391,7 +391,7 @@ $stack
? PresubmitGuardConclusionResult.ok
: PresubmitGuardConclusionResult.internalError,
remaining: remaining,
checkRunGuard: checkRunGuard ?? '',
mergeQueueGuard: checkRunGuard ?? '',
failed: failed,
summary: valid
? 'All tests passed'
Expand Down
21 changes: 21 additions & 0 deletions app_dart/lib/src/model/firestore/presubmit_guard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ final class PresubmitGuardId extends AppDocumentId<PresubmitGuard> {
final class PresubmitGuard extends AppDocument<PresubmitGuard> {
static const collectionId = 'presubmit_guards';
static const fieldCheckRun = 'check_run';
static const fieldCheckRunGuard = 'check_run_guard';
static const fieldCheckRunId = 'check_run_id';
static const fieldPrNum = 'pr_num';
static const fieldSlug = 'slug';
Expand Down Expand Up @@ -117,6 +118,7 @@ final class PresubmitGuard extends AppDocument<PresubmitGuard> {
required int creationTime,
required String author,
required int jobCount,
CheckRun? checkRunGuard,
}) {
return PresubmitGuard(
checkRun: checkRun,
Expand All @@ -128,6 +130,7 @@ final class PresubmitGuard extends AppDocument<PresubmitGuard> {
creationTime: creationTime,
remainingJobs: jobCount,
failedJobs: 0,
checkRunGuard: checkRunGuard,
);
}

Expand All @@ -145,6 +148,7 @@ final class PresubmitGuard extends AppDocument<PresubmitGuard> {
required String author,
required int remainingJobs,
required int failedJobs,
CheckRun? checkRunGuard,
Map<String, TaskStatus>? jobs,
}) {
return PresubmitGuard._(
Expand All @@ -159,6 +163,8 @@ final class PresubmitGuard extends AppDocument<PresubmitGuard> {
fieldCheckRun: json.encode(checkRun.toJson()).toValue(),
fieldRemainingJobs: remainingJobs.toValue(),
fieldFailedJobs: failedJobs.toValue(),
if (checkRunGuard != null)
fieldCheckRunGuard: json.encode(checkRunGuard.toJson()).toValue(),
if (jobs != null)
fieldJobs: Value(
mapValue: MapValue(
Expand Down Expand Up @@ -202,6 +208,21 @@ final class PresubmitGuard extends AppDocument<PresubmitGuard> {

String get checkRunJson => fields[fieldCheckRun]!.stringValue!;

CheckRun? get checkRunGuard {
if (fields[fieldCheckRunGuard]?.stringValue == null) {
return null;
}
final jsonData =
jsonDecode(fields[fieldCheckRunGuard]!.stringValue!)
as Map<String, Object?>;
if (jsonData['conclusion'] == 'null') {
jsonData.remove('conclusion');
}
return CheckRun.fromJson(jsonData);
}

String? get checkRunGuardJson => fields[fieldCheckRunGuard]?.stringValue;

/// The repository that this stage is recorded for.
RepositorySlug get slug {
if (fields[fieldSlug] != null) {
Expand Down
14 changes: 7 additions & 7 deletions app_dart/lib/src/request_handlers/rerun_all_failed_jobs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ final class RerunAllFailedJobs extends ApiRequestHandler {
// We're doing a transactional update, which could fail if multiple tasks
// are running at the same time so retry a sane amount of times before
// giving up.
final failedChecks = await const RetryOptions().retry(
final failedJobs = await const RetryOptions().retry(
() => UnifiedCheckRun.reInitializeFailedJobs(
firestoreService: _firestore,
slug: slug,
Expand All @@ -85,7 +85,7 @@ final class RerunAllFailedJobs extends ApiRequestHandler {
),
);

if (failedChecks == null) {
if (failedJobs == null) {
throw const BadRequestException('No failed jobs found to re-run');
}

Expand All @@ -96,12 +96,12 @@ final class RerunAllFailedJobs extends ApiRequestHandler {

final checkRetries = <Target, int>{};
for (final target in targets) {
if (failedChecks.jobRetries.containsKey(target.name)) {
checkRetries[target] = failedChecks.jobRetries[target.name]!;
if (failedJobs.jobRetries.containsKey(target.name)) {
checkRetries[target] = failedJobs.jobRetries[target.name]!;
}
}

if (checkRetries.length != failedChecks.jobRetries.length) {
if (checkRetries.length != failedJobs.jobRetries.length) {
throw const NotFoundException(
'Failed to find all failed targets in presubmit targets',
);
Expand All @@ -111,8 +111,8 @@ final class RerunAllFailedJobs extends ApiRequestHandler {
targets: checkRetries,
pullRequest: pullRequest,
engineArtifacts: artifacts,
checkRunGuard: failedChecks.checkRunGuard,
stage: failedChecks.stage,
dashboardChecks: failedJobs.dashboardChecks,
stage: failedJobs.stage,
);

return Response.json({
Expand Down
2 changes: 1 addition & 1 deletion app_dart/lib/src/request_handlers/rerun_failed_job.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ final class RerunFailedJob extends ApiRequestHandler {
targets: {target: retries},
pullRequest: pullRequest,
engineArtifacts: artifacts,
checkRunGuard: rerunInfo.checkRunGuard,
dashboardChecks: rerunInfo.dashboardChecks,
stage: rerunInfo.stage,
);

Expand Down
25 changes: 15 additions & 10 deletions app_dart/lib/src/service/firestore/unified_check_run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ final class UnifiedCheckRun {
required List<String> tasks,
required Config config,
PullRequest? pullRequest,
CheckRun? checkRun,
CheckRun? dashboardChecks,
CheckRun? mergeQueueGuard,
@visibleForTesting DateTime Function() utcNow = DateTime.timestamp,
}) async {
if (checkRun != null &&
if (dashboardChecks != null &&
pullRequest != null &&
config.flags.isUnifiedCheckRunFlowEnabledForUser(
pullRequest.user!.login!,
Expand All @@ -48,7 +49,8 @@ final class UnifiedCheckRun {
// was succeeded so we are interested in a state of the latest one.
final creationTime = utcNow().millisecondsSinceEpoch;
final guard = PresubmitGuard(
checkRun: checkRun,
checkRun: dashboardChecks,
checkRunGuard: mergeQueueGuard,
headSha: sha,
slug: slug,
prNum: pullRequest.number!,
Expand All @@ -64,7 +66,7 @@ final class UnifiedCheckRun {
PresubmitJob.init(
slug: slug,
jobName: task,
checkRunId: checkRun.id!,
checkRunId: dashboardChecks.id!,
creationTime: creationTime,
),
];
Expand All @@ -79,7 +81,7 @@ final class UnifiedCheckRun {
sha: sha,
stage: stage,
tasks: tasks,
checkRunGuard: checkRun != null ? '$checkRun' : '',
checkRunGuard: mergeQueueGuard != null ? '$mergeQueueGuard' : '',
);
}
}
Expand Down Expand Up @@ -163,7 +165,7 @@ final class UnifiedCheckRun {
'$logCrumb: results = ${response.writeResults?.map((e) => e.toJson())}',
);
return FailedJobsForRerun(
checkRunGuard: latestGuard.checkRun,
dashboardChecks: latestGuard.checkRun,
jobRetries: checkRetries,
stage: latestGuard.stage,
);
Expand Down Expand Up @@ -247,7 +249,7 @@ final class UnifiedCheckRun {
'$logCrumb: results = ${response.writeResults?.map((e) => e.toJson())}',
);
return FailedJobsForRerun(
checkRunGuard: guard.checkRun,
dashboardChecks: guard.checkRun,
jobRetries: {jobName: (latestCheck?.attemptNumber ?? 0) + 1},
stage: guard.stage,
);
Expand Down Expand Up @@ -559,7 +561,8 @@ final class UnifiedCheckRun {
return PresubmitGuardConclusion(
result: PresubmitGuardConclusionResult.missing,
remaining: presubmitGuard.remainingJobs,
checkRunGuard: presubmitGuard.checkRunJson,
dashboardChecks: presubmitGuard.checkRunJson,
mergeQueueGuard: presubmitGuard.checkRunGuardJson,
failed: presubmitGuard.failedJobs,
summary:
'Check run "${state.jobName}" not present in ${guardId.stage} CI stage',
Expand Down Expand Up @@ -654,7 +657,8 @@ final class UnifiedCheckRun {
return PresubmitGuardConclusion(
result: PresubmitGuardConclusionResult.internalError,
remaining: -1,
checkRunGuard: null,
dashboardChecks: null,
mergeQueueGuard: null,
failed: failed,
summary: 'Internal server error',
details:
Expand Down Expand Up @@ -689,7 +693,8 @@ $stack
? PresubmitGuardConclusionResult.ok
: PresubmitGuardConclusionResult.internalError,
remaining: remaining,
checkRunGuard: presubmitGuard.checkRunJson,
dashboardChecks: presubmitGuard.checkRunJson,
mergeQueueGuard: presubmitGuard.checkRunGuardJson,
failed: failed,
failedJobNames: valid ? presubmitGuard.failedJobNames : const [],
summary: valid
Expand Down
Loading
Loading