Skip to content

Commit 12b299d

Browse files
matanlureyjtmcdole
andauthored
Special case Linux analyze for CHANGELOG.md (#4521)
Closes a loop hole found in flutter/flutter#167225. --------- Co-authored-by: John McDole <codefu@google.com>
1 parent 9ca3303 commit 12b299d

File tree

5 files changed

+69
-26
lines changed

5 files changed

+69
-26
lines changed

app_dart/lib/src/service/scheduler.dart

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,8 @@ class Scheduler {
472472

473473
// The if-branch already skips the engine build phase.
474474
testsToRun: switch (opt) {
475-
FilesChangedOptimization.skipPresubmitAll =>
476-
_FlutterRepoTestsToRun.noTests,
475+
FilesChangedOptimization.skipPresubmitAllExceptFlutterAnalyze =>
476+
_FlutterRepoTestsToRun.frameworkFlutterAnalyzeOnly,
477477
FilesChangedOptimization.skipPresubmitEngine =>
478478
_FlutterRepoTestsToRun.frameworkTestsOnly,
479479
FilesChangedOptimization.none => throw StateError('Unreachable'),
@@ -1228,11 +1228,7 @@ $s
12281228
try {
12291229
// Both the author and label should be checked to make sure that no one is
12301230
// attempting to get a pull request without check through.
1231-
if (testsToRun == _FlutterRepoTestsToRun.noTests) {
1232-
log.info(
1233-
'$logCrumb: skipping generating the full set of checks: no tests required.',
1234-
);
1235-
} else if (pullRequest.user!.login == _config.autosubmitBot &&
1231+
if (pullRequest.user!.login == _config.autosubmitBot &&
12361232
pullRequest.labels!.any(
12371233
(element) => element.name == Config.revertOfLabel,
12381234
)) {
@@ -1242,20 +1238,39 @@ $s
12421238
} else {
12431239
// Schedule the tests that would have run in a call to triggerPresubmitTargets - but for both the
12441240
// engine and the framework.
1245-
final presubmitTargets = await _getTestsForStage(
1241+
var presubmitTargets = await _getTestsForStage(
12461242
pullRequest,
12471243
CiStage.fusionTests,
12481244
skipEngine:
12491245
testsToRun != _FlutterRepoTestsToRun.engineTestsAndFrameworkTests,
12501246
);
12511247

12521248
// Create the document for tracking test check runs.
1249+
final List<String> tasks;
1250+
if (testsToRun == _FlutterRepoTestsToRun.frameworkFlutterAnalyzeOnly) {
1251+
const linuxAnalyze = 'Linux analyze';
1252+
final singleTarget = presubmitTargets.firstWhereOrNull(
1253+
(t) => t.name == linuxAnalyze,
1254+
);
1255+
if (singleTarget == null) {
1256+
log.warn('No target found named "$linuxAnalyze"');
1257+
tasks = [];
1258+
presubmitTargets = [];
1259+
} else {
1260+
log.info('Only running target "$linuxAnalyze"');
1261+
tasks = [linuxAnalyze];
1262+
presubmitTargets = [singleTarget];
1263+
}
1264+
} else {
1265+
tasks = [...presubmitTargets.map((t) => t.name)];
1266+
}
1267+
12531268
await initializeCiStagingDocument(
12541269
firestoreService: await _config.createFirestoreService(),
12551270
slug: pullRequest.base!.repo!.slug(),
12561271
sha: pullRequest.head!.sha!,
12571272
stage: CiStage.fusionTests,
1258-
tasks: [...presubmitTargets.map((t) => t.name)],
1273+
tasks: tasks,
12591274
checkRunGuard: checkRunGuard,
12601275
);
12611276

@@ -1267,7 +1282,7 @@ $s
12671282
// from source and rely on remote-build execution (RBE) for builds to
12681283
// fast and cached.
12691284
final EngineArtifacts engineArtifacts;
1270-
if (testsToRun == _FlutterRepoTestsToRun.frameworkTestsOnly) {
1285+
if (testsToRun != _FlutterRepoTestsToRun.engineTestsAndFrameworkTests) {
12711286
// Use the engine that this PR was branched off of.
12721287
engineArtifacts = EngineArtifacts.usingExistingEngine(
12731288
commitSha: pullRequest.base!.sha!,
@@ -1682,5 +1697,5 @@ enum _FlutterRepoTestsToRun {
16821697
frameworkTestsOnly,
16831698

16841699
/// No tests.
1685-
noTests,
1700+
frameworkFlutterAnalyzeOnly,
16861701
}

app_dart/lib/src/service/scheduler/files_changed_optimization.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ final class FilesChangedOptimizer {
7575
return FilesChangedOptimization.none;
7676
case SuccessfulFilesChanged(:final filesChanged):
7777
if (filesChanged.length == 1 && filesChanged.contains('CHANGELOG.md')) {
78-
return FilesChangedOptimization.skipPresubmitAll;
78+
return FilesChangedOptimization.skipPresubmitAllExceptFlutterAnalyze;
7979
}
8080
for (final file in filesChanged) {
8181
if (file == 'DEPS' || file.startsWith('engine/')) {
@@ -98,8 +98,8 @@ enum FilesChangedOptimization {
9898
/// Engine builds (and tests) can be skipped for this presubmit run.
9999
skipPresubmitEngine,
100100

101-
/// All builds (and tests) can be skipped for this presubmit run.
102-
skipPresubmitAll;
101+
/// Almost all builds (and tests) can be skipped for this presubmit run.
102+
skipPresubmitAllExceptFlutterAnalyze;
103103

104104
/// Whether the engine should be prebuilt.
105105
bool get shouldUsePrebuiltEngine => !shouldBuildEngineFromSource;

app_dart/test/service/scheduler/files_changed_optimization_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void main() {
131131
optimizer.checkPullRequest(
132132
generatePullRequest(repo: 'flutter', changedFilesCount: 1, number: 123),
133133
),
134-
completion(FilesChangedOptimization.skipPresubmitAll),
134+
completion(FilesChangedOptimization.skipPresubmitAllExceptFlutterAnalyze),
135135
);
136136
});
137137

app_dart/test/service/scheduler_test.dart

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,28 @@ targets:
7373
scheduler: google_internal
7474
''';
7575

76+
const String singleCiYamlWithLinuxAnalyze = r'''
77+
enabled_branches:
78+
- master
79+
- main
80+
- flutter-\d+\.\d+-candidate\.\d+
81+
targets:
82+
- name: Linux A
83+
properties:
84+
custom: abc
85+
- name: Linux B
86+
enabled_branches:
87+
- stable
88+
scheduler: luci
89+
- name: Linux runIf
90+
runIf:
91+
- .ci.yaml
92+
- DEPS
93+
- dev/**
94+
- engine/**
95+
- name: Linux analyze
96+
''';
97+
7698
const String fusionCiYaml = r'''
7799
enabled_branches:
78100
- master
@@ -3403,7 +3425,10 @@ targets:
34033425
setUp(() {
34043426
mockGithubService = MockGithubService();
34053427
fakeLuciBuildService = _CapturingFakeLuciBuildService();
3406-
ciYamlFetcher.setCiYamlFrom(singleCiYaml, engine: fusionCiYaml);
3428+
ciYamlFetcher.setCiYamlFrom(
3429+
singleCiYamlWithLinuxAnalyze,
3430+
engine: fusionCiYaml,
3431+
);
34073432

34083433
scheduler = Scheduler(
34093434
cache: cache,
@@ -3492,7 +3517,7 @@ targets:
34923517
);
34933518
expect(
34943519
fakeLuciBuildService.scheduledTryBuilds.map((t) => t.name),
3495-
['Linux A'],
3520+
['Linux A', 'Linux analyze'],
34963521
reason: 'Should skip Linux engine_build',
34973522
);
34983523
// TODO(matanlurey): Refactoring should allow us to verify the first stage
@@ -3501,20 +3526,22 @@ targets:
35013526
});
35023527

35033528
// Regression test for https://github.com/flutter/flutter/issues/167124.
3504-
test('skips all builds', () async {
3529+
test('skips all tests except "Linux analyze"', () async {
35053530
getFilesChanged.cannedFiles = ['CHANGELOG.md'];
35063531
final pullRequest = generatePullRequest(authorLogin: allowListedUser);
35073532

35083533
await scheduler.triggerPresubmitTargets(pullRequest: pullRequest);
35093534
expect(
35103535
fakeLuciBuildService.engineArtifacts,
3511-
isNull,
3512-
reason: 'Did not schdule tests',
3536+
EngineArtifacts.usingExistingEngine(
3537+
commitSha: pullRequest.base!.sha!,
3538+
),
3539+
reason: 'Should use the base ref for the engine artifacts',
35133540
);
35143541
expect(
35153542
fakeLuciBuildService.scheduledTryBuilds.map((t) => t.name),
3516-
isEmpty,
3517-
reason: 'Did not schdule tests',
3543+
['Linux analyze'],
3544+
reason: 'Only scheduled a special-cased build',
35183545
);
35193546
});
35203547

test_utilities/bin/dart_test_runner.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ dart format --set-exit-if-changed .
3030
echo "########### analyze ###########"
3131
dart analyze --fatal-infos
3232

33+
# TODO(matanlurey): Re-enable (https://github.com/flutter/flutter/issues/167229).
3334
# agent doesn't use build_runner as of this writing.
34-
if grep -lq "build_runner" pubspec.yaml; then
35-
echo "############# build ###########"
36-
dart run build_runner build --delete-conflicting-outputs
37-
fi
35+
# if grep -lq "build_runner" pubspec.yaml; then
36+
# echo "############# build ###########"
37+
# dart run build_runner build --delete-conflicting-outputs
38+
# fi
3839

3940
# Only try tests if test folder exist.
4041
if [ -d 'test' ]; then

0 commit comments

Comments
 (0)