Skip to content

Commit

Permalink
ci: validate publish dry runs (#2161)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
buenaflor authored Jul 15, 2024
1 parent 33af3d6 commit 2d9f4e8
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ jobs:

- run: dart doc --dry-run

- name: Run publish validation
run: |
dart pub get --directory ../scripts/publish_validation
dart run ../scripts/publish_validation/bin/publish_validation.dart --executable ${{ inputs.sdk }}
package-analysis:
# `axel-op/dart-package-analyzer` is using `flutter pub upgrade` instead of `get`,
# which ignores pubspec.yaml `dependency_overrides`. Because of that, all `release/*` branches are failing,
Expand Down
3 changes: 3 additions & 0 deletions scripts/publish_validation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
An internal command-line application to validate publish.
We temporarily need to use the `--skip-validation` flag in order to publish with backwards compatible WASM support.
Since we now don't have validations in place, this validation tool will catch unexpected errors that might occur during dry runs.
1 change: 1 addition & 0 deletions scripts/publish_validation/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:lints/recommended.yaml
59 changes: 59 additions & 0 deletions scripts/publish_validation/bin/publish_validation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import 'dart:io';

import 'package:args/args.dart';

void main(List<String> arguments) async {
final parser = ArgParser()
..addOption(
'executable',
allowed: ['dart', 'flutter'],
defaultsTo: 'dart',
help: 'Specify the executable to use (dart or flutter)',
);

ArgResults args;
try {
args = parser.parse(arguments);
} on FormatException catch (e) {
print('Error: ${e.message}');
print('Usage: dart script.dart [--executable <dart|flutter>]');
exit(1);
}

final executable = args['executable'] as String;

final result = await Process.run(executable, ['pub', 'publish', '--dry-run']);
final publishOutput = result.stderr as String;

if (publishOutput.contains('Found no `pubspec.yaml` file')) {
print(publishOutput);
exit(1);
}

const expectedErrors = [
'lib/src/integrations/connectivity/web_connectivity_provider.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`',
'lib/src/event_processor/enricher/web_enricher_event_processor.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`',
'lib/src/origin_web.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`',
'lib/src/platform/_web_platform.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`'
];

// So far the expected errors all start with `* line`
final errorLines = publishOutput
.split('\n')
.where((line) => line.startsWith('* line'))
.toList();

final unexpectedErrors = errorLines.where((errorLine) {
return !expectedErrors
.any((expectedError) => errorLine.contains(expectedError));
}).toList();

if (unexpectedErrors.isEmpty) {
print('Only expected errors found. Validation passed.');
exit(0);
} else {
print('Unexpected errors found:');
unexpectedErrors.forEach(print);
exit(1);
}
}
13 changes: 13 additions & 0 deletions scripts/publish_validation/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: publish_validation
description: Command-line application for validating publish dry runs.
publish_to: none

environment:
sdk: ^3.4.3

dependencies:
args: ^2.5.0

dev_dependencies:
lints: ^3.0.0
test: ^1.24.0

0 comments on commit 2d9f4e8

Please sign in to comment.