diff --git a/.github/workflows/publishable.yml b/.github/workflows/publishable.yml deleted file mode 100644 index 1de8313a8..000000000 --- a/.github/workflows/publishable.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: Publishable - -on: - push: - branches: - - main - - '6.0.0' - paths: - - "**.md" - - "**.yaml" - - "**.yml" - pull_request: - branches: - - main - - '6.0.0' - paths: - - "**.md" - - "**.yaml" - - "**.yml" - -jobs: - publish-dry-run: - name: Publish dry-run with packages - runs-on: ubuntu-latest - strategy: - matrix: - directory: ["dio", "plugins/cookie_manager", "plugins/http2_adapter", "plugins/native_dio_adapter"] - steps: - - uses: actions/checkout@v3 - - name: "Check documents file size < 128kb" - working-directory: ${{ matrix.directory }} - run: | - limit_size=$(expr 128 \* 1024) # Maximum 128kb. - changelog_size=$(stat -c%s CHANGELOG.md) - echo "CHANGELOG.md file size: $changelog_size." - if [ $changelog_size -gt $limit_size ]; then - echo "CHANGELOG.md exceeded the maximum size: $changelog_size > $limit_size." - exit 1 - fi - readme_size=$(stat -c%s README.md) - echo "README.md file size: $readme_size." - if [ $readme_size -gt $limit_size ]; then - echo "README.md exceeded the maximum size: $readme_size > $limit_size." - exit 1 - fi - if [ -f README_ZH.md ]; then - readme_zh_size=$(stat -c%s README_ZH.md) - echo "README_ZH.md file size: $readme_zh_size." - if [ readme_zh_size -gt $limit_size ]; then - echo "README_ZH.md exceeded the maximum size: $readme_zh_size > $limit_size." - exit 1 - fi - fi - - uses: subosito/flutter-action@v2 - - run: | - if grep -q "flutter:" "${{ matrix.directory }}/pubspec.yaml"; then - flutter pub get - fi - - run: dart pub publish --dry-run - working-directory: ${{ matrix.directory }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b7170deaf..65ec0b16a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,4 +1,4 @@ -name: Tests +name: Verify packages abilities on: push: @@ -14,136 +14,50 @@ on: paths-ignore: - "**.md" -jobs: - format: - name: Check formatting - runs-on: ubuntu-latest - strategy: - matrix: - directory: [ - "dio", - "example", - "example_flutter_app", - "plugins/cookie_manager", - "plugins/http2_adapter", - "plugins/native_dio_adapter" - ] - defaults: - run: - working-directory: ${{ matrix.directory }} - steps: - - uses: actions/checkout@v3 - - uses: dart-lang/setup-dart@v1.3 - with: - sdk: stable - - run: dart format --set-exit-if-changed . - - analyze: - needs: format - name: Analyze Dart-only libraries - runs-on: ubuntu-latest - strategy: - matrix: - directory: ["dio", "example", "plugins/cookie_manager", "plugins/http2_adapter"] - defaults: - run: - working-directory: ${{ matrix.directory }} - steps: - - uses: actions/checkout@v3 - - name: Prepare Dart SDK - uses: dart-lang/setup-dart@v1.3 - with: - sdk: stable - - name: Analyze - run: dart pub get && dart analyze --fatal-infos - - analyze_flutter: - needs: format - name: Analyze Flutter libraries - runs-on: ubuntu-latest - strategy: - matrix: - directory: ["example_flutter_app", "plugins/native_dio_adapter"] - defaults: - run: - working-directory: ${{ matrix.directory }} - steps: - - uses: actions/checkout@v3 - - name: Prepare Flutter SDK - uses: subosito/flutter-action@v2.8.0 - with: - cache: true - channel: stable - - name: Analyze - run: flutter pub get && flutter analyze --fatal-infos +defaults: + run: + shell: bash -leo pipefail {0} - test_dio: - needs: [analyze, analyze_flutter] - name: Run unit tests with dio - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - sdk: [ 2.15.0, stable, beta ] - platform: [ vm, chrome, firefox ] - steps: - - uses: actions/checkout@v3 - - uses: dart-lang/setup-dart@v1.3 - with: - sdk: ${{ matrix.sdk }} - - run: | - chmod +x ./scripts/prepare_pinning_certs.sh - ./scripts/prepare_pinning_certs.sh - shell: bash - - run: dart pub get - working-directory: dio - - run: dart test --chain-stack-traces --platform=${{ matrix.platform }} - working-directory: dio - - test_plugins: - needs: [analyze, analyze_flutter] - name: Run unit tests with plugins +jobs: + workflows: runs-on: ubuntu-latest strategy: fail-fast: false matrix: - sdk: [ 2.15.0, stable, beta ] - directory: ["plugins/cookie_manager", "plugins/http2_adapter"] + sdk: [ min, stable, beta ] steps: - uses: actions/checkout@v3 - - uses: dart-lang/setup-dart@v1.3 + - uses: subosito/flutter-action@v2.8.0 with: - sdk: ${{ matrix.sdk }} + cache: true + flutter-version: ${{ matrix.sdk == 'min' && '2.8.0' || '' }} + channel: ${{ matrix.sdk == 'min' && '' || matrix.channel }} - run: | chmod +x ./scripts/prepare_pinning_certs.sh ./scripts/prepare_pinning_certs.sh - shell: bash - - name: Install proxy - if: matrix.directory == 'plugins/http2_adapter' + - name: Install proxy for tests run: sudo apt-get install -y squid - run: dart pub get - working-directory: ${{ matrix.directory }} - - run: dart test --chain-stack-traces - working-directory: ${{ matrix.directory }} - - test_flutter_plugins: - needs: [analyze, analyze_flutter] - name: Run unit tests with Flutter plugins - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - channel: [ min, stable, beta ] - directory: ["plugins/native_dio_adapter"] - defaults: - run: - working-directory: ${{ matrix.directory }} - steps: - - uses: actions/checkout@v3 - - name: Prepare Flutter SDK - uses: subosito/flutter-action@v2.8.0 + - uses: bluefireteam/melos-action@v2 with: - cache: true - flutter-version: ${{ matrix.channel == 'min' && '3.13.0' || '' }} - channel: ${{ matrix.channel == 'min' && 'stable' || matrix.channel }} - - run: flutter test + run-bootstrap: false + - name: Patching files for Flutter ${{ matrix.sdk }} + run: dart ./scripts/files_patch.dart + - name: Check satisfied packages + run: | + dart ./scripts/melos_ignored_packages.dart + echo $(cat .melos_ignored_packages) >> ~/.bash_profile + - name: Bootstrap + run: melos bootstrap $(eval echo $IGNORED_PACKAGES) + - name: '[Verify step] Format' + run: melos exec $(eval echo $IGNORED_PACKAGES) -- "dart format --set-exit-if-changed ." + - name: '[Verify step] Analyze Dart packages' + run: melos exec $(eval echo $IGNORED_PACKAGES) --no-flutter -- "dart analyze --fatal-infos" + - name: '[Verify step] Analyze Flutter packages' + run: melos exec $(eval echo $IGNORED_PACKAGES) --flutter -- "flutter analyze --fatal-infos" + - name: '[Verify step] Publish dry-run' + run: melos exec $(eval echo $IGNORED_PACKAGES) --ignore="*example*" -- "dart pub publish --dry-run" + - name: '[Verify step] Test Dart packages' + run: melos exec $(eval echo $IGNORED_PACKAGES) --ignore="*example*" --no-flutter -- "dart test --chain-stack-traces --platform=vm,chrome,firefox" + - name: '[Verify step] Test Flutter packages' + run: melos exec $(eval echo $IGNORED_PACKAGES) --ignore="*example*" --flutter -- "flutter test" diff --git a/.gitignore b/.gitignore index 335cd5440..13c027fcd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ .example/flutter.png build/ # Remove the following pattern if you wish to check in your lock file -**/pubspec.lock +pubspec.lock # Directory created by dartdoc doc/api/ @@ -41,6 +41,7 @@ plugins/http2_adapter/test/*_pinning.txt # Miscellaneous .DS_Store +.melos*packages # IDEA configurations /.idea/* diff --git a/analysis_options.yaml b/analysis_options.yaml index 3d5d84dd2..d424278a9 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -2,11 +2,12 @@ include: package:lints/recommended.yaml analyzer: errors: + deprecated_member_use_from_same_package: ignore todo: ignore linter: rules: - - prefer_final_locals - - prefer_final_in_for_each - - prefer_single_quotes - - unnecessary_parenthesis + prefer_final_locals: true + prefer_final_in_for_each: true + prefer_single_quotes: true + unnecessary_parenthesis: true diff --git a/example/pubspec.yaml b/example/pubspec.yaml index f890bc2a9..99aee5c6a 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -23,4 +23,3 @@ dependency_overrides: dev_dependencies: lints: any - test: ^1.22.1 diff --git a/example/test/example_test.dart b/example/test/example_test.dart deleted file mode 100644 index 34727d53a..000000000 --- a/example/test/example_test.dart +++ /dev/null @@ -1,31 +0,0 @@ -// ignore_for_file: unused_import - -import 'package:dio_example/adapter.dart'; -import 'package:dio_example/cancel_request.dart'; -import 'package:dio_example/cookie_mgr.dart'; -import 'package:dio_example/custom_cache_interceptor.dart'; -import 'package:dio_example/dio.dart'; -import 'package:dio_example/download.dart'; -import 'package:dio_example/download_with_trunks.dart'; -import 'package:dio_example/extend_dio.dart'; -import 'package:dio_example/formdata.dart'; -import 'package:dio_example/generic.dart'; -import 'package:dio_example/http2_adapter.dart'; -import 'package:dio_example/options.dart'; -import 'package:dio_example/post_stream_and_bytes.dart'; -import 'package:dio_example/proxy.dart'; -import 'package:dio_example/queue_interceptors.dart'; -import 'package:dio_example/queued_interceptor_crsftoken.dart'; -import 'package:dio_example/request_interceptors.dart'; -import 'package:dio_example/response_interceptor.dart'; -import 'package:dio_example/test.dart'; -import 'package:dio_example/transformer.dart'; -import 'package:test/test.dart'; - -/// This test ensures that all examples are included in the compilation unit -/// and have no compile errors during integration builds. -/// -/// Otherwise this does nothing. -void main() { - test('dummy', () {}); -} diff --git a/example_flutter_app/pubspec.yaml b/example_flutter_app/pubspec.yaml index ef0043ef0..082705494 100644 --- a/example_flutter_app/pubspec.yaml +++ b/example_flutter_app/pubspec.yaml @@ -30,8 +30,6 @@ dependencies: cupertino_icons: ^1.0.2 dev_dependencies: - flutter_test: - sdk: flutter lints: any # For information on the generic Dart part of this file, see the diff --git a/example_flutter_app/test/widget_test.dart b/example_flutter_app/test/widget_test.dart deleted file mode 100644 index cac60cf17..000000000 --- a/example_flutter_app/test/widget_test.dart +++ /dev/null @@ -1,30 +0,0 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility that Flutter provides. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:dio_flutter_example/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -} diff --git a/melos.yaml b/melos.yaml index 455278743..87bed215c 100644 --- a/melos.yaml +++ b/melos.yaml @@ -10,3 +10,7 @@ ide: intellij: enabled: true moduleNamePrefix: '' + +command: + bootstrap: + runPubGetInParallel: false diff --git a/plugins/cookie_manager/test/basic_test.dart b/plugins/cookie_manager/test/basic_test.dart index 41a98c83e..f1fb69ff6 100644 --- a/plugins/cookie_manager/test/basic_test.dart +++ b/plugins/cookie_manager/test/basic_test.dart @@ -1,3 +1,4 @@ +@TestOn('vm') import 'package:cookie_jar/cookie_jar.dart'; import 'package:dio/dio.dart'; import 'package:dio_cookie_manager/dio_cookie_manager.dart'; diff --git a/plugins/cookie_manager/test/cookies_persistance_test.dart b/plugins/cookie_manager/test/cookies_persistance_test.dart index 2ab50e13d..97fd3a1e3 100644 --- a/plugins/cookie_manager/test/cookies_persistance_test.dart +++ b/plugins/cookie_manager/test/cookies_persistance_test.dart @@ -1,3 +1,4 @@ +@TestOn('vm') import 'dart:collection'; import 'dart:convert'; import 'dart:io'; diff --git a/plugins/cookie_manager/test/cookies_test.dart b/plugins/cookie_manager/test/cookies_test.dart index 6915bc49d..931c12a72 100644 --- a/plugins/cookie_manager/test/cookies_test.dart +++ b/plugins/cookie_manager/test/cookies_test.dart @@ -1,3 +1,4 @@ +@TestOn('vm') import 'dart:io'; import 'dart:typed_data'; diff --git a/plugins/http2_adapter/test/http2_test.dart b/plugins/http2_adapter/test/http2_test.dart index bbe69fb0d..656788912 100644 --- a/plugins/http2_adapter/test/http2_test.dart +++ b/plugins/http2_adapter/test/http2_test.dart @@ -1,3 +1,4 @@ +@TestOn('vm') import 'package:dio/dio.dart'; import 'package:dio_http2_adapter/dio_http2_adapter.dart'; import 'package:test/test.dart'; diff --git a/plugins/native_dio_adapter/CHANGELOG.md b/plugins/native_dio_adapter/CHANGELOG.md index 15d87dd49..db9a05ede 100644 --- a/plugins/native_dio_adapter/CHANGELOG.md +++ b/plugins/native_dio_adapter/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -*None.* +- Adds the missing `flutter` dependency. ## 1.1.0 diff --git a/plugins/native_dio_adapter/pubspec.yaml b/plugins/native_dio_adapter/pubspec.yaml index 30bbc6247..56c245cf7 100644 --- a/plugins/native_dio_adapter/pubspec.yaml +++ b/plugins/native_dio_adapter/pubspec.yaml @@ -13,10 +13,13 @@ 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: + sdk: flutter + dio: ^5.2.0 cupertino_http: ^1.0.0 cronet_http: ^0.4.0 diff --git a/pubspec.yaml b/pubspec.yaml index a7e72fd53..b3184f3db 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,8 +3,11 @@ publish_to: 'none' repository: https://github.com/cfug/dio environment: - sdk: '>=2.16.0 <4.0.0' + sdk: '>=2.15.0 <4.0.0' dev_dependencies: lints: any - melos: ^3.1.0 + melos: any + cli_util: any # Required by custom melos command. + pub_semver: any # Required by custom melos command. + yaml: any # Required by custom melos command. diff --git a/scripts/files_patch.dart b/scripts/files_patch.dart new file mode 100644 index 000000000..973f899da --- /dev/null +++ b/scripts/files_patch.dart @@ -0,0 +1,33 @@ +import 'dart:io'; + +void main() { + final v = RegExp(r'(\d*\.\d*)\.\d*').firstMatch(Platform.version)!.group(1)!; + final patches = patchesForVersions[v]; + if (patches != null && patches.isNotEmpty) { + print('Found file patches for Dart $v.'); + for (final patch in patches) { + print('Applying patch for ${patch.path}'); + final before = File(patch.path).readAsStringSync(); + final after = before.replaceAll(patch.before, patch.after); + File(patch.path).writeAsStringSync(after); + } + } +} + +class Patch { + const Patch(this.path, this.before, this.after); + + final String path; + final String before; + final String after; +} + +final patchesForVersions = >{ + '2.15': [ + Patch( + 'dio/lib/src/adapters/io_adapter.dart', + ' this.onHttpClientCreate', + ' this.onHttpClientCreate', + ), + ], +}; diff --git a/scripts/melos_ignored_packages.dart b/scripts/melos_ignored_packages.dart new file mode 100644 index 000000000..595781cfd --- /dev/null +++ b/scripts/melos_ignored_packages.dart @@ -0,0 +1,56 @@ +import 'dart:io'; + +import 'package:cli_util/cli_logging.dart' show Logger; +import 'package:melos/melos.dart' + show MelosLogger, MelosWorkspace, MelosWorkspaceConfig; +import 'package:pub_semver/pub_semver.dart'; +import 'package:yaml/yaml.dart'; + +void main() async { + final root = + Platform.environment['MELOS_ROOT_PATH'] ?? Directory.current.path; + final config = MelosWorkspaceConfig.fromYaml( + loadYamlNode( + File('$root/melos.yaml').readAsStringSync(), + ).toPlainObject() as Map, + path: root, + ); + final workspace = await MelosWorkspace.fromConfig( + config, + logger: MelosLogger(Logger.standard()), + ); + final packages = workspace.filteredPackages.values; + final current = Version.parse( + RegExp(r'\d*\.\d*\.\d*').firstMatch(Platform.version)!.group(0)!, + ); + final ignoredPackages = packages + .where((e) => !e.pubSpec.environment!.sdkConstraint!.allows(current)) + .map((e) => e.name); + File('$root/.melos_ignored_packages').writeAsStringSync( + 'IGNORED_PACKAGES=' + "'${ignoredPackages.map((e) => '--ignore="$e"').join(' ')}'", + ); +} + +extension YamlUtils on YamlNode { + /// Converts a YAML node to a regular mutable Dart object. + Object? toPlainObject() { + final node = this; + if (node is YamlScalar) { + return node.value; + } + if (node is YamlMap) { + return { + for (final entry in node.nodes.entries) + (entry.key as YamlNode).toPlainObject(): entry.value.toPlainObject(), + }; + } + if (node is YamlList) { + return node.nodes.map((node) => node.toPlainObject()).toList(); + } + throw FormatException( + 'Unsupported YAML node type encountered: ${node.runtimeType}', + this, + ); + } +}