From 5c9295c954bbc4ed51e87b5f0e770181d73deee4 Mon Sep 17 00:00:00 2001 From: Ellet Date: Sat, 18 Jan 2025 23:06:51 +0300 Subject: [PATCH 1/6] chore: exclude generated pigeon files from code coverage calculation, coverage badge test --- .github/workflows/coverage-badge.yml | 40 ++++++++++++++++++++++++++++ lib/src/messages.g.dart | 1 + pigeons/messages.dart | 5 ++++ test/test_api.g.dart | 1 + 4 files changed, 47 insertions(+) create mode 100644 .github/workflows/coverage-badge.yml diff --git a/.github/workflows/coverage-badge.yml b/.github/workflows/coverage-badge.yml new file mode 100644 index 0000000..ccb138f --- /dev/null +++ b/.github/workflows/coverage-badge.yml @@ -0,0 +1,40 @@ +name: Create coverage badge + +on: + push: + branches: [main] + # TODO(EchoEllet): For testing only, remove + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Setup Flutter (Stable) + uses: subosito/flutter-action@v2 + with: + channel: stable + cache: true + + - name: Install Package Dependencies + run: flutter pub get + + - name: Collect coverage info + run: flutter test --coverage + + - name: Install lcov + run: sudo apt install -y lcov + + - name: Extract coverage percentage + id: coverage-extractor + run: | + percentage=$(lcov --summary coverage/lcov.info | grep 'lines' | awk '{print $2}' | sed 's/%//' | sed 's/.0$//') + echo "COVERAGE=$percentage" >> $GITHUB_OUTPUT + + - name: Print the coverage percentage for testing + run: | + echo "The coverage percentage is ${{ steps.coverage-extractor.outputs.COVERAGE }}" diff --git a/lib/src/messages.g.dart b/lib/src/messages.g.dart index 3d00988..b520bf0 100644 --- a/lib/src/messages.g.dart +++ b/lib/src/messages.g.dart @@ -1,3 +1,4 @@ +// coverage:ignore-file // Autogenerated from Pigeon (v22.7.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers diff --git a/pigeons/messages.dart b/pigeons/messages.dart index d2166f4..438d03e 100644 --- a/pigeons/messages.dart +++ b/pigeons/messages.dart @@ -6,6 +6,11 @@ import 'package:pigeon/pigeon.dart'; dartTestOut: 'test/test_api.g.dart', swiftOut: 'macos/native_image_picker_macos/Sources/native_image_picker_macos/Messages.g.swift', + dartOptions: DartOptions( + copyrightHeader: [ + 'coverage:ignore-file', + ], + ), ), ) diff --git a/test/test_api.g.dart b/test/test_api.g.dart index 7b03047..1601a42 100644 --- a/test/test_api.g.dart +++ b/test/test_api.g.dart @@ -1,3 +1,4 @@ +// coverage:ignore-file // Autogenerated from Pigeon (v22.7.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import, no_leading_underscores_for_local_identifiers From 47d668d9a926466ed38a873bf1c77ca689b38568 Mon Sep 17 00:00:00 2001 From: Ellet Date: Sat, 18 Jan 2025 23:42:01 +0300 Subject: [PATCH 2/6] ci: dynamic badge gist --- .github/workflows/coverage-badge.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/coverage-badge.yml b/.github/workflows/coverage-badge.yml index ccb138f..df7d1fe 100644 --- a/.github/workflows/coverage-badge.yml +++ b/.github/workflows/coverage-badge.yml @@ -38,3 +38,15 @@ jobs: - name: Print the coverage percentage for testing run: | echo "The coverage percentage is ${{ steps.coverage-extractor.outputs.COVERAGE }}" + + - name: Update dynamic badge gist + uses: schneegans/dynamic-badges-action@v1.7.0 + with: + auth: ${{ secrets.GIST_SECRET }} + gistID: e115a2922ddd4f9f897b6e2c15d6c071 # https://gist.github.com/EchoEllet/e115a2922ddd4f9f897b6e2c15d6c071 + filename: native-image-picker-macos-coverage-badge.json + label: coverage + message: ${{ steps.coverage-extractor.outputs.COVERAGE }}% + valColorRange: ${{ steps.coverage-extractor.outputs.COVERAGE }} + minColorRange: 0 + maxColorRange: 100 From 651667bfb821ad0d71b83dfddc3829b21b7fb496 Mon Sep 17 00:00:00 2001 From: Ellet Date: Sat, 18 Jan 2025 23:47:35 +0300 Subject: [PATCH 3/6] docs: apply dynamic badge in README.md --- .github/workflows/coverage-badge.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage-badge.yml b/.github/workflows/coverage-badge.yml index df7d1fe..7cde86a 100644 --- a/.github/workflows/coverage-badge.yml +++ b/.github/workflows/coverage-badge.yml @@ -45,7 +45,7 @@ jobs: auth: ${{ secrets.GIST_SECRET }} gistID: e115a2922ddd4f9f897b6e2c15d6c071 # https://gist.github.com/EchoEllet/e115a2922ddd4f9f897b6e2c15d6c071 filename: native-image-picker-macos-coverage-badge.json - label: coverage + label: 'Dart Coverage' message: ${{ steps.coverage-extractor.outputs.COVERAGE }}% valColorRange: ${{ steps.coverage-extractor.outputs.COVERAGE }} minColorRange: 0 diff --git a/README.md b/README.md index 54d3da0..1edf699 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Pub Version Star on Github License: MIT -Dart Code Coverage +Dart Coverage

