mirror of
https://github.com/flutter/samples.git
synced 2026-04-16 20:12:15 +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';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user