diff --git a/.github/workflows/coverage_base.yml b/.github/workflows/coverage_base.yml new file mode 100644 index 000000000..9ff7d2312 --- /dev/null +++ b/.github/workflows/coverage_base.yml @@ -0,0 +1,48 @@ +name: 'coverage_baseline' + +# The code-coverage-report-action uses workflow artifacts to store the coverage report. +# The action will upload the coverage report as an artifact, +# and the action will also download the coverage report from the artifact in PRs. +# The action will then compare the coverage report from the PR with the coverage report from the base branch. +# For this to work, the action needs to be run on the base branch after each pushed commit +# or at least once before the artifact retention period ends. + +on: + # Allow for manual runs + workflow_dispatch: + # Runs at 00:00, on day 1 of the month (every ~30 days) + schedule: + - cron: '0 0 1 * *' + push: + branches: + - main + +jobs: + generate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: subosito/flutter-action@v2 + with: + cache: true + channel: stable + - run: | + chmod +x ./scripts/prepare_pinning_certs.sh + ./scripts/prepare_pinning_certs.sh + - name: Install proxy for tests + run: sudo apt-get update && sudo apt-get install -y squid + - run: dart pub get + - uses: bluefireteam/melos-action@v3 + - name: '[Verify step] Test Dart packages [VM]' + run: melos run test:vm + - name: '[Verify step] Test Dart packages [Chrome]' + run: melos run test:web:chrome + - name: '[Verify step] Test Dart packages [Firefox]' + run: melos run test:web:firefox + - name: '[Verify step] Test Flutter packages' + run: melos run test:flutter + - name: '[Coverage] Generate report' + run: melos run coverage:combine + - uses: clearlyip/code-coverage-report-action@v4 + with: + filename: 'coverage/cobertura.xml' diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6a3b63504..2a56f4ee5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,7 +10,7 @@ jobs: if: github.event.issue.number == 1633 runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: token: ${{ secrets.CFUG_PUBLISHER }} - uses: dart-lang/setup-dart@v1.3 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index eb0482c90..8fabf94fe 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,6 +14,11 @@ on: paths-ignore: - "**.md" +# Ensure that new pushes/updates cancel running jobs +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + defaults: run: shell: bash -leo pipefail {0} @@ -25,9 +30,11 @@ jobs: fail-fast: false matrix: sdk: [ min, stable, beta ] + env: + TEST_PRESET: all steps: - - uses: actions/checkout@v3 - - uses: subosito/flutter-action@v2.8.0 + - uses: actions/checkout@v4 + - uses: subosito/flutter-action@v2 with: cache: true flutter-version: ${{ matrix.sdk == 'min' && '2.8.0' || '' }} @@ -38,30 +45,38 @@ jobs: - name: Install proxy for tests run: sudo apt-get update && sudo apt-get install -y squid - run: dart pub get - - uses: bluefireteam/melos-action@v2 + - uses: bluefireteam/melos-action@v3 with: 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) + dart ./scripts/melos_packages.dart + echo $(cat .melos_packages) >> $GITHUB_ENV + - name: Melos Bootstrap + run: melos bootstrap - 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" + if: ${{ matrix.sdk == 'stable' }} + run: melos run format + - name: '[Verify step] Analyze packages' + if: ${{ matrix.sdk == 'stable' }} + run: melos run analyze - name: '[Verify step] Publish dry-run' - run: melos exec $(eval echo $IGNORED_PACKAGES) --ignore="*example*" --ignore="dio_test" -- "dart pub publish --dry-run" + if: ${{ matrix.sdk == 'stable' }} + run: melos run publish-dry-run - name: '[Verify step] Test Dart packages [VM]' - run: melos exec $(eval echo $IGNORED_PACKAGES) --ignore="*example*" --ignore="dio_test" --no-flutter -- "MELOS_ROOT_PATH/scripts/dart_test.sh --platform=vm" + run: melos run test:vm - name: '[Verify step] Test Dart packages [Chrome]' - run: melos exec $(eval echo $IGNORED_PACKAGES) --ignore="*example*" --ignore="*http2*" --ignore="dio_test" --no-flutter -- "MELOS_ROOT_PATH/scripts/dart_test.sh --platform=chrome" + run: melos run test:web:chrome - name: '[Verify step] Test Dart packages [Firefox]' - run: melos exec $(eval echo $IGNORED_PACKAGES) --ignore="*example*" --ignore="*http2*" --ignore="dio_test" --no-flutter -- "MELOS_ROOT_PATH/scripts/dart_test.sh --platform=firefox" + run: melos run test:web:firefox - name: '[Verify step] Test Flutter packages' - run: melos exec $(eval echo $IGNORED_PACKAGES) --ignore="*example*" --flutter -- "flutter test" + run: melos run test:flutter + - name: '[Coverage] Format & print test coverage' + if: ${{ matrix.sdk == 'stable' }} + run: melos run coverage:show + - name: '[Coverage] Coverage Report' + uses: clearlyip/code-coverage-report-action@v4 + if: ${{ matrix.sdk == 'stable' && github.actor != 'dependabot[bot]'}} + with: + artifact_download_workflow_names: 'tests,coverage_base' + filename: 'coverage/cobertura.xml' diff --git a/.gitignore b/.gitignore index e3d4391c7..43efb4a52 100644 --- a/.gitignore +++ b/.gitignore @@ -12,32 +12,11 @@ pubspec_overrides.yaml doc/api/ .cookies/ -dio/.packages -dio/.dart_tool/ -dio/.pub/ -dio/.idea/ -dio/.exampl -dio/coverage - -# plugins -plugins/cookie_manager/.packages -plugins/cookie_manager/.dart_tool/ -plugins/cookie_manager/.pub/ -plugins/cookie_manager/.idea/ -plugins/cookie_manager/.exampl - -plugins/http2_adapter/.packages -plugins/http2_adapter/.dart_tool/ -plugins/http2_adapter/.pub/ -plugins/http2_adapter/.idea/ -plugins/http2_adapter/.exampl -plugins/http2_adapter/test/*_pinning.txt - .vscode/ # FVM .fvm -.fmvrc +.fvmrc # Miscellaneous .DS_Store @@ -47,3 +26,5 @@ plugins/http2_adapter/test/*_pinning.txt /.idea/* !/.idea/dio.iml !/.idea/modules.xml + +coverage diff --git a/CONTRIBUTING-ZH.md b/CONTRIBUTING-ZH.md new file mode 100644 index 000000000..daa3f683f --- /dev/null +++ b/CONTRIBUTING-ZH.md @@ -0,0 +1,96 @@ +# 贡献指南 + +Language: [English](CONTRIBUTING.md) | 简体中文 + +首先,感谢您考虑为 `dio` 项目做出贡献!像这样的开源项目得以成长和繁荣,多亏了像您这样的贡献者。无论您是在修复错误、添加新功能、改进文档还是报告问题,每一份贡献都是宝贵和值得赞赏的。 + +本文档提供了一些指南,以帮助确保您的贡献尽可能有效。在提交您的贡献之前,请花一点时间阅读这些指南。 + +请记住,每个为这个项目做出贡献的人都需要遵循我们的行为准则。这有助于确保所有贡献者的积极和包容环境。 + +再次感谢您的贡献,我们期待看到您将为 `dio` 项目带来什么! + +## 创建好的工单 + +> [!TIP] +> 在创建新问题之前,搜索已有的工单和拉取请求以避免重复是一个好习惯。 + +### 错误报告 + +报告错误时,请包括以下信息: + +1. **标题**:简短描述性的错误标题。 +2. **包**:指定有问题的包。 +3. **版本**:您正在使用的包版本。 +4. **操作系统**:出现问题的操作系统。 +5. **适配器**:指定使用的适配器。 +6. **`flutter doctor -v` 的输出**:使用 Flutter 时需要。 +7. **Dart 版本**:您使用的 Dart 版本。 +8. **重现步骤**:详细步骤说明如何重现错误。 +9. **预期结果**:您期望发生的事情。 +10. **实际结果**:实际发生的事情。包括日志、屏幕截图或任何其他相关信息。 + +### 功能请求 + +请求新功能时,请包括以下信息: + +1. **标题**:功能请求的简短描述性标题。 +2. **请求声明**:描述您认为 `dio` 项目能解决但目前没有解决的问题。 +3. **解决方案头脑风暴**:分享您的想法,关于如何解决问题。如果您没有特定的解决方案,那也没关系! + +> [!TIP] +> 记住,您提供的信息越多,我们就越容易理解和解决问题。感谢您的贡献! +> 请避免评论旧的、已关闭的工单。如果旧问题似乎与您的问题有关但并未完全解决您的问题,最好开一个新工单并引用旧的。 + +## 开发 + +此项目使用 [Melos](https://github.com/invertase/melos) 管理单体仓库和大多数任务。Melos 是一个为 Dart 和 Flutter 的多包项目优化工作流的工具。有关如何使用 Melos 的更多信息,请参阅 [Melos 文档](https://melos.invertase.dev)。 + +### 设置 + +开始之前,您需要全局安装 Melos: + +```bash +dart pub global activate melos +``` + +在安装 Melos 后,可以克隆仓库并安装依赖项: + +```bash +git clone https://github.com/cfug/dio.git +cd dio +melos bootstrap +``` + +## 提交更改 + +在以拉取请求提交您的更改之前,请确保格式化和分析您的代码并运行所有测试。以下是您应该了解的主要 melos 脚本: + +### 代码质量 + +要格式化(和修复)所有包,请运行: +```bash +melos run format +# 或者 +melos run format:fix +``` + +要分析所有包,请运行: +```bash +melos run analyze +``` + +### 测试 + +要运行所有测试,请使用: +```bash +melos run test +``` + +可以使用适当的脚本运行单个测试目标: +```bash +melos run test:vm +melos run test:web +melos run test:web:chrome +melos run test:web:firefox +``` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..241d6e791 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,97 @@ +# Contributing Guidelines + +Language: English | [简体中文](CONTRIBUTING-ZH.md) + +First of all, thank you for considering contributing to the `dio` project! Open source projects like this one grow and thrive thanks to the contributions from people like you. Whether you're fixing bugs, adding new features, improving the documentation, or even reporting issues, every contribution is valuable and appreciated. + +This document provides some guidelines to help ensure that your contributions are as effective as possible. Please take a moment to read through these guidelines before submitting your contribution. + +Remember, everyone contributing to this project is expected to follow our code of conduct. This helps ensure a positive and inclusive environment for all contributors. + +Thank you again for your contributions, and we look forward to seeing what you will bring to the `dio` project! + +## Creating Good Tickets + +> [!TIP] +> Before creating a new issue, it's a good practice to search for open tickets and pull requests to avoid duplicates. + +### Bug Reports + +When reporting a bug, please include the following information: + +1. **Title**: A brief, descriptive title for the bug. +2. **Package**: Specify which package has the problem. +3. **Version**: The version of the package you are using. +4. **Operating System**: The OS on which the problem occurs. +5. **Adapter**: Specify which adapter(s) are used. +6. **Output of `flutter doctor -v`**: Required when used with Flutter. +7. **Dart Version**: The version of Dart you are using. +8. **Steps to Reproduce**: Detailed steps on how to reproduce the bug. +9. **Expected Result**: What you expected to happen. +10. **Actual Result**: What actually happened. Include logs, screenshots, or any other relevant information. + +### Feature Requests + +When requesting a new feature, please include the following information: + +1. **Title**: A brief, descriptive title for the feature request. +2. **Request Statement**: Describe the problem that you believe the `dio` project could solve but currently doesn't. +3. **Solution Brainstorm**: Share your ideas on how the problem could be solved. If you don't have a specific solution in mind, that's okay too! + +> [!TIP] +> Remember, the more information you provide, the easier it is for us to understand and address the issue. Thank you for your contributions! +> Please refrain from commenting on old, closed tickets. If an old issue seems related but doesn't fully address your problem, it's best to open a new ticket and reference the old one instead. + +## Development + +This project uses [Melos](https://github.com/invertase/melos) to manage the mono-repo and most tasks. Melos is a tool that optimizes the workflow for multi-package Dart and Flutter projects. For more information on how to use Melos, please refer to the [Melos documentation](https://melos.invertase.dev). + + +### Setup + +To get started, you'll need to install Melos globally: + +```bash +dart pub global activate melos +``` + +After installing Melos, you can clone the repository and install the dependencies: + +```bash +git clone https://github.com/cfug/dio.git +cd dio +melos bootstrap +``` + +## Submitting changes + +Before submitting your changes as a pull request, please make sure to format and analyze your and run the all tests. Here are the main melos scripts you should be aware of: + +### Code quality + +To format (and fix) all packages, run: +```bash +melos run format +# OR +melos run format:fix +``` + +To analyze all packages, run: +```bash +melos run analyze +``` + +### Testing + +To run all tests, use: +```bash +melos run test +``` + +Individual test targets can be run with the appropriate scripts: +```bash +melos run test:vm +melos run test:web +melos run test:web:chrome +melos run test:web:firefox +``` diff --git a/dio/.gitignore b/dio/.gitignore index 9b76a7f71..45c92d6b1 100644 --- a/dio/.gitignore +++ b/dio/.gitignore @@ -33,3 +33,5 @@ build/ # Project related. test/*_pinning.txt + +coverage diff --git a/dio/dart_test.yaml b/dio/dart_test.yaml index 52cfb59fa..4e6cd51e3 100644 --- a/dio/dart_test.yaml +++ b/dio/dart_test.yaml @@ -7,6 +7,8 @@ tags: presets: all: skip: false + default: + skip: true override_platforms: chrome: diff --git a/melos.yaml b/melos.yaml index 390924fd0..da6a60073 100644 --- a/melos.yaml +++ b/melos.yaml @@ -16,3 +16,126 @@ ide: command: bootstrap: runPubGetInParallel: false + clean: + hooks: + post: | + # Clean all flutter projects + melos exec --flutter -- "flutter clean" + # Clean coverage files + rm -rf coverage + rm -rf pubspec.lock + melos exec --dir-exists coverage -- "rm -rf coverage" + +scripts: + analyze: + description: Analyze all packages + exec: dart analyze --fatal-infos + format: + description: Format check all packages + exec: dart format --set-exit-if-changed . + format:fix: + description: Format all packages + exec: dart format . + publish-dry-run: + description: Publish dry-run all packages + exec: dart pub publish --dry-run + packageFilters: + noPrivate: true + test: + name: All tests + run: | + melos run test:vm + TEST_PLATFORM=chrome melos run test:web + TEST_PLATFORM=firefox melos run test:web + melos run test:flutter + test:vm: + name: Dart VM tests + exec: dart test --preset ${TEST_PRESET:-default} --coverage coverage/vm --chain-stack-traces + packageFilters: + flutter: false + dirExists: test + # Old syntax for melos <= 2.9.0 - this can be removed once we bump the minimum Dart SDK. + select-package: + flutter: false + dir-exists: test + ignore: + - 'dio_compatibility_layer' + - 'dio_http2_adapter' + test:web: + name: Dart Web tests + run: | + melos run test:web:chrome + melos run test:web:firefox + test:web:chrome: + name: Dart Web tests in chrome + run: melos run test:web:single + env: + TEST_PLATFORM: chrome + test:web:firefox: + name: Dart Web tests in firefox + run: melos run test:web:single + env: + TEST_PLATFORM: firefox + test:web:single: + name: Dart Web tests in a browser + exec: dart test --platform ${TEST_PLATFORM} --coverage coverage/${TEST_PLATFORM} --preset ${TEST_PRESET:-default} --chain-stack-traces + packageFilters: + flutter: false + dirExists: test + ignore: + - '*http2*' + - '*cookie*' + # Old syntax for melos <= 2.9.0 - this can be removed once we bump the minimum Dart SDK. + select-package: + flutter: false + dir-exists: test + ignore: + - 'dio_compatibility_layer' + - '*http2*' + - '*cookie*' + test:flutter: + name: Flutter tests + exec: flutter test --coverage + packageFilters: + flutter: true + dirExists: test + ignore: + - '*example*' + # Old syntax for melos <= 2.9.0 - this can be removed once we bump the minimum Dart SDK. + # There is no packages to run on min SDK for this command. + select-package: + flutter: true + dir-exists: test + ignore: + - '*' + test:coverage: + name: Run all tests and display coverage + run: | + melos run test + melos run coverage:format + melos run coverage:show + coverage:format: + name: Format coverage + run: | + dart pub global activate coverage + melos run coverage:format:package + coverage:format:package: + name: Format coverage for each package + exec: dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info --report-on=lib + packageFilters: + flutter: false + dirExists: coverage + coverage:combine: + name: Combine & convert coverage report + run: | + rm -rf coverage + dart pub global activate combine_coverage + dart pub global activate cobertura + melos run coverage:format + dart pub global run combine_coverage --repo-path=$pwd + dart pub global run cobertura convert --pubspec dio/pubspec.yaml + coverage:show: + name: Show coverage report + run: | + melos run coverage:combine + dart pub global run cobertura show diff --git a/plugins/compatibility_layer/.gitignore b/plugins/compatibility_layer/.gitignore index 3cceda557..7cbf61702 100644 --- a/plugins/compatibility_layer/.gitignore +++ b/plugins/compatibility_layer/.gitignore @@ -5,3 +5,5 @@ # Avoid committing pubspec.lock for library packages; see # https://dart.dev/guides/libraries/private-files#pubspeclock. pubspec.lock + +coverage diff --git a/plugins/compatibility_layer/dart_test.yaml b/plugins/compatibility_layer/dart_test.yaml index dbc48f42c..454e43c22 100644 --- a/plugins/compatibility_layer/dart_test.yaml +++ b/plugins/compatibility_layer/dart_test.yaml @@ -1,6 +1,7 @@ presets: - # empty placeholder required in CI scripts + # empty placeholders required in CI scripts all: + default: override_platforms: chrome: diff --git a/plugins/cookie_manager/.gitignore b/plugins/cookie_manager/.gitignore index 54bb7b7a9..e2d3f95cc 100644 --- a/plugins/cookie_manager/.gitignore +++ b/plugins/cookie_manager/.gitignore @@ -28,45 +28,4 @@ .pub/ build/ -# Android related -**/android/**/gradle-wrapper.jar -**/android/.gradle -**/android/captures/ -**/android/gradlew -**/android/gradlew.bat -**/android/local.properties -**/android/**/GeneratedPluginRegistrant.java - -# iOS/XCode related -**/ios/**/*.mode1v3 -**/ios/**/*.mode2v3 -**/ios/**/*.moved-aside -**/ios/**/*.pbxuser -**/ios/**/*.perspectivev3 -**/ios/**/*sync/ -**/ios/**/.sconsign.dblite -**/ios/**/.tags* -**/ios/**/.vagrant/ -**/ios/**/DerivedData/ -**/ios/**/Icon? -**/ios/**/Pods/ -**/ios/**/.symlinks/ -**/ios/**/profile -**/ios/**/xcuserdata -**/ios/.generated/ -**/ios/Flutter/App.framework -**/ios/Flutter/Flutter.framework -**/ios/Flutter/Generated.xcconfig -**/ios/Flutter/app.flx -**/ios/Flutter/app.zip -**/ios/Flutter/flutter_assets/ -**/ios/Flutter/flutter_export_environment.sh -**/ios/ServiceDefinitions.json -**/ios/Runner/GeneratedPluginRegistrant.* - -# Exceptions to above rules. -!**/ios/**/default.mode1v3 -!**/ios/**/default.mode2v3 -!**/ios/**/default.pbxuser -!**/ios/**/default.perspectivev3 -!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages +coverage diff --git a/plugins/cookie_manager/dart_test.yaml b/plugins/cookie_manager/dart_test.yaml index 6633e2f9e..e8a1dc06d 100644 --- a/plugins/cookie_manager/dart_test.yaml +++ b/plugins/cookie_manager/dart_test.yaml @@ -2,5 +2,6 @@ file_reporters: json: build/reports/test-results.json presets: - # empty placeholder required in CI scripts + # empty placeholders required in CI scripts all: + default: diff --git a/plugins/http2_adapter/.gitignore b/plugins/http2_adapter/.gitignore index 870a7de62..c7707906d 100644 --- a/plugins/http2_adapter/.gitignore +++ b/plugins/http2_adapter/.gitignore @@ -28,47 +28,6 @@ .pub/ build/ -# Android related -**/android/**/gradle-wrapper.jar -**/android/.gradle -**/android/captures/ -**/android/gradlew -**/android/gradlew.bat -**/android/local.properties -**/android/**/GeneratedPluginRegistrant.java - -# iOS/XCode related -**/ios/**/*.mode1v3 -**/ios/**/*.mode2v3 -**/ios/**/*.moved-aside -**/ios/**/*.pbxuser -**/ios/**/*.perspectivev3 -**/ios/**/*sync/ -**/ios/**/.sconsign.dblite -**/ios/**/.tags* -**/ios/**/.vagrant/ -**/ios/**/DerivedData/ -**/ios/**/Icon? -**/ios/**/Pods/ -**/ios/**/.symlinks/ -**/ios/**/profile -**/ios/**/xcuserdata -**/ios/.generated/ -**/ios/Flutter/App.framework -**/ios/Flutter/Flutter.framework -**/ios/Flutter/Generated.xcconfig -**/ios/Flutter/app.flx -**/ios/Flutter/app.zip -**/ios/Flutter/flutter_assets/ -**/ios/Flutter/flutter_export_environment.sh -**/ios/ServiceDefinitions.json -**/ios/Runner/GeneratedPluginRegistrant.* - -# Exceptions to above rules. -!**/ios/**/default.mode1v3 -!**/ios/**/default.mode2v3 -!**/ios/**/default.pbxuser -!**/ios/**/default.perspectivev3 -!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages +coverage test/_pinning_http2.txt diff --git a/plugins/http2_adapter/dart_test.yaml b/plugins/http2_adapter/dart_test.yaml index 6b6bceba3..5e49832eb 100644 --- a/plugins/http2_adapter/dart_test.yaml +++ b/plugins/http2_adapter/dart_test.yaml @@ -7,8 +7,12 @@ tags: presets: all: skip: false + default: + skip: true proxy: skip: "Skipping proxy test with specific setup requirements by default. Use '-P all' to run all tests." presets: all: skip: false + default: + skip: true diff --git a/plugins/native_dio_adapter/.gitignore b/plugins/native_dio_adapter/.gitignore index 9fecad6d2..c312a3d6b 100644 --- a/plugins/native_dio_adapter/.gitignore +++ b/plugins/native_dio_adapter/.gitignore @@ -18,3 +18,5 @@ # https://dart.dev/guides/libraries/private-files#pubspeclock. pubspec.lock .DS_Store + +coverage diff --git a/scripts/dart_test.sh b/scripts/dart_test.sh deleted file mode 100755 index e5e9c201b..000000000 --- a/scripts/dart_test.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/bash - -while [[ "$1" == -* ]]; do - case "$1" in - --platform=*) PLATFORM="${1#*=}"; shift;; - --help|-h) echo "" - echo "Run Dart tests on the specific platform." - echo "" - echo "Usage: $(basename $0) [options]" - echo "" - echo " --platform Run tests on the specific platform" - echo " -h, --help Print this usage information" - echo ""; - exit 0;; - *) echo "Unrecognized option: $1. Use --help for usage."; exit 0;; - esac -done - -if [ -z "$PLATFORM" ]; then - echo "--platform is required." - exit 1 -fi - -dart test --chain-stack-traces --platform="$PLATFORM" -P all - -exit_code=$? - -## Escape 79 which means no tests run on the specific platform. -if [ $exit_code -eq 79 ]; then - exit 0 -else - exit $exit_code -fi diff --git a/scripts/files_patch.dart b/scripts/files_patch.dart deleted file mode 100644 index 973f899da..000000000 --- a/scripts/files_patch.dart +++ /dev/null @@ -1,33 +0,0 @@ -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_packages.dart similarity index 72% rename from scripts/melos_ignored_packages.dart rename to scripts/melos_packages.dart index 595781cfd..423b38a0a 100644 --- a/scripts/melos_ignored_packages.dart +++ b/scripts/melos_packages.dart @@ -6,6 +6,10 @@ import 'package:melos/melos.dart' import 'package:pub_semver/pub_semver.dart'; import 'package:yaml/yaml.dart'; +/// Writes a `.melos_packages` file to the root of the workspace with the +/// packages that are compatible with the current Dart SDK version. +/// This is useful for CI scripts that need to know which packages to run +/// melos for using the `MELOS_PACKAGES` environment variable. void main() async { final root = Platform.environment['MELOS_ROOT_PATH'] ?? Directory.current.path; @@ -23,13 +27,13 @@ void main() async { 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(' ')}'", - ); + final String validPackages = packages + .where((e) => e.pubSpec.environment!.sdkConstraint!.allows(current)) + .map((e) => e.name) + .join(','); + + File('$root/.melos_packages') + .writeAsStringSync('MELOS_PACKAGES=$validPackages'); } extension YamlUtils on YamlNode {