Skip to content

Add current version to the upgrade message of the Flutter tool#68421

Merged
christopherfujino merged 7 commits intoflutter:masterfrom
karamage:show_current_version_on_upgrade
Nov 23, 2020
Merged

Add current version to the upgrade message of the Flutter tool#68421
christopherfujino merged 7 commits intoflutter:masterfrom
karamage:show_current_version_on_upgrade

Conversation

@karamage
Copy link
Contributor

@karamage karamage commented Oct 18, 2020

Description

Add current version to the upgrade message of the Flutter tool.

I'm a first-time contributor.
There are many things I don't understand, so please let me know.
Please point out any mistakes.
Thank you for reviewing it.

Upgrading Flutter to 1.22.1 from 1.22.0 in C:\Programming\Flutter\sdk\flutter...                                                            Checking Dart SDK version...                                                                                            Downloading Dart SDK from Flutter engine c8e3b9485386425213e2973126d6f57e7ed83c54...                                    Unzipping Dart SDK...
Building flutter tool...
Running pub upgrade...

Upgrading engine...

Related Issues

Add current version to the upgrade message of the Flutter tool. #63023

Tests

I added the following tests:

Replace this with a list of the tests that you added as part of this PR. A change in behavior with no test covering it
will likely get reverted accidentally sooner or later. PRs must include tests for all changed/updated/fixed behaviors. See Test Coverage.

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Oct 18, 2020
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@google-cla
Copy link

google-cla bot commented Oct 18, 2020

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no label Oct 18, 2020
@jonahwilliams
Copy link
Contributor

@karamage can you sign the CLA?

@karamage
Copy link
Contributor Author

@jonahwilliams
OK.
I signed the CLA.

@karamage
Copy link
Contributor Author

@googlebot I signed it!

@google-cla google-cla bot added cla: yes and removed cla: no labels Oct 22, 2020
@jonahwilliams jonahwilliams self-requested a review October 23, 2020 04:42
Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

Seems like a nice change! If you can add a test case I'd be happy to land this

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't currently have any tests for what gets printed during the upgrade. The closest example is one that checks that a message is printed if nothing is upgraded:

https://github.com/flutter/flutter/blob/master/packages/flutter_tools/test/commands.shard/permeable/upgrade_test.dart#L92

I would see if you adapt that to add coverage for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reviewing it for you.
I agree with you about adding a test.
I'll TRY to do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sorry.
I tried, but I can't add the test.
I want to check the standard output, please tell me how to do it.

Reference.

expect(testLogger.statusText, contains('Flutter is already up to date'));

I ran the test and the testLogger.statusText was empty.

Please let me know.

Copy link
Contributor

Choose a reason for hiding this comment

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

@karamage check if the status text you want to display is actually being displayed, like these lines in a similar test:

expect(testLogger.statusText, contains('A new version of Flutter is available'));
expect(testLogger.statusText, contains(fakeCommandRunner.remoteRevision));
expect(testLogger.statusText, contains(revision));

I think you should take this (similar)test as a reference to create your new test:

