Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[tool] Improve check version ci so that it enforces the version in CHANGELOG and pubspec matches. #3678

Merged
merged 45 commits into from
Mar 10, 2021

Conversation

cyanglaz
Copy link
Contributor

@cyanglaz cyanglaz commented Mar 4, 2021

check version ci always make sure the version in CHANGELOG and pubspec matches for all the plugins.

Fixes flutter/flutter#77067

Pre-launch Checklist

  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@google-cla google-cla bot added the cla: yes label Mar 4, 2021
@cyanglaz cyanglaz requested a review from stuartmorgan-g March 4, 2021 22:02
# Sets CHANGED_PACKAGE_LIST and CHANGED_PACKAGES
check_changed_packages

plugin_tools version-check --base_sha="$(get_branch_base_sha)"
Copy link
Contributor Author

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

Comment on lines 14 to 15
# if [[ "${#CHANGED_PACKAGE_LIST[@]}" != 0 ]]; then
# fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Comment on lines 178 to 180
if (pubspec.publishTo == 'none') {
continue;
}
Copy link

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

source "$SCRIPT_DIR/common.sh"

# Sets CHANGED_PACKAGE_LIST and CHANGED_PACKAGES
check_changed_packages
Copy link
Contributor

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?

Comment on lines 14 to 15
# if [[ "${#CHANGED_PACKAGE_LIST[@]}" != 0 ]]; then
# fi
Copy link
Contributor

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.

@@ -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}) {
Copy link
Contributor

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.

Copy link
Contributor Author

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

Comment on lines 178 to 180
if (pubspec.publishTo == 'none') {
continue;
}
Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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.';
Copy link
Contributor

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)

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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{
Copy link
Contributor

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!'
]),
);
});
});
Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@cyanglaz cyanglaz requested a review from stuartmorgan-g March 9, 2021 20:35
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a 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)'}"
Copy link
Contributor

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?

changedFilesCommand.stdout.toString().isEmpty) {
return <String>[];
}
final List<String> changedFiles = changedFilesCommand.stdout
Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, done

baseShaFromMergeBase = await baseGitDir
.runCommand(<String>['merge-base', 'FETCH_HEAD', 'HEAD']);
}
return (baseShaFromMergeBase.stdout as String).replaceAll('\n', '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not trim()?

Copy link
Contributor Author

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'
Copy link
Contributor

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/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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}) {
Copy link
Contributor

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?

Copy link
Contributor Author

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 =
Copy link
Contributor

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) { ... }

?

Copy link
Contributor Author

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';
Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor Author

@cyanglaz cyanglaz left a 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

@@ -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}) {
Copy link
Contributor Author

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

changedFilesCommand.stdout.toString().isEmpty) {
return <String>[];
}
final List<String> changedFiles = changedFilesCommand.stdout
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, done

baseShaFromMergeBase = await baseGitDir
.runCommand(<String>['merge-base', 'FETCH_HEAD', 'HEAD']);
}
return (baseShaFromMergeBase.stdout as String).replaceAll('\n', '');
Copy link
Contributor Author

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'
Copy link
Contributor Author

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 =
Copy link
Contributor Author

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';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cyanglaz cyanglaz added waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. and removed p: device_info labels Mar 10, 2021
@fluttergithubbot fluttergithubbot merged commit 8feb2e7 into flutter:master Mar 10, 2021
@cyanglaz cyanglaz deleted the check_version branch March 10, 2021 22:15
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 10, 2021
fluttergithubbot pushed a commit to flutter/flutter that referenced this pull request Mar 11, 2021
yasargil added a commit to yasargil/plugins that referenced this pull request Mar 18, 2021
* 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)
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure pubspec and CHANGELOG version match
4 participants