Skip to content

Commit 2d9f4e8

Browse files
authored
ci: validate publish dry runs (#2161)
* draft script for checking publish * draft implementation * comment * trigger ci * Update workflow * Update workflow * Update workflow * Update workflow * revert example{ * Update workflow * Temporarily restrict drift for testing * Update pubspec.yaml * Update pubspec.yaml * Revert * Update analyze.yml * Update event_example.dart
1 parent 33af3d6 commit 2d9f4e8

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

.github/workflows/analyze.yml

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ jobs:
5151

5252
- run: dart doc --dry-run
5353

54+
- name: Run publish validation
55+
run: |
56+
dart pub get --directory ../scripts/publish_validation
57+
dart run ../scripts/publish_validation/bin/publish_validation.dart --executable ${{ inputs.sdk }}
58+
5459
package-analysis:
5560
# `axel-op/dart-package-analyzer` is using `flutter pub upgrade` instead of `get`,
5661
# which ignores pubspec.yaml `dependency_overrides`. Because of that, all `release/*` branches are failing,

scripts/publish_validation/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
An internal command-line application to validate publish.
2+
We temporarily need to use the `--skip-validation` flag in order to publish with backwards compatible WASM support.
3+
Since we now don't have validations in place, this validation tool will catch unexpected errors that might occur during dry runs.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:lints/recommended.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import 'dart:io';
2+
3+
import 'package:args/args.dart';
4+
5+
void main(List<String> arguments) async {
6+
final parser = ArgParser()
7+
..addOption(
8+
'executable',
9+
allowed: ['dart', 'flutter'],
10+
defaultsTo: 'dart',
11+
help: 'Specify the executable to use (dart or flutter)',
12+
);
13+
14+
ArgResults args;
15+
try {
16+
args = parser.parse(arguments);
17+
} on FormatException catch (e) {
18+
print('Error: ${e.message}');
19+
print('Usage: dart script.dart [--executable <dart|flutter>]');
20+
exit(1);
21+
}
22+
23+
final executable = args['executable'] as String;
24+
25+
final result = await Process.run(executable, ['pub', 'publish', '--dry-run']);
26+
final publishOutput = result.stderr as String;
27+
28+
if (publishOutput.contains('Found no `pubspec.yaml` file')) {
29+
print(publishOutput);
30+
exit(1);
31+
}
32+
33+
const expectedErrors = [
34+
'lib/src/integrations/connectivity/web_connectivity_provider.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`',
35+
'lib/src/event_processor/enricher/web_enricher_event_processor.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`',
36+
'lib/src/origin_web.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`',
37+
'lib/src/platform/_web_platform.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`'
38+
];
39+
40+
// So far the expected errors all start with `* line`
41+
final errorLines = publishOutput
42+
.split('\n')
43+
.where((line) => line.startsWith('* line'))
44+
.toList();
45+
46+
final unexpectedErrors = errorLines.where((errorLine) {
47+
return !expectedErrors
48+
.any((expectedError) => errorLine.contains(expectedError));
49+
}).toList();
50+
51+
if (unexpectedErrors.isEmpty) {
52+
print('Only expected errors found. Validation passed.');
53+
exit(0);
54+
} else {
55+
print('Unexpected errors found:');
56+
unexpectedErrors.forEach(print);
57+
exit(1);
58+
}
59+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: publish_validation
2+
description: Command-line application for validating publish dry runs.
3+
publish_to: none
4+
5+
environment:
6+
sdk: ^3.4.3
7+
8+
dependencies:
9+
args: ^2.5.0
10+
11+
dev_dependencies:
12+
lints: ^3.0.0
13+
test: ^1.24.0

0 commit comments

Comments
 (0)