mirror of
https://github.com/flutter/packages.git
synced 2025-06-17 02:48:43 +08:00
[tools] Improves version-check logic (#6354)
Improves the logic used to determine whether to require a version and/or CHANGELOG change: - Removes the requirement that dev-only (e.g., test) changes update the CHANGELOG, since in practice we were essentially always overriding in that case. - Adds file-level analysis of `build.gradle` files to determine whether they are only changing test dependencies. - Improves the "is this a published example file" logic to better match pub.dev's logic, to fix some false positives and false negatives (e.g., `rfw`'s `example/<foo>/lib/main.dart` being considered published). Removes the no-longer-necessary special-case handling of some Dependabot PRs, as well as the PR-description-based system it was built on (and that turned out not to be very useful due to the way `CIRRUS_CHANGE_MESSAGE` actually worked). `build.gradle` analysis should not cover all such cases, and without the need to hard-code them by package name.
This commit is contained in:
@ -3,7 +3,9 @@
|
||||
// found in the LICENSE file.
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_plugin_tools/src/common/git_version_finder.dart';
|
||||
import 'package:flutter_plugin_tools/src/common/package_state_utils.dart';
|
||||
import 'package:test/fake.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../util.dart';
|
||||
@ -26,12 +28,13 @@ void main() {
|
||||
'packages/a_package/lib/plugin.dart',
|
||||
];
|
||||
|
||||
final PackageChangeState state = checkPackageChangeState(package,
|
||||
final PackageChangeState state = await checkPackageChangeState(package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_package');
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, true);
|
||||
expect(state.needsChangelogChange, true);
|
||||
});
|
||||
|
||||
test('handles trailing slash on package path', () async {
|
||||
@ -42,16 +45,18 @@ void main() {
|
||||
'packages/a_package/lib/plugin.dart',
|
||||
];
|
||||
|
||||
final PackageChangeState state = checkPackageChangeState(package,
|
||||
final PackageChangeState state = await checkPackageChangeState(package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_package/');
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, true);
|
||||
expect(state.needsChangelogChange, true);
|
||||
expect(state.hasChangelogChange, false);
|
||||
});
|
||||
|
||||
test('does not report version change exempt changes', () async {
|
||||
test('does not flag version- and changelog-change-exempt changes',
|
||||
() async {
|
||||
final RepositoryPackage package =
|
||||
createFakePlugin('a_plugin', packagesDir);
|
||||
|
||||
@ -64,12 +69,13 @@ void main() {
|
||||
'packages/a_plugin/CHANGELOG.md',
|
||||
];
|
||||
|
||||
final PackageChangeState state = checkPackageChangeState(package,
|
||||
final PackageChangeState state = await checkPackageChangeState(package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_plugin/');
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, false);
|
||||
expect(state.needsChangelogChange, false);
|
||||
expect(state.hasChangelogChange, true);
|
||||
});
|
||||
|
||||
@ -81,28 +87,49 @@ void main() {
|
||||
'packages/a_plugin/lib/foo/tool/tool_thing.dart',
|
||||
];
|
||||
|
||||
final PackageChangeState state = checkPackageChangeState(package,
|
||||
final PackageChangeState state = await checkPackageChangeState(package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_plugin/');
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, true);
|
||||
expect(state.needsChangelogChange, true);
|
||||
});
|
||||
|
||||
test('requires a version change for example main', () async {
|
||||
final RepositoryPackage package =
|
||||
createFakePlugin('a_plugin', packagesDir);
|
||||
test('requires a version change for example/lib/main.dart', () async {
|
||||
final RepositoryPackage package = createFakePlugin(
|
||||
'a_plugin', packagesDir,
|
||||
extraFiles: <String>['example/lib/main.dart']);
|
||||
|
||||
const List<String> changedFiles = <String>[
|
||||
'packages/a_plugin/example/lib/main.dart',
|
||||
];
|
||||
|
||||
final PackageChangeState state = checkPackageChangeState(package,
|
||||
final PackageChangeState state = await checkPackageChangeState(package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_plugin/');
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, true);
|
||||
expect(state.needsChangelogChange, true);
|
||||
});
|
||||
|
||||
test('requires a version change for example/main.dart', () async {
|
||||
final RepositoryPackage package = createFakePlugin(
|
||||
'a_plugin', packagesDir,
|
||||
extraFiles: <String>['example/main.dart']);
|
||||
|
||||
const List<String> changedFiles = <String>[
|
||||
'packages/a_plugin/example/main.dart',
|
||||
];
|
||||
|
||||
final PackageChangeState state = await checkPackageChangeState(package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_plugin/');
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, true);
|
||||
expect(state.needsChangelogChange, true);
|
||||
});
|
||||
|
||||
test('requires a version change for example readme.md', () async {
|
||||
@ -113,28 +140,189 @@ void main() {
|
||||
'packages/a_plugin/example/README.md',
|
||||
];
|
||||
|
||||
final PackageChangeState state = checkPackageChangeState(package,
|
||||
final PackageChangeState state = await checkPackageChangeState(package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_plugin/');
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, true);
|
||||
expect(state.needsChangelogChange, true);
|
||||
});
|
||||
|
||||
test('requires a version change for example example.md', () async {
|
||||
test('requires a version change for example/example.md', () async {
|
||||
final RepositoryPackage package = createFakePlugin(
|
||||
'a_plugin', packagesDir,
|
||||
extraFiles: <String>['example/example.md']);
|
||||
|
||||
const List<String> changedFiles = <String>[
|
||||
'packages/a_plugin/example/example.md',
|
||||
];
|
||||
|
||||
final PackageChangeState state = await checkPackageChangeState(package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_plugin/');
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, true);
|
||||
expect(state.needsChangelogChange, true);
|
||||
});
|
||||
|
||||
test(
|
||||
'requires a changelog change but no version change for '
|
||||
'lower-priority examples when example.md is present', () async {
|
||||
final RepositoryPackage package = createFakePlugin(
|
||||
'a_plugin', packagesDir,
|
||||
extraFiles: <String>['example/example.md']);
|
||||
|
||||
const List<String> changedFiles = <String>[
|
||||
'packages/a_plugin/example/lib/main.dart',
|
||||
'packages/a_plugin/example/main.dart',
|
||||
'packages/a_plugin/example/README.md',
|
||||
];
|
||||
|
||||
final PackageChangeState state = await checkPackageChangeState(package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_plugin/');
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, false);
|
||||
expect(state.needsChangelogChange, true);
|
||||
});
|
||||
|
||||
test(
|
||||
'requires a changelog change but no version change for README.md when '
|
||||
'code example is present', () async {
|
||||
final RepositoryPackage package = createFakePlugin(
|
||||
'a_plugin', packagesDir,
|
||||
extraFiles: <String>['example/lib/main.dart']);
|
||||
|
||||
const List<String> changedFiles = <String>[
|
||||
'packages/a_plugin/example/README.md',
|
||||
];
|
||||
|
||||
final PackageChangeState state = await checkPackageChangeState(package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_plugin/');
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, false);
|
||||
expect(state.needsChangelogChange, true);
|
||||
});
|
||||
|
||||
test(
|
||||
'does not requires changelog or version change for build.gradle '
|
||||
'test-dependency-only changes', () async {
|
||||
final RepositoryPackage package =
|
||||
createFakePlugin('a_plugin', packagesDir);
|
||||
|
||||
const List<String> changedFiles = <String>[
|
||||
'packages/a_plugin/example/lib/example.md',
|
||||
'packages/a_plugin/android/build.gradle',
|
||||
];
|
||||
|
||||
final PackageChangeState state = checkPackageChangeState(package,
|
||||
final GitVersionFinder git = FakeGitVersionFinder(<String, List<String>>{
|
||||
'packages/a_plugin/android/build.gradle': <String>[
|
||||
"- androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'",
|
||||
"- testImplementation 'junit:junit:4.10.0'",
|
||||
"+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'",
|
||||
"+ testImplementation 'junit:junit:4.13.2'",
|
||||
]
|
||||
});
|
||||
|
||||
final PackageChangeState state = await checkPackageChangeState(package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_plugin/',
|
||||
git: git);
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, false);
|
||||
expect(state.needsChangelogChange, false);
|
||||
});
|
||||
|
||||
test('requires changelog or version change for other build.gradle changes',
|
||||
() async {
|
||||
final RepositoryPackage package =
|
||||
createFakePlugin('a_plugin', packagesDir);
|
||||
|
||||
const List<String> changedFiles = <String>[
|
||||
'packages/a_plugin/android/build.gradle',
|
||||
];
|
||||
|
||||
final GitVersionFinder git = FakeGitVersionFinder(<String, List<String>>{
|
||||
'packages/a_plugin/android/build.gradle': <String>[
|
||||
"- androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'",
|
||||
"- testImplementation 'junit:junit:4.10.0'",
|
||||
"+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'",
|
||||
"+ testImplementation 'junit:junit:4.13.2'",
|
||||
"- implementation 'com.google.android.gms:play-services-maps:18.0.0'",
|
||||
"+ implementation 'com.google.android.gms:play-services-maps:18.0.2'",
|
||||
]
|
||||
});
|
||||
|
||||
final PackageChangeState state = await checkPackageChangeState(package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_plugin/',
|
||||
git: git);
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, true);
|
||||
expect(state.needsChangelogChange, true);
|
||||
});
|
||||
|
||||
test(
|
||||
'requires changelog or version change if build.gradle diffs cannot '
|
||||
'be checked', () async {
|
||||
final RepositoryPackage package =
|
||||
createFakePlugin('a_plugin', packagesDir);
|
||||
|
||||
const List<String> changedFiles = <String>[
|
||||
'packages/a_plugin/android/build.gradle',
|
||||
];
|
||||
|
||||
final PackageChangeState state = await checkPackageChangeState(package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_plugin/');
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, true);
|
||||
expect(state.needsChangelogChange, true);
|
||||
});
|
||||
|
||||
test(
|
||||
'requires changelog or version change if build.gradle diffs cannot '
|
||||
'be determined', () async {
|
||||
final RepositoryPackage package =
|
||||
createFakePlugin('a_plugin', packagesDir);
|
||||
|
||||
const List<String> changedFiles = <String>[
|
||||
'packages/a_plugin/android/build.gradle',
|
||||
];
|
||||
|
||||
final GitVersionFinder git = FakeGitVersionFinder(<String, List<String>>{
|
||||
'packages/a_plugin/android/build.gradle': <String>[]
|
||||
});
|
||||
|
||||
final PackageChangeState state = await checkPackageChangeState(package,
|
||||
changedPaths: changedFiles,
|
||||
relativePackagePath: 'packages/a_plugin/',
|
||||
git: git);
|
||||
|
||||
expect(state.hasChanges, true);
|
||||
expect(state.needsVersionChange, true);
|
||||
expect(state.needsChangelogChange, true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class FakeGitVersionFinder extends Fake implements GitVersionFinder {
|
||||
FakeGitVersionFinder(this.fileDiffs);
|
||||
|
||||
final Map<String, List<String>> fileDiffs;
|
||||
|
||||
@override
|
||||
Future<List<String>> getDiffContents({
|
||||
String? targetPath,
|
||||
bool includeUncommitted = false,
|
||||
}) async {
|
||||
return fileDiffs[targetPath]!;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user