From 755974c89387fbc039ac86245992dc8cc2c813e2 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Thu, 2 Nov 2023 12:30:43 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Add=20SDK=20satisfaction=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- melos.yaml | 6 ++++-- plugins/native_dio_adapter/pubspec.yaml | 4 ++-- pubspec.yaml | 1 + scripts/sdk_satisfaction.dart | 22 ++++++++++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 scripts/sdk_satisfaction.dart diff --git a/melos.yaml b/melos.yaml index 42bb9a9f6..bc6eeca14 100644 --- a/melos.yaml +++ b/melos.yaml @@ -34,11 +34,13 @@ scripts: melos run test:flutter --no-select test:dart: - exec: dart test --chain-stack-traces --platform=vm,chrome,firefox + exec: dart run $MELOS_ROOT_PATH/scripts/sdk_satisfaction.dart && dart test --chain-stack-traces --platform=vm,chrome,firefox || exit 0 packageFilters: flutter: false + dirExists: 'test' test:flutter: - exec: flutter test + exec: dart run $MELOS_ROOT_PATH/scripts/sdk_satisfaction.dart && flutter test || exit 0 packageFilters: flutter: true + dirExists: 'test' diff --git a/plugins/native_dio_adapter/pubspec.yaml b/plugins/native_dio_adapter/pubspec.yaml index c85be5059..3d025f66e 100644 --- a/plugins/native_dio_adapter/pubspec.yaml +++ b/plugins/native_dio_adapter/pubspec.yaml @@ -13,8 +13,8 @@ repository: https://github.com/cfug/dio/blob/main/plugins/native_dio_adapter issue_tracker: https://github.com/cfug/dio/issues environment: - sdk: ">=3.1.0 <4.0.0" - flutter: ">=3.13.0" + sdk: '>=3.1.0 <4.0.0' + flutter: '>=3.13.0' dependencies: flutter: diff --git a/pubspec.yaml b/pubspec.yaml index a7e72fd53..ec172130a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,3 +8,4 @@ environment: dev_dependencies: lints: any melos: ^3.1.0 + pub_semver: ^2.1.0 diff --git a/scripts/sdk_satisfaction.dart b/scripts/sdk_satisfaction.dart new file mode 100644 index 000000000..acaed8e2c --- /dev/null +++ b/scripts/sdk_satisfaction.dart @@ -0,0 +1,22 @@ +import 'dart:io'; + +import 'package:pub_semver/pub_semver.dart'; + +void main() async { + final current = RegExp(r'\d.\d.\d') + .firstMatch(Process.runSync('dart', ['--version']).stdout as String)! + .group(0)!; + final min = RegExp('sdk: [\'"]>=(\\d*.\\d*.\\d*)') + .firstMatch(File('pubspec.yaml').readAsStringSync())! + .group(1)!; + stdout.writeln('${Directory.current.path}: [$current <=> $min]'); + if (Version.parse(current) >= Version.parse(min)) { + exit(0); + } else { + stdout.writeln( + 'Skip test for [${Platform.environment['MELOS_PACKAGE_NAME']}] ' + 'due to not satisfied SDK constraint.', + ); + exit(1); + } +}