testUsingContext("Doesn't throw on known tag, dev branch, no force", () async {
final Future<FlutterCommandResult> result = fakeCommandRunner.runCommand(
force: false,
continueFlow: false,
testFlow: false,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@royarg02 Thank you. I'll try.

Copy link
Contributor

Choose a reason for hiding this comment

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

Try this out for a bit and let me know if you make any progress. I will take a look at this PR again tomorrow and make some suggestions to get your test working correctly

Copy link
Contributor

Choose a reason for hiding this comment

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

@karamage I think you need to use realCommandRunner in this case, as fakeCommandRunner.upgradeChannel doesn't do anything:

Future<void> upgradeChannel(FlutterVersion flutterVersion) async {}

It also explains you getting Actual: '' in your test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. I appreciate it.

Okay, I understand.

I will try to write the test code using realCommandRunner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@royarg02 @jonahwilliams

I've added the test code.

I would like you to review it.

Thank you for showing me how to test it.

The test was a success.

../../bin/dart pub run test test/commands.shard/permeable/upgrade_test.dart
00:04 +15: All tests passed!

Copy link
Contributor

Choose a reason for hiding this comment

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

🎊

Copy link
Contributor

Choose a reason for hiding this comment

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

I would leave this message in upgradeChannel, and instead pass the upstreamRevision revision in as an argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood. I will modify it to pass in arguments.

Copy link
Contributor

Choose a reason for hiding this comment

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

For just a single identifier you don't need the{}:

Suggested change
globals.printStatus('Upgrading Flutter to ${upstreamRevision} from ${flutterVersion.frameworkRevision} ($workingDirectory...)');
globals.printStatus('Upgrading Flutter to $upstreamRevision from ${flutterVersion.frameworkRevision} ($workingDirectory...)');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll fix it.

@karamage karamage force-pushed the show_current_version_on_upgrade branch from ba1ddb5 to 1b842c5 Compare October 28, 2020 14:08
@google-cla
Copy link

google-cla bot commented Oct 28, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no and removed cla: yes labels Oct 28, 2020
@karamage
Copy link
Contributor Author

@googlebot I consent.

@google-cla
Copy link

google-cla bot commented Oct 28, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@royarg02
Copy link
Contributor

@googlebot I consent.

@google-cla google-cla bot added cla: yes and removed cla: no labels Oct 28, 2020
jonahwilliams
jonahwilliams previously approved these changes Oct 29, 2020
Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM!

I'd also like @christopherfujino to double check too. Thank you @royarg02 for the help as well

Copy link
Contributor

@royarg02 royarg02 Oct 29, 2020

Choose a reason for hiding this comment

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

I just realized that flutterVersion.frameworkRevision is probably not what the PR was intending to use:

Take a look at these lines of code:

String toString() {
final String versionText = frameworkVersion == 'unknown' ? '' : ' $frameworkVersion';
final String flutterText = 'Flutter$versionText • channel $channel • ${repositoryUrl ?? 'unknown source'}';
final String frameworkText = 'Framework • revision $frameworkRevisionShort ($frameworkAge) • $frameworkCommitDate';
final String engineText = 'Engine • revision $engineRevisionShort';
final String toolsText = 'Tools • Dart $dartSdkVersion';
// Flutter 1.10.2-pre.69 • channel master • https://github.com/flutter/flutter.git
// Framework • revision 340c158f32 (84 minutes ago) • 2018-10-26 11:27:22 -0400
// Engine • revision 9c46333e14
// Tools • Dart 2.1.0 (build 2.1.0-dev.8.0 bf26f760b1)
return '$flutterText\n$frameworkText\n$engineText\n$toolsText';
}

My understanding is that flutterVersion.frameworkVersion should be used, but is there anyway the corresponding version of the upstreamRevision could be obtained?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thats a good point, it is probably printing out the commit hash right now. We should know what the tag we're checking out is

Copy link
Contributor

Choose a reason for hiding this comment

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

This might be something of interest in that case:

_frameworkVersion = gitTagVersion.frameworkVersionFor(_frameworkRevision);

Copy link
Contributor

Choose a reason for hiding this comment

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

Thats a good point, it is probably printing out the commit hash right now. We should know what the tag we're checking out is

@jonahwilliams You're right. #68866 was merged yesterday which uses flutterVersion.frameworkRevision:

$ flutter upgrade --verify-only
A new version of Flutter is available on channel master

The latest revision: 18341efa2fb8c3570ca32e71d1a9da74e8b2cbf5
Your current version: 8b9e9680d24ffd4b3dbfa216f5f64a0490088f45

To upgrade now, run "flutter upgrade".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@royarg02 @jonahwilliams Thanks for reviewing it for you.
I understand that using flutterVersion.frameworkRevision is a mistake.
Thank you.

I will modify it to use frameworkVersion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have modified it to use frameworkVersion.
I also rewrote the test and it was successful!
Please give you a review.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm taking a look now.

@jonahwilliams jonahwilliams requested review from jonahwilliams and removed request for jonahwilliams October 30, 2020 20:14
@jonahwilliams jonahwilliams dismissed their stale review October 30, 2020 20:16

out of date

@christopherfujino christopherfujino changed the title Add current version to the upgrade message of the Flutter tool. #63023 Add current version to the upgrade message of the Flutter tool Oct 30, 2020
Copy link
Contributor

@christopherfujino christopherfujino Oct 30, 2020

Choose a reason for hiding this comment

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

Unfortunately, I don't believe this is right either. The .frameworkVersionFor() method is confusingly named. It does not return the correct version for the input revision you input, but rather the GitTagVersion that it is a method for. And on line 157, I believe that gitTagVersion is the current HEAD, or the version that the tool is currently at.

Please see my comments at @royarg02's PR for more context: https://github.com/flutter/flutter/pull/69420/files#r515275570. It seems like are both trying to hook into functionality that we don't yet support (namely, creating a GitTagVersion object for a commit that ISN'T HEAD). It would be great if the two of you could coordinate implementing this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@karamage I've updated #69420 as per suggestions from @christopherfujino. Please have a look at it(I've not updated the tests yet).

If you need any clarifications about my approach, or have a better idea on implementing the feature, we can discuss on the chat.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@royarg02 @christopherfujino Thanks for your suggestion.
I'll look at #69420.

I am trying to understand your approach.

@royarg02
Copy link
Contributor

@karamage #69420 has landed. You can work on this PR now.

@karamage
Copy link
Contributor Author

@royarg02 Thank you. I will work on this PR.

@karamage karamage force-pushed the show_current_version_on_upgrade branch from 459da7e to 5bba3db Compare November 21, 2020 02:37
@karamage
Copy link
Contributor Author

I went back to the changes because of the conflicts.

I will continue to change the PR from here.

It's going to take some time to understand the changes.

@karamage
Copy link
Contributor Author

I saw #69420. It was very informative. Thank you.

I wrote the code for this PR, but I'm not sure if it's good enough.

The upgradeChannel method is gone, so I made a change to the recordState method.

If I'm wrong, please let me know.

I wrote the test code and ran the test.
The test was successful.

Thank you for reading.


void recordState(FlutterVersion flutterVersion) {
void recordState(FlutterVersion flutterVersion, FlutterVersion upstreamVersion) {
globals.printStatus('Upgrading Flutter to ${upstreamVersion.frameworkVersion} from ${flutterVersion.frameworkVersion} in $workingDirectory...');
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be better if you directly put this line in runCommandFirstHalf after calling recordState.

const String upstreamVersion = '4.5.6';

when(flutterVersion.frameworkRevision).thenReturn(revision);
when(flutterVersion.frameworkRevisionShort).thenReturn(revision);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you'll need flutterVersion.frameworkRevisionShort in your test.
Same for latestVersion.frameworkRevisionShort below.

),
);
realCommandRunner.recordState(flutterVersion, latestVersion);
expect(testLogger.statusText, contains('Upgrading Flutter to ${latestVersion.frameworkVersion} from ${flutterVersion.frameworkVersion} in ${realCommandRunner.workingDirectory}'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Tests should be matched against hardcoded strings.
See #69420 (comment) for context.

@karamage karamage force-pushed the show_current_version_on_upgrade branch from a313aa9 to 348656f Compare November 23, 2020 02:20
@karamage
Copy link
Contributor Author

@royarg02 Your suggestions were very helpful. Thank you.
I have modified the code according to your suggestion.
I would appreciate it if you could take a look at the code again.

]),
]);

await realCommandRunner.runCommandFirstHalf(force: true, gitTagVersion: gitTagVersion, flutterVersion: flutterVersion, testFlow: true, verifyOnly: false);
Copy link
Contributor

@royarg02 royarg02 Nov 23, 2020

Choose a reason for hiding this comment

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

Since the message you are expecting is in runCommandFirstHalf, it would be preferable to run fakeCommandRunner.runCommand and await for FlutterCommandResult.success instead of adding commands explicitly to processManager, just like other tests.

Also, please format the call as following:

final Future<FlutterCommandResult> result = fakeCommandRunner.runCommand(
        force: false,
        continueFlow: false,
        testFlow: false,
        gitTagVersion: gitTagVersion,
        flutterVersion: flutterVersion,
        verifyOnly: true,
      );

]);

await realCommandRunner.runCommandFirstHalf(force: true, gitTagVersion: gitTagVersion, flutterVersion: flutterVersion, testFlow: true, verifyOnly: false);
expect(testLogger.statusText, contains('Upgrading Flutter to 4.5.6 from 1.2.3 in null'));
Copy link
Contributor

@royarg02 royarg02 Nov 23, 2020

Choose a reason for hiding this comment

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

Could you change null to something meaningful? I think using fakeCommandRunner.workingDirectory may fix this.

@karamage
Copy link
Contributor Author

@royarg02 The improvements you have pointed out have been very helpful.
Thanks to that, I now understand how to use the fakeCommandRunner.

I have fixed the test code, could you take a look at it?
Thank you, I've fixed it and would appreciate it if you could take a look.

@royarg02
Copy link
Contributor

royarg02 commented Nov 23, 2020

Everything looks good, let's see how the maintainers respond.

You may want to update the original PR comment.

Copy link
Contributor

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks so much @karamage for making this change and @royarg02 for helping and doing code review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants