-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[tool] Improve check version ci so that it enforces the version in CHANGELOG and pubspec matches. #3678
Conversation
script/check_version.sh
Outdated
# Sets CHANGED_PACKAGE_LIST and CHANGED_PACKAGES | ||
check_changed_packages | ||
|
||
plugin_tools version-check --base_sha="$(get_branch_base_sha)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be moved into the if block below before merging
script/check_version.sh
Outdated
# if [[ "${#CHANGED_PACKAGE_LIST[@]}" != 0 ]]; then | ||
# fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, before merging, ill move the check into this if block so pre-submit only checks version for changed packages. (also add a block to run everything when on master
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same; I would much rather this be Dart.
if (pubspec.publishTo == 'none') { | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be handy if a plugin is a WIP state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes testing very hard, because in testing, pubspecs are all created with publishTo = none. See: https://github.com/flutter/plugins/blob/master/script/tool/test/util.dart#L154-L156
So this check basically made tests imposable if we want to test with a pubspec that contains versions.
I was thinking even for WIP plugins, it is still ok to check to see if versions match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we change that test safeguard from none
to some made up pub server that doesn't exist, so it wouldn't clash with real none
entries?
.cirrus.yml
Outdated
- name: version | ||
script: | ||
- flutter channel master | ||
- ./script/check_version.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's fold this into the publishable
task a new script line. There's some overhead to each job we spin up, and this is conceptually part of publishable
IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
script/check_version.sh
Outdated
source "$SCRIPT_DIR/common.sh" | ||
|
||
# Sets CHANGED_PACKAGE_LIST and CHANGED_PACKAGES | ||
check_changed_packages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we do this in Dart so we're not adding more logic to shell scripts that we need to deal with?
script/check_version.sh
Outdated
# if [[ "${#CHANGED_PACKAGE_LIST[@]}" != 0 ]]; then | ||
# fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same; I would much rather this be Dart.
script/tool/lib/src/common.dart
Outdated
@@ -140,6 +142,13 @@ bool isLinuxPlugin(FileSystemEntity entity, FileSystem fileSystem) { | |||
return pluginSupportsPlatform(kLinux, entity, fileSystem); | |||
} | |||
|
|||
/// Throws a [ToolExit] with `exitCode` and log the `errorMessage` in red. | |||
void ThrowsToolExit({@required String errorMessage, int exitCode = 1}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Throws/Throw/; this name sounds like a test function to validate that something throws a ToolExit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. Renamed it as PrintErrorAndExit
if (pubspec.publishTo == 'none') { | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we change that test safeguard from none
to some made up pub server that doesn't exist, so it wouldn't clash with real none
entries?
// get version from CHANGELOG | ||
final File changelog = plugin.childFile('CHANGELOG.md'); | ||
final List<String> lines = changelog.readAsLinesSync(); | ||
final String firstLine = lines.first; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably skip blank lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
|
||
if (fromPubspec != fromChangeLog) { | ||
final String error = 'versions for $packageName in CHANGELOG.md and pubspec.yaml do not match.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please print the two versions here for debugging if there are issues (e.g., if some accidentally put something after the version on the CHANGELOG line, it might not be obvious why this fails)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
print('${plugin.basename} passed version check'); | ||
} | ||
|
||
// ignore: missing_return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this a real bug you're suppressing, since you're only handling Exception
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -196,6 +196,73 @@ void main() { | |||
expect(gitDirCommands[2].join(' '), | |||
equals('show HEAD:packages/plugin_platform_interface/pubspec.yaml')); | |||
}); | |||
|
|||
test('Throws if first line in change log is empty', () async{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we want to do this? Isn't an empty first line a harmless cosmetic thing that we should just ignore?
'No version check errors found!' | ||
]), | ||
); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include a test where the version matches an older entry in the CHANGELOG (an actual bug that's happened).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, just some small things left. Yay for less logic in bash! (And a clear path to migrate some of our other bash easily.)
.cirrus.yml
Outdated
@@ -8,6 +8,8 @@ task: | |||
memory: 16G | |||
env: | |||
INTEGRATION_TEST_PATH: "./packages/integration_test" | |||
PLUGIN_TOOLS: "dart run ./script/tool/lib/src/main.dart" | |||
BRANCH: "${BRANCH:-'$(git rev-parse --abbrev-ref HEAD)'}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this just $CIRRUS_BRANCH
?
script/tool/lib/src/common.dart
Outdated
changedFilesCommand.stdout.toString().isEmpty) { | ||
return <String>[]; | ||
} | ||
final List<String> changedFiles = changedFilesCommand.stdout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changedFilesCommand.stdout.toString()
is used three times; let's make it a local variable. (You could avoid the early return and its two checks by just setting that string with an ?? ''
and then proceeding; an empty string fed to the logic below should give you an empty list).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, done
script/tool/lib/src/common.dart
Outdated
baseShaFromMergeBase = await baseGitDir | ||
.runCommand(<String>['merge-base', 'FETCH_HEAD', 'HEAD']); | ||
} | ||
return (baseShaFromMergeBase.stdout as String).replaceAll('\n', ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not trim()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
@override | ||
final String name = 'version-check'; | ||
|
||
@override | ||
final String description = | ||
'Checks if the versions of the plugins have been incremented per pub specification.\n\n' | ||
'Checks if the versions of the plugins have been incremented per pub specification.\n' | ||
'Also checks if the version in CHANGELOG matches the version in pubspec.\n\n' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/the version/the latest version/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
script/tool/lib/src/common.dart
Outdated
@@ -140,6 +144,13 @@ bool isLinuxPlugin(FileSystemEntity entity, FileSystem fileSystem) { | |||
return pluginSupportsPlatform(kLinux, entity, fileSystem); | |||
} | |||
|
|||
/// Throws a [ToolExit] with `exitCode` and log the `errorMessage` in red. | |||
void PrintErrorAndExit({@required String errorMessage, int exitCode = 1}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this Print
rather than print
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, it is probably caused by context switching between CPP and dart. Will fix
String firstLineWithText; | ||
final Iterator iterator = lines.iterator; | ||
while (iterator.moveNext()) { | ||
final String currentStriptEmptySpaces = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just:
if ((iterator.current as String).trim()?.isNotEmpty == true) { ... }
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Version fromChangeLog = Version.parse(versionString); | ||
if (fromChangeLog == null) { | ||
final String error = | ||
'Cannot find version on the first line of CHANGELOG.md'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This path isn't printing what it found and tried to parse (related to previous review comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated based on your review, PTAL @stuartmorgan
script/tool/lib/src/common.dart
Outdated
@@ -140,6 +144,13 @@ bool isLinuxPlugin(FileSystemEntity entity, FileSystem fileSystem) { | |||
return pluginSupportsPlatform(kLinux, entity, fileSystem); | |||
} | |||
|
|||
/// Throws a [ToolExit] with `exitCode` and log the `errorMessage` in red. | |||
void PrintErrorAndExit({@required String errorMessage, int exitCode = 1}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, it is probably caused by context switching between CPP and dart. Will fix
script/tool/lib/src/common.dart
Outdated
changedFilesCommand.stdout.toString().isEmpty) { | ||
return <String>[]; | ||
} | ||
final List<String> changedFiles = changedFilesCommand.stdout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, done
script/tool/lib/src/common.dart
Outdated
baseShaFromMergeBase = await baseGitDir | ||
.runCommand(<String>['merge-base', 'FETCH_HEAD', 'HEAD']); | ||
} | ||
return (baseShaFromMergeBase.stdout as String).replaceAll('\n', ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
@override | ||
final String name = 'version-check'; | ||
|
||
@override | ||
final String description = | ||
'Checks if the versions of the plugins have been incremented per pub specification.\n\n' | ||
'Checks if the versions of the plugins have been incremented per pub specification.\n' | ||
'Also checks if the version in CHANGELOG matches the version in pubspec.\n\n' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
String firstLineWithText; | ||
final Iterator iterator = lines.iterator; | ||
while (iterator.moveNext()) { | ||
final String currentStriptEmptySpaces = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Version fromChangeLog = Version.parse(versionString); | ||
if (fromChangeLog == null) { | ||
final String error = | ||
'Cannot find version on the first line of CHANGELOG.md'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…on in CHANGELOG and pubspec matches. (flutter/plugins#3678)
…on in CHANGELOG and pubspec matches. (flutter/plugins#3678) (#77854)
* master: (49 commits) Prep for alignment with Flutter analysis options (flutter#3703) [google_maps_flutter_platform_interface] Mark constructors as const for ids (flutter#3718) [image_picker] Endorse image_picker_for_web (flutter#3717) Add missing licenses, and add a check (flutter#3720) [ci] Add libgcrypt to Docker image. (flutter#3711) Reorder the checkboxes in the PR template (flutter#3666) Re-endorse connectivity_for_web (flutter#3708) Fix missing declaration of windows' default_package (flutter#3705) Typos in comments (flutter#2846) Skip flutter upgrade for pod linting Cirrus task (flutter#3700) [cross_file] Delete. (flutter#3698) [tool] Improve check version ci so that it enforces the version in CHANGELOG and pubspec matches. (flutter#3678) Streamline CI setup, and reenable macOS credits (flutter#3697) [video_player] fixed misleading size and aspect ratio documentation (flutter#3668) [image_picker] Implemented 2860 and added Unit Test to test functionality (flutter#3685) [shared_preferences] Fix concurrent modification of the shared preferences on Android (flutter#3684) [extension_google_sign_in_as_googleapis_auth] Deleted. (flutter#3694) Skip pod lint tests (flutter#3692) [Video_Player] Remove the deprecated API reference. (flutter#3669) [google_sign_in] fix test(flutter#3690) ...
check version ci always make sure the version in CHANGELOG and pubspec matches for all the plugins.
Fixes flutter/flutter#77067
Pre-launch Checklist
[shared_preferences]
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.