Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement module-based code coverage thresholds #6

Merged
merged 1 commit into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
- name: Set up Melos
uses: bluefireteam/melos-action@v3

- name: Install tools
run: ./scripts/install_tools.sh

- name: Check for cyclic dependencies
run: |
set +e
Expand All @@ -50,8 +53,8 @@ jobs:
- name: Check formatting of Dart files
run: melos run format_check

- name: Run unit tests
run: melos run test_unit
- name: Run unit tests with coverage check
run: melos run test_unit_with_coverage

- name: Run golden tests
run: melos run test_golden
Expand Down Expand Up @@ -81,6 +84,9 @@ jobs:
- name: Set up Melos
uses: bluefireteam/melos-action@v3

- name: Install tools
run: ./scripts/install_tools.sh

- name: Check for cyclic dependencies
run: |
set +e
Expand Down Expand Up @@ -115,7 +121,7 @@ jobs:
run: melos run format_check

- name: Run unit tests with Git Diff using MELOS_PACKAGES
run: melos run test_unit
run: melos run test_unit_with_coverage

- name: Run golden tests with Git Diff using MELOS_PACKAGES
run: melos run test_golden
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ pubspec_overrides.yaml

# FVM Version Cache
.fvm/

coverage
6 changes: 3 additions & 3 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ scripts:

format_check: melos exec dart format . --set-exit-if-changed

test_unit_package:
run: melos exec flutter test --exclude-tags golden
test_unit_with_coverage_package:
run: melos exec MELOS_ROOT_PATH/scripts/test_with_coverage.sh --exclude-tags golden
packageFilters:
dirExists:
- test
Expand All @@ -57,7 +57,7 @@ scripts:
dirExists:
- test

test_unit: melos run test_unit_package --no-select
test_unit_with_coverage: melos run test_unit_with_coverage_package --no-select

test_unit_diff: melos run test_unit_package_diff --no-select

Expand Down
1 change: 1 addition & 0 deletions packages/domain/test/min_code_coverage.melos
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
100
1 change: 1 addition & 0 deletions packages/presentation/test/min_code_coverage.melos
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
40
2 changes: 2 additions & 0 deletions scripts/install_tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
dart pub global activate very_good_cli 0.22.2
47 changes: 47 additions & 0 deletions scripts/test_with_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh

# Default values
MIN_CODE_COVERAGE_FILE_PATH="$MELOS_PACKAGE_PATH/test/min_code_coverage.melos"
TAGS=""
EXCLUDE_TAGS=""
EXCLUDE_COVERAGE="**/*.g.dart"

# Parse named arguments
while [ "$1" != "" ]; do
case $1 in
--tags ) shift
TAGS=$1
;;
--exclude-tags ) shift
EXCLUDE_TAGS=$1
;;
--exclude-coverage ) shift
EXCLUDE_COVERAGE=$1
;;
* ) echo "Invalid argument: $1"
exit 1
esac
shift
done

if [ -f "$MIN_CODE_COVERAGE_FILE_PATH" ]; then
MIN_CODE_COVERAGE=$(cat "$MIN_CODE_COVERAGE_FILE_PATH")
else
MIN_CODE_COVERAGE=0
fi

echo "Min required code coverage for '$MELOS_PACKAGE_NAME' is $MIN_CODE_COVERAGE%"

# Construct the command with optional args
COMMAND="very_good test --coverage --no-optimization --exclude-coverage $EXCLUDE_COVERAGE --min-coverage $MIN_CODE_COVERAGE"

if [ -n "$TAGS" ]; then
COMMAND="$COMMAND --tags $TAGS"
fi

if [ -n "$EXCLUDE_TAGS" ]; then
COMMAND="$COMMAND --exclude-tags $EXCLUDE_TAGS"
fi

# Execute the command
eval $COMMAND