A macOS platform implementation of [`image_picker`](https://pub.dev/packages/image_picker) From b6e0bbca8fee2d44955358212f6518e501d1fdc7 Mon Sep 17 00:00:00 2001 From: Ellet Date: Sat, 18 Jan 2025 23:53:29 +0300 Subject: [PATCH 4/6] docs: update the badge alt and the link url to the latest --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1edf699..20693e9 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Pub Version Star on Github License: MIT -Dart Coverage +Dart Code Coverage

A macOS platform implementation of [`image_picker`](https://pub.dev/packages/image_picker) From 1ef07112f14c02a0e92c3fc39b5dfd8b2b4c3cd6 Mon Sep 17 00:00:00 2001 From: Ellet Date: Sat, 18 Jan 2025 23:58:35 +0300 Subject: [PATCH 5/6] chore: add reference to https://bitspittle.dev/blog/2022/kover-badge in coverage-badge.yml --- .github/workflows/coverage-badge.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/coverage-badge.yml b/.github/workflows/coverage-badge.yml index 7cde86a..1e2e2d8 100644 --- a/.github/workflows/coverage-badge.yml +++ b/.github/workflows/coverage-badge.yml @@ -14,31 +14,32 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup Flutter (Stable) + - name: Setup Flutter (stable) uses: subosito/flutter-action@v2 with: channel: stable cache: true - - name: Install Package Dependencies + - name: Install package dependencies run: flutter pub get - - name: Collect coverage info + - name: Run tests and collect coverage information run: flutter test --coverage - - name: Install lcov + - name: Install lcov (coverage tool) run: sudo apt install -y lcov - name: Extract coverage percentage id: coverage-extractor run: | - percentage=$(lcov --summary coverage/lcov.info | grep 'lines' | awk '{print $2}' | sed 's/%//' | sed 's/.0$//') - echo "COVERAGE=$percentage" >> $GITHUB_OUTPUT + coverage=$(lcov --summary coverage/lcov.info | grep 'lines' | awk '{print $2}' | sed 's/%//' | sed 's/.0$//') + echo "COVERAGE=$coverage" >> $GITHUB_OUTPUT - - name: Print the coverage percentage for testing + - name: Output coverage percentage run: | - echo "The coverage percentage is ${{ steps.coverage-extractor.outputs.COVERAGE }}" + echo "The code coverage percentage is ${{ steps.coverage-extractor.outputs.COVERAGE }}" + # For a detailed guide, refer to: https://bitspittle.dev/blog/2022/kover-badge - name: Update dynamic badge gist uses: schneegans/dynamic-badges-action@v1.7.0 with: From 46c0933605b28372c494e7512aa240cda6c2adc0 Mon Sep 17 00:00:00 2001 From: Ellet Date: Sun, 19 Jan 2025 00:00:15 +0300 Subject: [PATCH 6/6] chore: remove the TODO and on pull requests --- .github/workflows/coverage-badge.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/coverage-badge.yml b/.github/workflows/coverage-badge.yml index 1e2e2d8..0cb4595 100644 --- a/.github/workflows/coverage-badge.yml +++ b/.github/workflows/coverage-badge.yml @@ -3,9 +3,6 @@ name: Create coverage badge on: push: branches: [main] - # TODO(EchoEllet): For testing only, remove - pull_request: - branches: [main] jobs: build: