Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Clean up the tool code #499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Dry run on pull request
if: ${{ github.event_name == 'pull_request' }}
run: |
./tools/tools_runner.sh publish-plugin \
./tools/tools_runner.sh publish \
--all-changed \
--pub-publish-flags=--dry-run \
--base-sha=HEAD~
Expand All @@ -34,12 +34,12 @@ jobs:
wait-interval: 180 # seconds
allowed-conclusions: success
verbose: false
- name: Publish plugins
- name: Publish packages
if: ${{ github.event_name == 'push' }}
env:
PUB_CREDENTIALS: ${{ secrets.PUB_CREDENTIALS }}
run: |
./tools/tools_runner.sh publish-plugin \
./tools/tools_runner.sh publish \
--all-changed \
--base-sha=HEAD~ \
--skip-confirmation
6 changes: 3 additions & 3 deletions tools/LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved.
Copyright 2013 The Flutter Authors. All rights reserved.
Copyright (c) 2022 Samsung Electronics Co., Ltd. All rights reserved.
Copyright (c) 2013 The Flutter Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Expand All @@ -10,7 +10,7 @@ are permitted provided that the following conditions are met:
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google Inc. nor the names of its
* Neither the names of the copyright holders nor the names of the
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

Expand Down
78 changes: 29 additions & 49 deletions tools/lib/src/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ import 'dart:io' as io;

import 'package:file/file.dart';
import 'package:flutter_plugin_tools/src/common/core.dart';
import 'package:flutter_plugin_tools/src/common/package_looping_command.dart';
import 'package:flutter_plugin_tools/src/common/process_runner.dart';

import 'process_runner_apis.dart';
import 'tizen_sdk.dart';

export 'package:flutter_plugin_tools/src/common/package_looping_command.dart'
show PackageResult, RunState;

