From 487ed5738800ee7569b1d5a42467393f3f278102 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Mon, 22 May 2023 15:03:14 -0700 Subject: [PATCH] Suggest that people move to "beta" when they upgrade on "master" (#127146) Similar to https://github.com/flutter/flutter/pull/126972 but for master upgrades. Co-authored-by: Tim Sneath --- .../lib/src/commands/upgrade.dart | 19 ++- .../commands.shard/hermetic/upgrade_test.dart | 154 +++++++++++++++++- 2 files changed, 169 insertions(+), 4 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/upgrade.dart b/packages/flutter_tools/lib/src/commands/upgrade.dart index 294eb33899..e8f75bb5e5 100644 --- a/packages/flutter_tools/lib/src/commands/upgrade.dart +++ b/packages/flutter_tools/lib/src/commands/upgrade.dart @@ -47,6 +47,7 @@ class UpgradeCommand extends FlutterCommand { hide: !verboseHelp, help: 'Override the upgrade working directory. ' 'This is only intended to enable integration testing of the tool itself.' + // Also notably, this will override the FakeFlutterVersion if any is set! ) ..addFlag( 'verify-only', @@ -88,7 +89,7 @@ class UpgradeCommand extends FlutterCommand { @visibleForTesting class UpgradeCommandRunner { - String? workingDirectory; + String? workingDirectory; // set in runCommand() above Future runCommand({ required bool force, @@ -209,6 +210,22 @@ class UpgradeCommandRunner { await runDoctor(); // Force the welcome message to re-display following the upgrade. persistentToolState.setShouldRedisplayWelcomeMessage(true); + if (globals.flutterVersion.channel == 'master' || globals.flutterVersion.channel == 'main') { + globals.printStatus( + '\n' + 'This channel is intended for Flutter contributors. ' + 'This channel is not as thoroughly tested as the "beta" and "stable" channels. ' + 'We do not recommend using this channel for normal use as it more likely to contain serious regressions.\n' + '\n' + 'For information on contributing to Flutter, see our contributing guide:\n' + ' https://github.com/flutter/flutter/blob/master/CONTRIBUTING.md\n' + '\n' + 'For the most up to date stable version of flutter, consider using the "beta" channel instead. ' + 'The Flutter "beta" channel enjoys all the same automated testing as the "stable" channel, ' + 'but is updated roughly once a month instead of once a quarter.\n' + 'To change channel, run the "flutter channel beta" command.', + ); + } } Future hasUncommittedChanges() async { diff --git a/packages/flutter_tools/test/commands.shard/hermetic/upgrade_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/upgrade_test.dart index 1bfdb01ea8..9d07f82170 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/upgrade_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/upgrade_test.dart @@ -23,7 +23,6 @@ void main() { late FakeProcessManager processManager; UpgradeCommand command; late CommandRunner runner; - late FlutterVersion flutterVersion; setUpAll(() { Cache.disableLocking(); @@ -41,7 +40,6 @@ void main() { testUsingContext('can auto-migrate a user from dev to beta', () async { const String startingTag = '3.0.0-1.2.pre'; - flutterVersion = FakeFlutterVersion(channel: 'dev'); const String latestUpstreamTag = '3.0.0-1.3.pre'; const String upstreamHeadRevision = 'deadbeef'; final Completer reEntryCompleter = Completer(); @@ -116,7 +114,157 @@ void main() { expect(logger.statusText, contains("Transitioning from 'dev' to 'beta'...")); }, overrides: { FileSystem: () => fileSystem, - FlutterVersion: () => flutterVersion, + FlutterVersion: () => FakeFlutterVersion(channel: 'dev'), + Logger: () => logger, + ProcessManager: () => processManager, + }); + + const String startingTag = '3.0.0'; + const String latestUpstreamTag = '3.1.0'; + const String upstreamHeadRevision = '5765737420536964652053746f7279'; + + testUsingContext('can push people from master to beta', () async { + final Completer reEntryCompleter = Completer(); + + Future reEnterTool() async { + await runner.run(['upgrade', '--continue', '--no-version-check']); + reEntryCompleter.complete(); + } + + processManager.addCommands([ + const FakeCommand( + command: ['git', 'tag', '--points-at', 'HEAD'], + stdout: startingTag, + ), + const FakeCommand( + command: ['git', 'fetch', '--tags'], + ), + const FakeCommand( + command: ['git', 'rev-parse', '--verify', '@{upstream}'], + stdout: upstreamHeadRevision, + ), + const FakeCommand( + command: ['git', 'tag', '--points-at', upstreamHeadRevision], + stdout: latestUpstreamTag, + ), + const FakeCommand( + command: ['git', 'status', '-s'], + ), + const FakeCommand( + command: ['git', 'reset', '--hard', upstreamHeadRevision], + ), + FakeCommand( + command: const ['bin/flutter', 'upgrade', '--continue', '--no-version-check'], + onRun: reEnterTool, + completer: reEntryCompleter, + ), + + // commands following this are from the re-entrant `flutter upgrade --continue` call + + const FakeCommand( + command: ['git', 'tag', '--points-at', 'HEAD'], + stdout: latestUpstreamTag, + ), + const FakeCommand( + command: ['bin/flutter', '--no-color', '--no-version-check', 'precache'], + ), + const FakeCommand( + command: ['bin/flutter', '--no-version-check', 'doctor'], + ), + ]); + await runner.run(['upgrade']); + expect(processManager, hasNoRemainingExpectations); + expect(logger.statusText, + 'Upgrading Flutter to 3.1.0 from 3.0.0 in ${Cache.flutterRoot}...\n' + '\n' + 'Upgrading engine...\n' + '\n' + "Instance of 'FakeFlutterVersion'\n" // the real FlutterVersion has a better toString, heh + '\n' + 'Running flutter doctor...\n' + '\n' + 'This channel is intended for Flutter contributors. This channel is not as thoroughly ' + 'tested as the "beta" and "stable" channels. We do not recommend using this channel ' + 'for normal use as it more likely to contain serious regressions.\n' + '\n' + 'For information on contributing to Flutter, see our contributing guide:\n' + ' https://github.com/flutter/flutter/blob/master/CONTRIBUTING.md\n' + '\n' + 'For the most up to date stable version of flutter, consider using the "beta" channel ' + 'instead. The Flutter "beta" channel enjoys all the same automated testing as the ' + '"stable" channel, but is updated roughly once a month instead of once a quarter.\n' + 'To change channel, run the "flutter channel beta" command.\n' + ); + }, overrides: { + FileSystem: () => fileSystem, + FlutterVersion: () => FakeFlutterVersion(channel: 'master', frameworkVersion: startingTag, engineRevision: 'engine'), + Logger: () => logger, + ProcessManager: () => processManager, + }); + + testUsingContext('do not push people from beta to anything else', () async { + final Completer reEntryCompleter = Completer(); + + Future reEnterTool() async { + await runner.run(['upgrade', '--continue', '--no-version-check']); + reEntryCompleter.complete(); + } + + processManager.addCommands([ + const FakeCommand( + command: ['git', 'tag', '--points-at', 'HEAD'], + stdout: startingTag, + ), + const FakeCommand( + command: ['git', 'fetch', '--tags'], + ), + const FakeCommand( + command: ['git', 'rev-parse', '--verify', '@{upstream}'], + stdout: upstreamHeadRevision, + ), + const FakeCommand( + command: ['git', 'tag', '--points-at', upstreamHeadRevision], + stdout: latestUpstreamTag, + ), + const FakeCommand( + command: ['git', 'status', '-s'], + ), + const FakeCommand( + command: ['git', 'reset', '--hard', upstreamHeadRevision], + ), + FakeCommand( + command: const ['bin/flutter', 'upgrade', '--continue', '--no-version-check'], + onRun: reEnterTool, + completer: reEntryCompleter, + ), + + // commands following this are from the re-entrant `flutter upgrade --continue` call + + const FakeCommand( + command: ['git', 'tag', '--points-at', 'HEAD'], + stdout: latestUpstreamTag, + ), + const FakeCommand( + command: ['bin/flutter', '--no-color', '--no-version-check', 'precache'], + ), + const FakeCommand( + command: ['bin/flutter', '--no-version-check', 'doctor'], + ), + ]); + await runner.run(['upgrade']); + expect(processManager, hasNoRemainingExpectations); + expect(logger.statusText, + 'Upgrading Flutter to 3.1.0 from 3.0.0 in ${Cache.flutterRoot}...\n' + '\n' + 'Upgrading engine...\n' + '\n' + "Instance of 'FakeFlutterVersion'\n" // the real FlutterVersion has a better toString, heh + '\n' + 'Running flutter doctor...\n' + ); + }, overrides: { + FileSystem: () => fileSystem, + FlutterVersion: () => FakeFlutterVersion(channel: 'beta', frameworkVersion: startingTag, engineRevision: 'engine'), Logger: () => logger, ProcessManager: () => processManager, });