Skip to content

Commit 4b91e98

Browse files
authored
ci: code coverage badge (#3)
* chore: exclude generated pigeon files from code coverage calculation, coverage badge test * ci: dynamic badge gist * docs: apply dynamic badge in README.md
1 parent faac094 commit 4b91e98

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

.github/workflows/coverage-badge.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Create coverage badge
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Setup Flutter (stable)
15+
uses: subosito/flutter-action@v2
16+
with:
17+
channel: stable
18+
cache: true
19+
20+
- name: Install package dependencies
21+
run: flutter pub get
22+
23+
- name: Run tests and collect coverage information
24+
run: flutter test --coverage
25+
26+
- name: Install lcov (coverage tool)
27+
run: sudo apt install -y lcov
28+
29+
- name: Extract coverage percentage
30+
id: coverage-extractor
31+
run: |
32+
coverage=$(lcov --summary coverage/lcov.info | grep 'lines' | awk '{print $2}' | sed 's/%//' | sed 's/.0$//')
33+
echo "COVERAGE=$coverage" >> $GITHUB_OUTPUT
34+
35+
- name: Output coverage percentage
36+
run: |
37+
echo "The code coverage percentage is ${{ steps.coverage-extractor.outputs.COVERAGE }}"
38+
39+
# For a detailed guide, refer to: https://bitspittle.dev/blog/2022/kover-badge
40+
- name: Update dynamic badge gist
41+
uses: schneegans/[email protected]
42+
with:
43+
auth: ${{ secrets.GIST_SECRET }}
44+
gistID: e115a2922ddd4f9f897b6e2c15d6c071 # https://gist.github.com/EchoEllet/e115a2922ddd4f9f897b6e2c15d6c071
45+
filename: native-image-picker-macos-coverage-badge.json
46+
label: 'Dart Coverage'
47+
message: ${{ steps.coverage-extractor.outputs.COVERAGE }}%
48+
valColorRange: ${{ steps.coverage-extractor.outputs.COVERAGE }}
49+
minColorRange: 0
50+
maxColorRange: 100

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<a href="https://pub.dev/packages/native_image_picker_macos"><img src="https://img.shields.io/pub/v/native_image_picker_macos" alt="Pub Version"></a>
55
<a href="https://github.com/CompileKernel/native-image-picker-macos"><img src="https://img.shields.io/github/stars/CompileKernel/native-image-picker-macos" alt="Star on Github"></a>
66
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-purple.svg" alt="License: MIT"></a>
7-
<a href="https://github.com/CompileKernel/native-image-picker-macos"><img src="https://img.shields.io/badge/Dart%20Code%20Coverage-100%25-brightgreen" alt="Dart Code Coverage"></a>
7+
<a href="https://github.com/CompileKernel/native-image-picker-macos/actions"><img src="https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/EchoEllet/e115a2922ddd4f9f897b6e2c15d6c071/raw/native-image-picker-macos-coverage-badge.json" alt="Dart Code Coverage"></a>
88
</p>
99

1010
A macOS platform implementation of [`image_picker`](https://pub.dev/packages/image_picker)

lib/src/messages.g.dart

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// coverage:ignore-file
12
// Autogenerated from Pigeon (v22.7.2), do not edit directly.
23
// See also: https://pub.dev/packages/pigeon
34
// 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

pigeons/messages.dart

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import 'package:pigeon/pigeon.dart';
66
dartTestOut: 'test/test_api.g.dart',
77
swiftOut:
88
'macos/native_image_picker_macos/Sources/native_image_picker_macos/Messages.g.swift',
9+
dartOptions: DartOptions(
10+
copyrightHeader: <String>[
11+
'coverage:ignore-file',
12+
],
13+
),
914
),
1015
)
1116

test/test_api.g.dart

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// coverage:ignore-file
12
// Autogenerated from Pigeon (v22.7.2), do not edit directly.
23
// See also: https://pub.dev/packages/pigeon
34
// 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

0 commit comments

Comments
 (0)