/// A reference to a Tizen device (either physical or emulator) that can run
/// Flutter applications.
///
Expand Down Expand Up @@ -114,36 +110,24 @@ class Device {

/// Runs integration test in [workingDir].
///
/// [workingDir] must be a valid exisiting flutter directory where
/// `flutter pub get` has already been ran succesfully. For an app project,
/// [workingDir] must be a valid existing Flutter project directory where
/// `flutter pub get` has already been run succesfully. For an app project,
/// [workingDir] is the app's source root. For a plugin project, [workingDir]
/// is one of the example directories.
///
/// If test doesn't finish after [timeout], it's considered a failure and the
/// function will return [PackageResult.fail] with time expired log.
///
/// Returns [PackageResult.success] when every test passes succesfully,
/// otherwise returns [PackageResult.fail]. Never returns [PackageResult.skip]
/// nor [PackageResult.exclude].
Future<PackageResult> runIntegrationTest(
/// Returns null if all tests have passed successfully before [timeout],
/// otherwise returns a string with the error details.
Future<String?> runIntegrationTest(
Directory workingDir,
Duration timeout, {
bool debug = false,
}) async {
Duration timeout,
) async {
if (!isConnected) {
return PackageResult.fail(
<String>['Device $name ($profile) is not connected.']);
return 'Device $name ($profile) is not connected.';
}

final io.Process process = await _processRunner.start(
'flutter-tizen',
<String>[
if (debug) '-v',
'-d',
serial!,
'test',
'integration_test',
],
<String>['-d', serial!, 'test', 'integration_test'],
workingDirectory: workingDir,
);

Expand Down Expand Up @@ -173,30 +157,27 @@ class Device {
// guarantee that all buffered outputs of the process have returned.
await completer.future;

final List<String> errors = <String>[];
String? error;
if (timedOut) {
errors.add('Timeout expired. The test may need more time to finish. '
error = 'Timeout expired. The test may need more time to finish. '
'If you expect the test to finish before timeout, check if the tests '
'require device screen to be awake or if they require manually '
'clicking the UI button for permissions.');
'clicking the UI button for permissions.';
} else if (lastLine.startsWith('No tests ran')) {
errors.add(
'Missing integration tests (use --exclude if this is intentional).');
error =
'Missing integration tests (use --exclude if this is intentional).';
} else if (lastLine.startsWith('No devices found')) {
errors.add('Device was disconnected during test.');
error = 'Device was disconnected during test.';
} else {
final RegExpMatch? match = _logPattern.firstMatch(lastLine);
if (match == null || match.group(2) == null) {
throw Exception('Log message is not parsed correctly.');
error = 'Could not parse the log output.';
} else if (!match.group(2)!.startsWith('All tests passed!')) {
errors.add('flutter-tizen test integration_test failed, see the output '
'above for details.');
error = 'flutter-tizen test integration_test failed, see the output '
'above for details.';
}
}

return errors.isEmpty
? PackageResult.success()
: PackageResult.fail(errors);
return error;
}
}

Expand Down Expand Up @@ -247,6 +228,7 @@ class EmulatorDevice extends Device {
final io.ProcessResult result =
_processRunner.runSync(_tizenSdk.emCli.path, <String>['list-vm']);
if (result.exitCode != 0) {
print('Error: Unable to list available emulators.');
throw ToolExit(result.exitCode);
}

Expand Down Expand Up @@ -319,11 +301,10 @@ class EmulatorDevice extends Device {
}

/// Deletes this emulator.
Future<void> delete() async => await _processRunner.runAndStream(
_tizenSdk.emCli.path,
<String>['delete', '-n', name],
exitOnError: true,
);
Future<void> delete() async {
await _processRunner
.runAndStream(_tizenSdk.emCli.path, <String>['delete', '-n', name]);
}

/// Launches this emualtor.
Future<void> launch() async {
Expand Down Expand Up @@ -385,7 +366,7 @@ class EmulatorDevice extends Device {
Future<void> _poll(
FutureOr<bool> Function() function, {
Duration interval = const Duration(seconds: 1),
Duration timeout = const Duration(minutes: 10),
Duration timeout = const Duration(minutes: 5),
}) async {
final DateTime start = DateTime.now();
while (DateTime.now().difference(start) <= timeout) {
Expand All @@ -398,11 +379,10 @@ class EmulatorDevice extends Device {
}

@override
Future<PackageResult> runIntegrationTest(
Future<String?> runIntegrationTest(
Directory workingDir,
Duration timeout, {
bool debug = false,
}) async {
Duration timeout,
) async {
bool autoLaunched = false;
bool autoCreated = false;
try {
Expand All @@ -415,7 +395,7 @@ class EmulatorDevice extends Device {
await launch();
}
_disablePermissionPopups();
return await super.runIntegrationTest(workingDir, timeout, debug: debug);
return await super.runIntegrationTest(workingDir, timeout);
} finally {
if (autoLaunched) {
await close();
Expand Down
37 changes: 18 additions & 19 deletions tools/lib/src/integration_test_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import 'package:args/args.dart';
import 'package:file/file.dart';
import 'package:file/local.dart';
import 'package:flutter_plugin_tools/src/common/core.dart';
import 'package:flutter_plugin_tools/src/common/package_command.dart';
import 'package:flutter_plugin_tools/src/common/package_looping_command.dart';
import 'package:flutter_plugin_tools/src/common/plugin_command.dart';
import 'package:flutter_plugin_tools/src/common/repository_package.dart';
import 'package:yaml/yaml.dart';

Expand Down Expand Up @@ -58,16 +58,16 @@ class IntegrationTestCommand extends PackageLoopingCommand {
);
argParser.addOption(
_timeoutArg,
help: 'Timeout limit of each integration test in seconds.',
help: 'Time in seconds to wait for each test to finish.',
valueHelp: 'seconds',
defaultsTo: _timeout.inSeconds.toString(),
);
}

/// Copied from [PluginCommand].
/// Copied from [PackageCommand].
static const String _excludeArg = 'exclude';

/// Copied from [PluginCommand].
/// Copied from [PackageCommand].
static const String _packagesArg = 'packages';

static const String _generateEmulatorsArg = 'generate-emulators';
Expand Down Expand Up @@ -142,7 +142,7 @@ class IntegrationTestCommand extends PackageLoopingCommand {
}
}

/// See: [PluginCommand.getTargetPackages].
/// See: [PackageCommand.getTargetPackages].
@override
Stream<PackageEnumerationEntry> getTargetPackages({
bool filterExcluded = true,
Expand All @@ -151,19 +151,19 @@ class IntegrationTestCommand extends PackageLoopingCommand {
yield* super.getTargetPackages(filterExcluded: filterExcluded);
} else {
final Recipe recipe = _recipe!;
final List<PackageEnumerationEntry> plugins = await super
final List<PackageEnumerationEntry> packages = await super
.getTargetPackages(filterExcluded: filterExcluded)
.toList();

for (final PackageEnumerationEntry plugin in plugins) {
final String pluginName = plugin.package.displayName;
if (!recipe.contains(pluginName)) {
for (final PackageEnumerationEntry package in packages) {
final String packageName = package.package.displayName;
if (!recipe.contains(packageName)) {
continue;
}
if (!(filterExcluded && plugin.excluded)) {
yield recipe.isExcluded(pluginName)
? PackageEnumerationEntry(plugin.package, excluded: true)
: plugin;
if (!(filterExcluded && package.excluded)) {
yield recipe.isExcluded(packageName)
? PackageEnumerationEntry(package.package, excluded: true)
: package;
}
}
}
Expand Down Expand Up @@ -224,15 +224,14 @@ class IntegrationTestCommand extends PackageLoopingCommand {
}

for (final Device device in devices) {
PackageResult packageResult =
String? error =
await device.runIntegrationTest(example.directory, _timeout);
if (packageResult.state == RunState.failed) {
if (error != null) {
// Tests may fail unexpectedly on a self-hosted runner. Try again.
packageResult = await device
.runIntegrationTest(example.directory, _timeout, debug: true);
error = await device.runIntegrationTest(example.directory, _timeout);
}
if (packageResult.state == RunState.failed) {
errors.addAll(packageResult.details);
if (error != null) {
errors.add(error);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tools/lib/src/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'package:flutter_plugin_tools/src/list_command.dart';

import 'build_examples_command.dart';
import 'integration_test_command.dart';
import 'publish_plugin_command.dart';
import 'publish_command.dart';

void main(List<String> args) {
const FileSystem fileSystem = LocalFileSystem();
Expand All @@ -40,7 +40,7 @@ void main(List<String> args) {
..addCommand(FormatCommand(packagesDir))
..addCommand(IntegrationTestCommand(packagesDir))
..addCommand(ListCommand(packagesDir))
..addCommand(PublishPluginCommand(packagesDir));
..addCommand(PublishCommand(packagesDir));

commandRunner.run(args).catchError((Object e) {
final ToolExit toolExit = e as ToolExit;
Expand Down
1 change: 0 additions & 1 deletion tools/lib/src/process_runner_apis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'dart:io' as io;

import 'package:file/file.dart';
import 'package:flutter_plugin_tools/src/common/core.dart';

import 'package:flutter_plugin_tools/src/common/process_runner.dart';

/// An extension method of [ProcessRunner] to supports synchronous operations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,25 @@ import 'package:file/file.dart';
import 'package:flutter_plugin_tools/src/common/core.dart';
import 'package:flutter_plugin_tools/src/common/file_utils.dart';
import 'package:flutter_plugin_tools/src/common/git_version_finder.dart';
import 'package:flutter_plugin_tools/src/common/package_command.dart';
import 'package:flutter_plugin_tools/src/common/package_looping_command.dart';
import 'package:flutter_plugin_tools/src/common/plugin_command.dart';
import 'package:flutter_plugin_tools/src/common/process_runner.dart';
import 'package:flutter_plugin_tools/src/common/pub_version_finder.dart';
import 'package:flutter_plugin_tools/src/common/repository_package.dart';
import 'package:flutter_plugin_tools/src/publish_command.dart'
as flutter_plugin_tools;
import 'package:http/http.dart' as http;
import 'package:path/path.dart' as p;
import 'package:platform/platform.dart';
import 'package:pub_semver/pub_semver.dart';

/// Wraps pub publish with a few niceties used by the flutter-tizen team.
// The code is mostly copied from `PublishPluginCommand` in
// `flutter_plugin_tools`, parts regarding git tagging are removed as we don't
// tag our releases.
class PublishPluginCommand extends PackageLoopingCommand {
///
/// The code is a copy of [flutter_plugin_tools.PublishCommand] with parts
/// related to git tagging removed as we don't tag our releases.
class PublishCommand extends PackageLoopingCommand {
/// Creates an instance of the publish command.
PublishPluginCommand(
PublishCommand(
super.packagesDir, {
super.processRunner = const ProcessRunner(),
super.platform = const LocalPlatform(),
Expand All @@ -48,23 +50,18 @@ class PublishPluginCommand extends PackageLoopingCommand {
help:
'Release all packages that contains pubspec changes at the current commit compares to the base-sha.\n'
'The --packages option is ignored if this is on.',
defaultsTo: false,
);
argParser.addFlag(
_dryRunFlag,
help:
'Skips the real `pub publish` command and assumes the command is successful.\n'
'This does not run `pub publish --dry-run`.\n'
'If you want to run the command with `pub publish --dry-run`, use `--pub-publish-flags=--dry-run`',
defaultsTo: false,
negatable: true,
);
argParser.addFlag(
_skipConfirmationFlag,
help: 'Run the command without asking for Y/N inputs.\n'
'This command will add a `--force` flag to the `pub publish` command if it is not added with $_pubFlagsOption\n',
defaultsTo: false,
negatable: true,
);
}

Expand All @@ -76,7 +73,7 @@ class PublishPluginCommand extends PackageLoopingCommand {
static const String _pubCredentialName = 'PUB_CREDENTIALS';

@override
String get name => 'publish-plugin';
String get name => 'publish';

@override
String get description => 'Attempts to publish the given packages to pub.\n'
Expand Down
Loading