|
| 1 | +import 'package:args/args.dart'; |
| 2 | +import 'package:file/local.dart'; |
| 3 | +import 'package:flutter_symbol_collector/flutter_symbol_collector.dart'; |
| 4 | +import 'package:github/github.dart'; |
| 5 | +import 'package:logging/logging.dart'; |
| 6 | + |
| 7 | +const githubToken = String.fromEnvironment('GITHUB_TOKEN'); |
| 8 | +final githubAuth = githubToken.isEmpty |
| 9 | + ? Authentication.anonymous() |
| 10 | + : Authentication.withToken(githubToken); |
| 11 | +final source = FlutterSymbolSource(githubAuth: githubAuth); |
| 12 | +final fs = LocalFileSystem(); |
| 13 | +final tempDir = fs.currentDirectory.childDirectory('.temp'); |
| 14 | +final stateCache = |
| 15 | + DirectoryStatusCache(fs.currentDirectory.childDirectory('.cache')); |
| 16 | +late final SymbolCollectorCli collector; |
| 17 | + |
| 18 | +void main(List<String> arguments) async { |
| 19 | + Logger.root.level = Level.ALL; |
| 20 | + Logger.root.onRecord.listen((record) { |
| 21 | + print('${record.level.name}: ${record.time}: ${record.message}' |
| 22 | + '${record.error == null ? '' : ': ${record.error}'}'); |
| 23 | + }); |
| 24 | + |
| 25 | + final parser = ArgParser()..addOption('version', defaultsTo: ''); |
| 26 | + final args = parser.parse(arguments); |
| 27 | + final argVersion = args['version'] as String; |
| 28 | + |
| 29 | + collector = await SymbolCollectorCli.setup(tempDir); |
| 30 | + |
| 31 | + // If a specific version was given, run just for this version. |
| 32 | + if (argVersion.isNotEmpty && |
| 33 | + !argVersion.contains('*') && |
| 34 | + argVersion.split('.').length == 3) { |
| 35 | + Logger.root.info('Running for a single flutter version: $argVersion'); |
| 36 | + await processFlutterVersion(FlutterVersion(argVersion)); |
| 37 | + } else { |
| 38 | + // Otherwise, walk all the versions and run for the matching ones. |
| 39 | + final versionRegex = RegExp(argVersion.isEmpty |
| 40 | + ? '.*' |
| 41 | + : '^${argVersion.replaceAll('.', '\\.').replaceAll('*', '.+')}\$'); |
| 42 | + Logger.root.info('Running for all Flutter versions matching $versionRegex'); |
| 43 | + final versions = await source |
| 44 | + .listFlutterVersions() |
| 45 | + .where((v) => !v.isPreRelease) |
| 46 | + .where((v) => versionRegex.hasMatch(v.tagName)) |
| 47 | + .toList(); |
| 48 | + Logger.root.info( |
| 49 | + 'Found ${versions.length} Flutter versions matching $versionRegex'); |
| 50 | + for (var version in versions) { |
| 51 | + await processFlutterVersion(version); |
| 52 | + } |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +Future<void> processFlutterVersion(FlutterVersion version) async { |
| 57 | + if (bool.hasEnvironment('CI')) { |
| 58 | + print('::group::Processing Flutter ${version.tagName}'); |
| 59 | + } |
| 60 | + Logger.root.info('Processing Flutter ${version.tagName}'); |
| 61 | + Logger.root.info('Engine version: ${await version.engineVersion}'); |
| 62 | + |
| 63 | + final archives = await source.listSymbolArchives(version); |
| 64 | + final dir = tempDir.childDirectory(version.tagName); |
| 65 | + for (final archive in archives) { |
| 66 | + final status = await stateCache.getStatus(archive); |
| 67 | + if (status == SymbolArchiveStatus.success) { |
| 68 | + Logger.root |
| 69 | + .info('Skipping ${archive.path} - already processed successfully'); |
| 70 | + continue; |
| 71 | + } |
| 72 | + |
| 73 | + final archiveDir = dir.childDirectory(archive.platform.operatingSystem); |
| 74 | + try { |
| 75 | + if (await source.downloadAndExtractTo(archiveDir, archive.path)) { |
| 76 | + if (await collector.upload(archiveDir, archive.platform, version)) { |
| 77 | + await stateCache.setStatus(archive, SymbolArchiveStatus.success); |
| 78 | + continue; |
| 79 | + } |
| 80 | + } |
| 81 | + await stateCache.setStatus(archive, SymbolArchiveStatus.error); |
| 82 | + } finally { |
| 83 | + if (await archiveDir.exists()) { |
| 84 | + await archiveDir.delete(recursive: true); |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + if (await dir.exists()) { |
| 90 | + await dir.delete(recursive: true); |
| 91 | + } |
| 92 | + |
| 93 | + if (bool.hasEnvironment('CI')) { |
| 94 | + print('::endgroup::'); |
| 95 | + } |
| 96 | +} |
0 commit comments