Skip to content

Commit d020224

Browse files
authored
Converge melos usage and CI scripts & add code coverage (#2136)
The idea of this PR is to make it easier to run tests locally based on melos while also adding code coverage reporting. * move all scripts to melos and make them available for usage locally * automatically generation coverage information for all Dart tests (vm, chrome, firefox) * print coverage results to CLI for stable SDK * only run analyze/format/publish on Stable SDK, this way we can skip the patching for format/analyze for older SDK versions which actually makes no sense since it is not being released I want to further extend the coverage reporting by using https://github.com/clearlyip/code-coverage-report-action. This action would run for each push/merge to the main branch an generate a constant coverage baseline for the main branch. The baseline is uploaded as workflow artifact and as such available to pull request which can then display the change in coverage. <!-- Write down your pull request descriptions. --> ### New Pull Request Checklist - [ ] I have read the [Documentation](https://pub.dev/documentation/dio/latest/) - [ ] I have searched for a similar pull request in the [project](https://github.com/cfug/dio/pulls) and found none - [ ] I have updated this branch with the latest `main` branch to avoid conflicts (via merge from master or rebase) - [ ] I have added the required tests to prove the fix/feature I'm adding - [ ] I have updated the documentation (if necessary) - [ ] I have run the tests without failures - [ ] I have updated the `CHANGELOG.md` in the corresponding package ### Additional context and info (if any) <!-- Provide more context and info about the PR. -->
1 parent 797145a commit d020224

File tree

19 files changed

+431
-201
lines changed

19 files changed

+431
-201
lines changed

.github/workflows/coverage_base.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: 'coverage_baseline'
2+
3+
# The code-coverage-report-action uses workflow artifacts to store the coverage report.
4+
# The action will upload the coverage report as an artifact,
5+
# and the action will also download the coverage report from the artifact in PRs.
6+
# The action will then compare the coverage report from the PR with the coverage report from the base branch.
7+
# For this to work, the action needs to be run on the base branch after each pushed commit
8+
# or at least once before the artifact retention period ends.
9+
10+
on:
11+
# Allow for manual runs
12+
workflow_dispatch:
13+
# Runs at 00:00, on day 1 of the month (every ~30 days)
14+
schedule:
15+
- cron: '0 0 1 * *'
16+
push:
17+
branches:
18+
- main
19+
20+
jobs:
21+
generate:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- uses: subosito/flutter-action@v2
26+
with:
27+
cache: true
28+
channel: stable
29+
- run: |
30+
chmod +x ./scripts/prepare_pinning_certs.sh
31+
./scripts/prepare_pinning_certs.sh
32+
- name: Install proxy for tests
33+
run: sudo apt-get update && sudo apt-get install -y squid
34+
- run: dart pub get
35+
- uses: bluefireteam/melos-action@v3
36+
- name: '[Verify step] Test Dart packages [VM]'
37+
run: melos run test:vm
38+
- name: '[Verify step] Test Dart packages [Chrome]'
39+
run: melos run test:web:chrome
40+
- name: '[Verify step] Test Dart packages [Firefox]'
41+
run: melos run test:web:firefox
42+
- name: '[Verify step] Test Flutter packages'
43+
run: melos run test:flutter
44+
- name: '[Coverage] Generate report'
45+
run: melos run coverage:combine
46+
- uses: clearlyip/code-coverage-report-action@v4
47+
with:
48+
filename: 'coverage/cobertura.xml'

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
if: github.event.issue.number == 1633
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414
with:
1515
token: ${{ secrets.CFUG_PUBLISHER }}
1616
- uses: dart-lang/[email protected]

.github/workflows/tests.yml

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ on:
1414
paths-ignore:
1515
- "**.md"
1616

17+
# Ensure that new pushes/updates cancel running jobs
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
20+
cancel-in-progress: true
21+
1722
defaults:
1823
run:
1924
shell: bash -leo pipefail {0}
@@ -25,9 +30,11 @@ jobs:
2530
fail-fast: false
2631
matrix:
2732
sdk: [ min, stable, beta ]
33+
env:
34+
TEST_PRESET: all
2835
steps:
29-
- uses: actions/checkout@v3
30-
- uses: subosito/flutter-action@v2.8.0
36+
- uses: actions/checkout@v4
37+
- uses: subosito/flutter-action@v2
3138
with:
3239
cache: true
3340
flutter-version: ${{ matrix.sdk == 'min' && '2.8.0' || '' }}
@@ -38,30 +45,38 @@ jobs:
3845
- name: Install proxy for tests
3946
run: sudo apt-get update && sudo apt-get install -y squid
4047
- run: dart pub get
41-
- uses: bluefireteam/melos-action@v2
48+
- uses: bluefireteam/melos-action@v3
4249
with:
4350
run-bootstrap: false
44-
- name: Patching files for Flutter ${{ matrix.sdk }}
45-
run: dart ./scripts/files_patch.dart
4651
- name: Check satisfied packages
4752
run: |
48-
dart ./scripts/melos_ignored_packages.dart
49-
echo $(cat .melos_ignored_packages) >> ~/.bash_profile
50-
- name: Bootstrap
51-
run: melos bootstrap $(eval echo $IGNORED_PACKAGES)
53+
dart ./scripts/melos_packages.dart
54+
echo $(cat .melos_packages) >> $GITHUB_ENV
55+
- name: Melos Bootstrap
56+
run: melos bootstrap
5257
- name: '[Verify step] Format'
53-
run: melos exec $(eval echo $IGNORED_PACKAGES) -- "dart format --set-exit-if-changed ."
54-
- name: '[Verify step] Analyze Dart packages'
55-
run: melos exec $(eval echo $IGNORED_PACKAGES) --no-flutter -- "dart analyze --fatal-infos"
56-
- name: '[Verify step] Analyze Flutter packages'
57-
run: melos exec $(eval echo $IGNORED_PACKAGES) --flutter -- "flutter analyze --fatal-infos"
58+
if: ${{ matrix.sdk == 'stable' }}
59+
run: melos run format
60+
- name: '[Verify step] Analyze packages'
61+
if: ${{ matrix.sdk == 'stable' }}
62+
run: melos run analyze
5863
- name: '[Verify step] Publish dry-run'
59-
run: melos exec $(eval echo $IGNORED_PACKAGES) --ignore="*example*" --ignore="dio_test" -- "dart pub publish --dry-run"
64+
if: ${{ matrix.sdk == 'stable' }}
65+
run: melos run publish-dry-run
6066
- name: '[Verify step] Test Dart packages [VM]'
61-
run: melos exec $(eval echo $IGNORED_PACKAGES) --ignore="*example*" --ignore="dio_test" --no-flutter -- "MELOS_ROOT_PATH/scripts/dart_test.sh --platform=vm"
67+
run: melos run test:vm
6268
- name: '[Verify step] Test Dart packages [Chrome]'
63-
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"
69+
run: melos run test:web:chrome
6470
- name: '[Verify step] Test Dart packages [Firefox]'
65-
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"
71+
run: melos run test:web:firefox
6672
- name: '[Verify step] Test Flutter packages'
67-
run: melos exec $(eval echo $IGNORED_PACKAGES) --ignore="*example*" --flutter -- "flutter test"
73+
run: melos run test:flutter
74+
- name: '[Coverage] Format & print test coverage'
75+
if: ${{ matrix.sdk == 'stable' }}
76+
run: melos run coverage:show
77+
- name: '[Coverage] Coverage Report'
78+
uses: clearlyip/code-coverage-report-action@v4
79+
if: ${{ matrix.sdk == 'stable' && github.actor != 'dependabot[bot]'}}
80+
with:
81+
artifact_download_workflow_names: 'tests,coverage_base'
82+
filename: 'coverage/cobertura.xml'

.gitignore

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,11 @@ pubspec_overrides.yaml
1212
doc/api/
1313
.cookies/
1414

15-
dio/.packages
16-
dio/.dart_tool/
17-
dio/.pub/
18-
dio/.idea/
19-
dio/.exampl
20-
dio/coverage
21-
22-
# plugins
23-
plugins/cookie_manager/.packages
24-
plugins/cookie_manager/.dart_tool/
25-
plugins/cookie_manager/.pub/
26-
plugins/cookie_manager/.idea/
27-
plugins/cookie_manager/.exampl
28-
29-
plugins/http2_adapter/.packages
30-
plugins/http2_adapter/.dart_tool/
31-
plugins/http2_adapter/.pub/
32-
plugins/http2_adapter/.idea/
33-
plugins/http2_adapter/.exampl
34-
plugins/http2_adapter/test/*_pinning.txt
35-
3615
.vscode/
3716

3817
# FVM
3918
.fvm
40-
.fmvrc
19+
.fvmrc
4120

4221
# Miscellaneous
4322
.DS_Store
@@ -47,3 +26,5 @@ plugins/http2_adapter/test/*_pinning.txt
4726
/.idea/*
4827
!/.idea/dio.iml
4928
!/.idea/modules.xml
29+
30+
coverage

CONTRIBUTING-ZH.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# 贡献指南
2+
3+
Language: [English](CONTRIBUTING.md) | 简体中文
4+
5+
首先,感谢您考虑为 `dio` 项目做出贡献!像这样的开源项目得以成长和繁荣,多亏了像您这样的贡献者。无论您是在修复错误、添加新功能、改进文档还是报告问题,每一份贡献都是宝贵和值得赞赏的。
6+
7+
本文档提供了一些指南,以帮助确保您的贡献尽可能有效。在提交您的贡献之前,请花一点时间阅读这些指南。
8+
9+
请记住,每个为这个项目做出贡献的人都需要遵循我们的行为准则。这有助于确保所有贡献者的积极和包容环境。
10+
11+
再次感谢您的贡献,我们期待看到您将为 `dio` 项目带来什么!
12+
13+
## 创建好的工单
14+
15+
> [!TIP]
16+
> 在创建新问题之前,搜索已有的工单和拉取请求以避免重复是一个好习惯。
17+
18+
### 错误报告
19+
20+
报告错误时,请包括以下信息:
21+
22+
1. **标题**:简短描述性的错误标题。
23+
2. ****:指定有问题的包。
24+
3. **版本**:您正在使用的包版本。
25+
4. **操作系统**:出现问题的操作系统。
26+
5. **适配器**:指定使用的适配器。
27+
6. **`flutter doctor -v` 的输出**:使用 Flutter 时需要。
28+
7. **Dart 版本**:您使用的 Dart 版本。
29+
8. **重现步骤**:详细步骤说明如何重现错误。
30+
9. **预期结果**:您期望发生的事情。
31+
10. **实际结果**:实际发生的事情。包括日志、屏幕截图或任何其他相关信息。
32+
33+
### 功能请求
34+
35+
请求新功能时,请包括以下信息:
36+
37+
1. **标题**:功能请求的简短描述性标题。
38+
2. **请求声明**:描述您认为 `dio` 项目能解决但目前没有解决的问题。
39+
3. **解决方案头脑风暴**:分享您的想法,关于如何解决问题。如果您没有特定的解决方案,那也没关系!
40+
41+
> [!TIP]
42+
> 记住,您提供的信息越多,我们就越容易理解和解决问题。感谢您的贡献!
43+
> 请避免评论旧的、已关闭的工单。如果旧问题似乎与您的问题有关但并未完全解决您的问题,最好开一个新工单并引用旧的。
44+
45+
## 开发
46+
47+
此项目使用 [Melos](https://github.com/invertase/melos) 管理单体仓库和大多数任务。Melos 是一个为 Dart 和 Flutter 的多包项目优化工作流的工具。有关如何使用 Melos 的更多信息,请参阅 [Melos 文档](https://melos.invertase.dev)
48+
49+
### 设置
50+
51+
开始之前,您需要全局安装 Melos:
52+
53+
```bash
54+
dart pub global activate melos
55+
```
56+
57+
在安装 Melos 后,可以克隆仓库并安装依赖项:
58+
59+
```bash
60+
git clone https://github.com/cfug/dio.git
61+
cd dio
62+
melos bootstrap
63+
```
64+
65+
## 提交更改
66+
67+
在以拉取请求提交您的更改之前,请确保格式化和分析您的代码并运行所有测试。以下是您应该了解的主要 melos 脚本:
68+
69+
### 代码质量
70+
71+
要格式化(和修复)所有包,请运行:
72+
```bash
73+
melos run format
74+
# 或者
75+
melos run format:fix
76+
```
77+
78+
要分析所有包,请运行:
79+
```bash
80+
melos run analyze
81+
```
82+
83+
### 测试
84+
85+
要运行所有测试,请使用:
86+
```bash
87+
melos run test
88+
```
89+
90+
可以使用适当的脚本运行单个测试目标:
91+
```bash
92+
melos run test:vm
93+
melos run test:web
94+
melos run test:web:chrome
95+
melos run test:web:firefox
96+
```

CONTRIBUTING.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Contributing Guidelines
2+
3+
Language: English | [简体中文](CONTRIBUTING-ZH.md)
4+
5+
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.
6+
7+
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.
8+
9+
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.
10+
11+
Thank you again for your contributions, and we look forward to seeing what you will bring to the `dio` project!
12+
13+
## Creating Good Tickets
14+
15+
> [!TIP]
16+
> Before creating a new issue, it's a good practice to search for open tickets and pull requests to avoid duplicates.
17+
18+
### Bug Reports
19+
20+
When reporting a bug, please include the following information:
21+
22+
1. **Title**: A brief, descriptive title for the bug.
23+
2. **Package**: Specify which package has the problem.
24+
3. **Version**: The version of the package you are using.
25+
4. **Operating System**: The OS on which the problem occurs.
26+
5. **Adapter**: Specify which adapter(s) are used.
27+
6. **Output of `flutter doctor -v`**: Required when used with Flutter.
28+
7. **Dart Version**: The version of Dart you are using.
29+
8. **Steps to Reproduce**: Detailed steps on how to reproduce the bug.
30+
9. **Expected Result**: What you expected to happen.
31+
10. **Actual Result**: What actually happened. Include logs, screenshots, or any other relevant information.
32+
33+
### Feature Requests
34+
35+
When requesting a new feature, please include the following information:
36+
37+
1. **Title**: A brief, descriptive title for the feature request.
38+
2. **Request Statement**: Describe the problem that you believe the `dio` project could solve but currently doesn't.
39+
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!
40+
41+
> [!TIP]
42+
> Remember, the more information you provide, the easier it is for us to understand and address the issue. Thank you for your contributions!
43+
> 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.
44+
45+
## Development
46+
47+
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).
48+
49+
50+
### Setup
51+
52+
To get started, you'll need to install Melos globally:
53+
54+
```bash
55+
dart pub global activate melos
56+
```
57+
58+
After installing Melos, you can clone the repository and install the dependencies:
59+
60+
```bash
61+
git clone https://github.com/cfug/dio.git
62+
cd dio
63+
melos bootstrap
64+
```
65+
66+
## Submitting changes
67+
68+
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:
69+
70+
### Code quality
71+
72+
To format (and fix) all packages, run:
73+
```bash
74+
melos run format
75+
# OR
76+
melos run format:fix
77+
```
78+
79+
To analyze all packages, run:
80+
```bash
81+
melos run analyze
82+
```
83+
84+
### Testing
85+
86+
To run all tests, use:
87+
```bash
88+
melos run test
89+
```
90+
91+
Individual test targets can be run with the appropriate scripts:
92+
```bash
93+
melos run test:vm
94+
melos run test:web
95+
melos run test:web:chrome
96+
melos run test:web:firefox
97+
```

dio/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ build/
3333

3434
# Project related.
3535
test/*_pinning.txt
36+
37+
coverage

dio/dart_test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ tags:
77
presets:
88
all:
99
skip: false
10+
default:
11+
skip: true
1012

1113
override_platforms:
1214
chrome:

0 commit comments

Comments
 (0)