Skip to content

Commit

Permalink
Merge pull request #18 from bamlab/feat/add-tests-on-ci
Browse files Browse the repository at this point in the history
Feat/add tests on ci
  • Loading branch information
giboin authored Jul 4, 2024
2 parents 096b68f + cbcac2e commit 6d44cb8
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 48 deletions.
1 change: 1 addition & 0 deletions .github/workflows/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FLUTTER_VERSION=3.22.2
66 changes: 66 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Pull request checks

on:
pull_request:
branches: [main]
workflow_call:

jobs:
analyze:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: 📚 Git Checkout
uses: actions/checkout@v4

- id: dotenv
uses: falti/[email protected]
with:
path: .github/workflows/.env

- name: 💙 Install Flutter
uses: subosito/[email protected]
with:
flutter-version: ${{ steps.dotenv.outputs.flutter_version }}
channel: "stable"
cache: true
cache-key: ${{ runner.os }}-flutter-${{ steps.dotenv.outputs.flutter_version }}
cache-path: ${{ runner.tool_cache }}/flutter-${{ steps.dotenv.outputs.flutter_version }}

- name: 🟠 Install Dependencies
uses: bluefireteam/melos-action@v1

- name: 🧐 Analyze
run: melos analyze

test-extensions:
needs: analyze
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: 📚 Git Checkout
uses: actions/checkout@v4

- id: dotenv
uses: falti/[email protected]
with:
path: .github/workflows/.env

- name: 💙 Install Flutter
uses: subosito/[email protected]
with:
flutter-version: ${{ steps.dotenv.outputs.flutter_version }}
channel: "stable"
cache: true
cache-key: ${{ runner.os }}-flutter-${{ steps.dotenv.outputs.flutter_version }}
cache-path: ${{ runner.tool_cache }}/flutter-${{ steps.dotenv.outputs.flutter_version }}

- name: 🟠 Install Dependencies
run: flutter pub get

- name: ✅ Run tests
run: flutter test --coverage --no-pub --test-randomize-ordering-seed random

- name: 💯 Check coverage
uses: VeryGoodOpenSource/very_good_coverage@v3
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
.dart_tool
.dart_tool
*coverage/
melos_riverpod_community_extensions.iml
*build/
.idea
47 changes: 47 additions & 0 deletions CONTRIBUTE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## How to Contribute 🤝

If you want to report a bug, suggest an enhancement, or contribute to this project, you can leave an issue or open a pull request. Here are some guidelines to help you get started:

- Be respectful and considerate when interacting with other contributors.
- If you want to report a bug, provide a detailed description of the bug, including the steps to reproduce it.
- Clearly describe the issue or enhancement you are reporting or suggesting.
- When opening a pull request, provide a clear and concise description of the changes you have made.
- Write meaningful commit messages that accurately describe the changes made in each commit.
- Make sure to run tests and ensure that all tests are passing before submitting a pull request.

## Running Tests 🧪

This project uses [melos][melos_link] for convenience scripts such as running tests and coverage. All of these scripts can be run from any directory in the project, and are defined in the root `melos.yaml` file.

To activate melos, run the following command:

```sh
dart pub global activate melos
```

After that, to run all unit tests:

```sh
melos test
```

To run all tests and generate coverage report:

```sh
melos test:cov
```

To view the generated coverage report using [lcov][lcov_link] in your browser, run:

```sh
melos open:cov
```

If you want to reproduce the CI analyze job locally, you can run:

```sh
melos analyze
```

[melos_link]: https://melos.invertase.dev/
[lcov_link]: https://github.com/linux-test-project/lcov
28 changes: 0 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,6 @@ dart pub add riverpods_community_extensions

---

## Continuous Integration 🤖

Riverpods Community Extensions comes with a built-in [GitHub Actions workflow][github_actions_link] powered by [Very Good Workflows][very_good_workflows_link] but you can also add your preferred CI/CD solution.

Out of the box, on each pull request and push, the CI `formats`, `lints`, and `tests` the code. This ensures the code remains consistent and behaves correctly as you add functionality or make changes. The project uses [Very Good Analysis][very_good_analysis_link] for a strict set of analysis options used by our team. Code coverage is enforced using the [Very Good Workflows][very_good_coverage_link].

---

## Running Tests 🧪

To run all unit tests:

```sh
dart pub global activate coverage 1.2.0
dart test --coverage=coverage
dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info
```

To view the generated coverage report you can use [lcov](https://github.com/linux-test-project/lcov).

```sh
# Generate Coverage Report
genhtml coverage/lcov.info -o coverage/

# Open Coverage Report
open coverage/index.html
```

[dart_install_link]: https://dart.dev/get-dart
[github_actions_link]: https://docs.github.com/en/actions/learn-github-actions
[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg
Expand Down
36 changes: 36 additions & 0 deletions melos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: riverpod_community_extensions

packages:
- .

scripts:
analyze:
exec: |
dart analyze . && \
dart format --set-exit-if-changed lib test
description: Run analyzer

test:
exec: flutter test --no-pub --test-randomize-ordering-seed random
description: Run tests
fix:
exec: |
dart fix . --apply && \
dart format lib test
description: Run fix
test:cov:
exec: |
rm -rf coverage && \
flutter test --coverage --no-pub --test-randomize-ordering-seed random && \
genhtml coverage/lcov.info -o coverage && \
coverde value -i coverage/lcov.info
description: Run test with coverage
test:cov:check:
exec: |
melos test:cov && \
coverde check 100 -i coverage/lcov.info
description: Check test coverage
open:cov:
exec: |
open coverage/index.html
description: Open test coverage
Loading

0 comments on commit 6d44cb8

Please sign in to comment.