From 2d9f4e87d88c40c80f2a3ee1e54adfc620bb9be3 Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Mon, 15 Jul 2024 11:05:17 +0200 Subject: [PATCH] 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 --- .github/workflows/analyze.yml | 5 ++ scripts/publish_validation/README.md | 3 + .../publish_validation/analysis_options.yaml | 1 + .../bin/publish_validation.dart | 59 +++++++++++++++++++ scripts/publish_validation/pubspec.yaml | 13 ++++ 5 files changed, 81 insertions(+) create mode 100644 scripts/publish_validation/README.md create mode 100644 scripts/publish_validation/analysis_options.yaml create mode 100644 scripts/publish_validation/bin/publish_validation.dart create mode 100644 scripts/publish_validation/pubspec.yaml diff --git a/.github/workflows/analyze.yml b/.github/workflows/analyze.yml index 5ae2d469a1..11a9afa61c 100644 --- a/.github/workflows/analyze.yml +++ b/.github/workflows/analyze.yml @@ -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, diff --git a/scripts/publish_validation/README.md b/scripts/publish_validation/README.md new file mode 100644 index 0000000000..e87d94c86d --- /dev/null +++ b/scripts/publish_validation/README.md @@ -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. \ No newline at end of file diff --git a/scripts/publish_validation/analysis_options.yaml b/scripts/publish_validation/analysis_options.yaml new file mode 100644 index 0000000000..572dd239d0 --- /dev/null +++ b/scripts/publish_validation/analysis_options.yaml @@ -0,0 +1 @@ +include: package:lints/recommended.yaml diff --git a/scripts/publish_validation/bin/publish_validation.dart b/scripts/publish_validation/bin/publish_validation.dart new file mode 100644 index 0000000000..ab871e910e --- /dev/null +++ b/scripts/publish_validation/bin/publish_validation.dart @@ -0,0 +1,59 @@ +import 'dart:io'; + +import 'package:args/args.dart'; + +void main(List 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 ]'); + 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); + } +} diff --git a/scripts/publish_validation/pubspec.yaml b/scripts/publish_validation/pubspec.yaml new file mode 100644 index 0000000000..a8dd96a670 --- /dev/null +++ b/scripts/publish_validation/pubspec.yaml @@ -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