mirror of
https://github.com/flutter/samples.git
synced 2026-04-17 04:22:16 +00:00
@@ -1,3 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:yaml/yaml.dart';
|
||||
@@ -8,19 +9,39 @@ Future<void> main() async {
|
||||
final pubspecContent = await pubspecFile.readAsString();
|
||||
final pubspecYaml = loadYaml(pubspecContent);
|
||||
|
||||
// contains full list of samples
|
||||
final workspace = pubspecYaml['workspace'] as YamlList?;
|
||||
|
||||
if (workspace == null) {
|
||||
print('No workspace found in pubspec.yaml');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// CI always skips the samples on this list
|
||||
final skipCiList = pubspecYaml['skip_ci'] as YamlList?;
|
||||
|
||||
// CI will also skip for samples on specific branches
|
||||
// This is useful when API changes in the beta branch are causing CI to fail
|
||||
// and there isn't a solution that works in both beta and main
|
||||
final channel = await _getFlutterChannel();
|
||||
print('Current Flutter channel: $channel');
|
||||
|
||||
final channelSkipKey = 'skip_ci_$channel';
|
||||
final channelSkipList = pubspecYaml[channelSkipKey] as YamlList?;
|
||||
if (channelSkipList != null) {
|
||||
print('Applying skips for channel "$channel": $channelSkipList');
|
||||
}
|
||||
|
||||
// pub workspace, only run 'get' once
|
||||
await _runCommand('flutter', ['pub', 'get'], workingDirectory: rootDir.path);
|
||||
|
||||
final packages = workspace
|
||||
.where((e) => skipCiList == null || !skipCiList.contains(e))
|
||||
.where((e) {
|
||||
if (skipCiList != null && skipCiList.contains(e)) return false;
|
||||
if (channelSkipList != null && channelSkipList.contains(e))
|
||||
return false;
|
||||
return true;
|
||||
})
|
||||
.map((e) => e.toString())
|
||||
.toList();
|
||||
|
||||
@@ -70,3 +91,23 @@ Future<void> _runCommand(
|
||||
exit(exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> _getFlutterChannel() async {
|
||||
try {
|
||||
final result = await Process.run('flutter', [
|
||||
'--version',
|
||||
'--machine',
|
||||
], runInShell: true);
|
||||
if (result.exitCode != 0) {
|
||||
print('Flutter version command failed with exit code ${result.exitCode}');
|
||||
print('Stdout: ${result.stdout}');
|
||||
print('Stderr: ${result.stderr}');
|
||||
return 'unknown';
|
||||
}
|
||||
final machineInfo = jsonDecode(result.stdout as String);
|
||||
return machineInfo['channel'] as String? ?? 'unknown';
|
||||
} catch (e) {
|
||||
print('Error detecting Flutter channel: $e');
|
||||
return 'unknown';
|
||||
}
|
||||
}
|
||||
|
||||
76
tool/clean_all.dart
Normal file
76
tool/clean_all.dart
Normal file
@@ -0,0 +1,76 @@
|
||||
import 'dart:io';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
/// Runs `flutter clean` in every package listed in the root pubspec.yaml
|
||||
/// workspace. Useful for clearing stale build artifacts after switching Flutter
|
||||
/// channels.
|
||||
Future<void> main() async {
|
||||
final rootDir = Directory.current;
|
||||
final pubspecFile = File(path.join(rootDir.path, 'pubspec.yaml'));
|
||||
final pubspecContent = await pubspecFile.readAsString();
|
||||
final pubspecYaml = loadYaml(pubspecContent);
|
||||
|
||||
final workspace = pubspecYaml['workspace'] as YamlList?;
|
||||
if (workspace == null) {
|
||||
print('No workspace found in pubspec.yaml');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
final flutterBin = _resolveFlutterBin();
|
||||
print('Using flutter: $flutterBin');
|
||||
|
||||
var cleaned = 0;
|
||||
var skipped = 0;
|
||||
|
||||
for (final entry in workspace) {
|
||||
final package = entry.toString();
|
||||
final packagePath = path.join(rootDir.path, package);
|
||||
|
||||
// Only clean packages that have a pubspec.yaml (i.e. are Flutter/Dart pkgs)
|
||||
final pubspec = File(path.join(packagePath, 'pubspec.yaml'));
|
||||
if (!await pubspec.exists()) {
|
||||
print('-- Skipping \'$package\' (no pubspec.yaml found)');
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
print('== Cleaning \'$package\' ==');
|
||||
final process = await Process.start(
|
||||
flutterBin,
|
||||
['clean'],
|
||||
workingDirectory: packagePath,
|
||||
runInShell: true,
|
||||
mode: ProcessStartMode.inheritStdio,
|
||||
);
|
||||
final exitCode = await process.exitCode;
|
||||
if (exitCode != 0) {
|
||||
print(
|
||||
'Warning: flutter clean failed with exit code $exitCode in $packagePath',
|
||||
);
|
||||
} else {
|
||||
cleaned++;
|
||||
}
|
||||
}
|
||||
|
||||
print('');
|
||||
print('Done. Cleaned $cleaned package(s), skipped $skipped.');
|
||||
}
|
||||
|
||||
/// Resolves the path to the `flutter` binary by finding it relative to the
|
||||
/// running Dart SDK. Falls back to 'flutter' (uses PATH) if not found.
|
||||
String _resolveFlutterBin() {
|
||||
// Platform.resolvedExecutable points to the dart binary, e.g.:
|
||||
// /path/to/flutter/bin/cache/dart-sdk/bin/dart
|
||||
// Flutter binary is at /path/to/flutter/bin/flutter
|
||||
final dartBin = File(Platform.resolvedExecutable);
|
||||
final flutterBin = path.join(
|
||||
dartBin.parent.parent.parent.parent.path,
|
||||
'bin',
|
||||
'flutter',
|
||||
);
|
||||
if (File(flutterBin).existsSync()) {
|
||||
return flutterBin;
|
||||
}
|
||||
return 'flutter'; // fallback to PATH
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
DIR="${BASH_SOURCE%/*}"
|
||||
source "$DIR/flutter_ci_script_shared.sh"
|
||||
|
||||
flutter doctor -v
|
||||
|
||||
declare -ar PROJECT_NAMES=(
|
||||
"add_to_app/android_view/flutter_module_using_plugin"
|
||||
"add_to_app/books/flutter_module_books"
|
||||
"add_to_app/fullscreen/flutter_module"
|
||||
"add_to_app/multiple_flutters/multiple_flutters_module"
|
||||
"add_to_app/plugin/flutter_module_using_plugin"
|
||||
"add_to_app/prebuilt_module/flutter_module"
|
||||
"analysis_defaults"
|
||||
"android_splash_screen"
|
||||
"animations"
|
||||
"asset_transformation"
|
||||
"background_isolate_channels"
|
||||
"code_sharing/client"
|
||||
"code_sharing/server"
|
||||
"code_sharing/shared"
|
||||
"compass_app/app"
|
||||
"compass_app/server"
|
||||
"context_menus"
|
||||
"deeplink_store_example"
|
||||
"desktop_photo_search/fluent_ui"
|
||||
"desktop_photo_search/material"
|
||||
"dynamic_theme"
|
||||
"flutter_maps_firestore"
|
||||
"form_app"
|
||||
"game_template"
|
||||
"google_maps"
|
||||
"infinite_list"
|
||||
"ios_app_clip"
|
||||
# TODO(ewindmill): replace deprecated activeColor with activeThumbColor in 3.33
|
||||
# "isolate_example"
|
||||
# TODO(ewindmill) - RadioGroup api changed.
|
||||
# "material_3_demo"
|
||||
"navigation_and_routing"
|
||||
# TODO(domesticmouse): Angle brackets will be interpreted as HTML.
|
||||
# "pedometer"
|
||||
"pedometer/example"
|
||||
"place_tracker"
|
||||
"platform_channels"
|
||||
"platform_design"
|
||||
"platform_view_swift"
|
||||
"provider_counter"
|
||||
"provider_shopper"
|
||||
"simple_shader"
|
||||
"simplistic_calculator"
|
||||
"simplistic_editor"
|
||||
"testing_app"
|
||||
"veggieseasons"
|
||||
"web_embedding/element_embedding_demo"
|
||||
)
|
||||
|
||||
ci_projects "beta" "${PROJECT_NAMES[@]}"
|
||||
|
||||
echo "-- Success --"
|
||||
@@ -1,65 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
DIR="${BASH_SOURCE%/*}"
|
||||
source "$DIR/flutter_ci_script_shared.sh"
|
||||
|
||||
flutter doctor -v
|
||||
|
||||
declare -ar PROJECT_NAMES=(
|
||||
"add_to_app/android_view/flutter_module_using_plugin"
|
||||
"add_to_app/books/flutter_module_books"
|
||||
"add_to_app/fullscreen/flutter_module"
|
||||
"add_to_app/multiple_flutters/multiple_flutters_module"
|
||||
"add_to_app/plugin/flutter_module_using_plugin"
|
||||
"add_to_app/prebuilt_module/flutter_module"
|
||||
"analysis_defaults"
|
||||
"android_splash_screen"
|
||||
"animations"
|
||||
"asset_transformation"
|
||||
"background_isolate_channels"
|
||||
"code_sharing/client"
|
||||
# TODO(ewindmill): The integration tests are failing
|
||||
# "code_sharing/server"
|
||||
"code_sharing/shared"
|
||||
"compass_app/app"
|
||||
# TODO(ewindmill): The integration tests are failing
|
||||
# "compass_app/server"
|
||||
"context_menus"
|
||||
"date_planner"
|
||||
"deeplink_store_example"
|
||||
"desktop_photo_search/fluent_ui"
|
||||
"desktop_photo_search/material"
|
||||
"dynamic_theme"
|
||||
"flutter_maps_firestore"
|
||||
"form_app"
|
||||
"game_template"
|
||||
"google_maps"
|
||||
"infinite_list"
|
||||
"ios_app_clip"
|
||||
# TODO(ewindmill): replace deprecated activeColor with activeThumbColor in 3.33
|
||||
# "isolate_example"
|
||||
# TODO(ewindmill) - RadioGroup api changed.
|
||||
# "material_3_demo"
|
||||
"navigation_and_routing"
|
||||
# TODO(domesticmouse): Angle brackets will be interpreted as HTML.
|
||||
# "pedometer"
|
||||
"pedometer/example"
|
||||
"place_tracker"
|
||||
"platform_channels"
|
||||
"platform_design"
|
||||
"platform_view_swift"
|
||||
"provider_counter"
|
||||
"provider_shopper"
|
||||
"simple_shader"
|
||||
"simplistic_calculator"
|
||||
"simplistic_editor"
|
||||
"testing_app"
|
||||
"veggieseasons"
|
||||
"web_embedding/element_embedding_demo"
|
||||
)
|
||||
|
||||
ci_projects "master" "${PROJECT_NAMES[@]}"
|
||||
|
||||
echo "-- Success --"
|
||||
@@ -1,33 +0,0 @@
|
||||
function ci_projects () {
|
||||
local channel="$1"
|
||||
|
||||
shift
|
||||
local arr=("$@")
|
||||
for PROJECT_NAME in "${arr[@]}"
|
||||
do
|
||||
echo "== Testing '${PROJECT_NAME}' on Flutter's $channel channel =="
|
||||
pushd "${PROJECT_NAME}"
|
||||
|
||||
# Grab packages.
|
||||
flutter pub get
|
||||
|
||||
# Run the analyzer to find any static analysis issues.
|
||||
dart analyze --fatal-infos --fatal-warnings
|
||||
|
||||
# Run the formatter on all the dart files to make sure everything's linted.
|
||||
dart format --output none .
|
||||
|
||||
# Run the actual tests.
|
||||
if [ -d "test" ]
|
||||
then
|
||||
if grep -q "flutter:" "pubspec.yaml"; then
|
||||
flutter test
|
||||
else
|
||||
# If the project is not a Flutter project, use the Dart CLI.
|
||||
dart test
|
||||
fi
|
||||
fi
|
||||
|
||||
popd
|
||||
done
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
DIR="${BASH_SOURCE%/*}"
|
||||
source "$DIR/flutter_ci_script_shared.sh"
|
||||
|
||||
flutter doctor -v
|
||||
|
||||
declare -ar PROJECT_NAMES=(
|
||||
"add_to_app/android_view/flutter_module_using_plugin"
|
||||
"add_to_app/books/flutter_module_books"
|
||||
"add_to_app/fullscreen/flutter_module"
|
||||
"add_to_app/multiple_flutters/multiple_flutters_module"
|
||||
"add_to_app/plugin/flutter_module_using_plugin"
|
||||
"add_to_app/prebuilt_module/flutter_module"
|
||||
"analysis_defaults"
|
||||
"android_splash_screen"
|
||||
"animations"
|
||||
"asset_transformation"
|
||||
"background_isolate_channels"
|
||||
"code_sharing/client"
|
||||
"code_sharing/server"
|
||||
"code_sharing/shared"
|
||||
"compass_app/app"
|
||||
"compass_app/server"
|
||||
"context_menus"
|
||||
"deeplink_store_example"
|
||||
"desktop_photo_search/fluent_ui"
|
||||
"desktop_photo_search/material"
|
||||
"dynamic_theme"
|
||||
"flutter_maps_firestore"
|
||||
"form_app"
|
||||
"game_template"
|
||||
"google_maps"
|
||||
"infinite_list"
|
||||
"ios_app_clip"
|
||||
"isolate_example"
|
||||
"material_3_demo"
|
||||
"platform_channels"
|
||||
"platform_design"
|
||||
"navigation_and_routing"
|
||||
"pedometer"
|
||||
"pedometer/example"
|
||||
"place_tracker"
|
||||
"platform_view_swift"
|
||||
"provider_counter"
|
||||
"provider_shopper"
|
||||
"simple_shader"
|
||||
"simplistic_calculator"
|
||||
"simplistic_editor"
|
||||
"testing_app"
|
||||
"veggieseasons"
|
||||
"web_embedding/element_embedding_demo"
|
||||
)
|
||||
|
||||
ci_projects "stable" "${PROJECT_NAMES[@]}"
|
||||
|
||||
echo "-- Success --"
|
||||
@@ -1,77 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
flutter doctor -v
|
||||
|
||||
declare -ar PROJECT_NAMES=(
|
||||
"add_to_app/android_view/flutter_module_using_plugin"
|
||||
"add_to_app/books/flutter_module_books"
|
||||
"add_to_app/fullscreen/flutter_module"
|
||||
"add_to_app/multiple_flutters/multiple_flutters_module"
|
||||
"add_to_app/plugin/flutter_module_using_plugin"
|
||||
"add_to_app/prebuilt_module/flutter_module"
|
||||
"ai_recipe_generation"
|
||||
"analysis_defaults"
|
||||
"android_splash_screen"
|
||||
"animations"
|
||||
"asset_transformation"
|
||||
"background_isolate_channels"
|
||||
"code_sharing/client"
|
||||
"code_sharing/server"
|
||||
"code_sharing/shared"
|
||||
"context_menus"
|
||||
"deeplink_store_example"
|
||||
"desktop_photo_search/fluent_ui"
|
||||
"desktop_photo_search/material"
|
||||
"dynamic_theme"
|
||||
"experimental/federated_plugin/federated_plugin"
|
||||
"experimental/federated_plugin/federated_plugin/example"
|
||||
"experimental/federated_plugin/federated_plugin_macos"
|
||||
"experimental/federated_plugin/federated_plugin_platform_interface"
|
||||
"experimental/federated_plugin/federated_plugin_web"
|
||||
"experimental/federated_plugin/federated_plugin_windows"
|
||||
"experimental/pedometer"
|
||||
"experimental/pedometer/example"
|
||||
"experimental/varfont_shader_puzzle"
|
||||
"experimental/web_dashboard"
|
||||
"flutter_maps_firestore"
|
||||
"form_app"
|
||||
"game_template"
|
||||
"google_maps"
|
||||
"infinite_list"
|
||||
"ios_app_clip"
|
||||
"isolate_example"
|
||||
"material_3_demo"
|
||||
"navigation_and_routing"
|
||||
"place_tracker"
|
||||
"platform_channels"
|
||||
"platform_design"
|
||||
"platform_view_swift"
|
||||
"provider_counter"
|
||||
"provider_shopper"
|
||||
"simple_shader"
|
||||
"simplistic_calculator"
|
||||
"simplistic_editor"
|
||||
"testing_app"
|
||||
"veggieseasons"
|
||||
"web_embedding/element_embedding_demo"
|
||||
)
|
||||
|
||||
echo "--- Running flutter clean and flutter pub get for each sample ---"
|
||||
|
||||
for PROJECT_NAME in "${PROJECT_NAMES[@]}"
|
||||
do
|
||||
echo "== Cleaning '${PROJECT_NAME}' with Flutter clean =="
|
||||
pushd "${PROJECT_NAME}"
|
||||
|
||||
# run `flutter clean` for project
|
||||
flutter clean
|
||||
|
||||
# Grab packages.
|
||||
flutter pub get
|
||||
|
||||
popd
|
||||
done
|
||||
|
||||
echo "--- Success ---"
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
scriptDirectory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
|
||||
# It seems federated_plugin_* isn't happy to run flutter pub upgrade
|
||||
for dir in `find "${scriptDirectory}/.." -name pubspec.yaml -exec dirname {} \; | grep -v federated_plugin | grep -v experimental | sort`
|
||||
do
|
||||
(
|
||||
cd $dir
|
||||
echo "Updating `pwd`"
|
||||
flutter pub upgrade
|
||||
flutter pub outdated
|
||||
)
|
||||
done
|
||||
Reference in New Issue
Block a user