Gitea CI / Check code and tests (push) Successful in 7m38s
Gitea CI / Build Android APK (push) Successful in 6m20s
Gitea CI / Audit and package Windows x64 (push) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (push) Canceled after 0s
Gitea CI / Gitea CI passed (push) Canceled after 0s
Gitea CI / Build Windows x64 app (push) Canceled after 14m42s
94 lines
2.5 KiB
Dart
94 lines
2.5 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:crypto/crypto.dart';
|
|
|
|
import 'support/dart_executable.dart';
|
|
|
|
const _generatedFiles = [
|
|
':(glob)lib/**/*.g.dart',
|
|
':(glob)lib/**/*.freezed.dart',
|
|
':(glob)test/**/*.g.dart',
|
|
':(glob)test/**/*.freezed.dart',
|
|
];
|
|
|
|
void main() {
|
|
test('workspace generated code is up to date', () async {
|
|
await _expectNoUntrackedGeneratedFiles();
|
|
final before = await _generatedContents();
|
|
final dart = flutterTestDartExecutable();
|
|
for (final directory in _generatorRoots()) {
|
|
final result = await Process.run(dart, [
|
|
'run',
|
|
'build_runner',
|
|
'build',
|
|
], workingDirectory: directory);
|
|
expect(
|
|
result.exitCode,
|
|
0,
|
|
reason: '$directory\n${result.stdout}\n${result.stderr}',
|
|
);
|
|
}
|
|
expect(
|
|
await _generatedContents(),
|
|
before,
|
|
reason: 'Generated files changed. Run dart run build_runner build and review the output.',
|
|
);
|
|
await _expectNoUntrackedGeneratedFiles();
|
|
}, timeout: const Timeout(Duration(minutes: 5)));
|
|
}
|
|
|
|
Future<void> _expectNoUntrackedGeneratedFiles() async {
|
|
final result = await Process.run('git', [
|
|
'ls-files',
|
|
'--others',
|
|
'--',
|
|
..._generatedFiles,
|
|
]);
|
|
expect(result.exitCode, 0, reason: '${result.stderr}');
|
|
expect(
|
|
(result.stdout as String).trim(),
|
|
isEmpty,
|
|
reason: 'Generate and track the .g.dart and .freezed.dart files in Git.',
|
|
);
|
|
}
|
|
|
|
Future<Map<String, String>> _generatedContents() async {
|
|
final contents = <String, String>{};
|
|
for (final root in [
|
|
for (final directory in _generatorRoots()) ...[
|
|
'$directory/lib',
|
|
'$directory/test',
|
|
],
|
|
]) {
|
|
if (!Directory(root).existsSync()) continue;
|
|
await for (final entity in Directory(root).list(recursive: true)) {
|
|
if (entity is File &&
|
|
(entity.path.endsWith('.g.dart') ||
|
|
entity.path.endsWith('.freezed.dart'))) {
|
|
contents[entity.path] = sha256
|
|
.convert(
|
|
utf8.encode(
|
|
(await entity.readAsString()).replaceAll('\r\n', '\n'),
|
|
),
|
|
)
|
|
.toString();
|
|
}
|
|
}
|
|
}
|
|
return contents;
|
|
}
|
|
|
|
Iterable<String> _generatorRoots() sync* {
|
|
yield '.';
|
|
for (final directory in Directory(
|
|
'packages',
|
|
).listSync().whereType<Directory>()) {
|
|
final manifest = File('${directory.path}/pubspec.yaml').readAsStringSync();
|
|
if (RegExp(r'^ build_runner:', multiLine: true).hasMatch(manifest)) {
|
|
yield directory.path;
|
|
}
|
|
}
|
|
}
|