File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Dart
2+
3+ on :
4+ push :
5+ branches : [ main ]
6+ pull_request :
7+ branches : [ main ]
8+
9+ jobs :
10+ build :
11+ runs-on : ubuntu-latest
12+
13+ steps :
14+ - uses : actions/checkout@v4
15+
16+ - uses : dart-lang/setup-dart@v1
17+ with :
18+ sdk : stable
19+
20+ - name : Install dependencies
21+ run : dart pub get
22+
23+ - name : Verify formatting
24+ run : dart format --output=none --set-exit-if-changed .
25+
26+ - name : Analyze project source
27+ run : dart analyze
28+
29+ - name : Run tests with coverage
30+ run : |
31+ dart pub global activate coverage
32+ dart test --coverage=coverage
33+ dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info --report-on=lib
34+
35+ - name : Verify Coverage (>= 80%)
36+ run : dart script/verify_coverage.dart coverage/lcov.info 80
37+
38+ - name : Upload coverage to Codecov
39+ uses : codecov/codecov-action@v5
40+ with :
41+ token : ${{ secrets.CODECOV_TOKEN }}
42+ files : coverage/lcov.info
43+ fail_ci_if_error : true
44+
45+ - name : Install Pana
46+ run : dart pub global activate pana
47+
48+ - name : Run Pana Verification
49+ run : |
50+ dart pub global run pana . --no-warning --json > pana_report.json
51+ dart script/verify_pana_score.dart
52+
53+ - name : Publish Dry Run
54+ run : dart pub publish --dry-run
Original file line number Diff line number Diff line change 1+ import 'dart:io' ;
2+
3+ void main (List <String > args) {
4+ if (args.length < 2 ) {
5+ print ('Usage: dart verify_coverage.dart <lcov_file> <min_percent>' );
6+ exit (1 );
7+ }
8+
9+ final lcovPath = args[0 ];
10+ final minPercent = double .parse (args[1 ]);
11+
12+ final file = File (lcovPath);
13+ if (! file.existsSync ()) {
14+ print ('Error: LCOV file not found at $lcovPath ' );
15+ exit (1 );
16+ }
17+
18+ final lines = file.readAsLinesSync ();
19+ int totalLines = 0 ;
20+ int hitLines = 0 ;
21+
22+ for (final line in lines) {
23+ if (line.startsWith ('DA:' )) {
24+ // DA:<line_number>,<execution_count>
25+ final parts = line.substring (3 ).split (',' );
26+ if (parts.length >= 2 ) {
27+ totalLines++ ;
28+ if (int .parse (parts[1 ]) > 0 ) {
29+ hitLines++ ;
30+ }
31+ }
32+ }
33+ }
34+
35+ if (totalLines == 0 ) {
36+ print ('Error: No lines found in coverage report.' );
37+ exit (1 );
38+ }
39+
40+ final coverage = (hitLines / totalLines) * 100 ;
41+ print (
42+ 'Coverage: ${coverage .toStringAsFixed (2 )}% ($hitLines /$totalLines lines)' ,
43+ );
44+
45+ if (coverage < minPercent) {
46+ print ('Failure: Coverage is below the required threshold of $minPercent %.' );
47+ exit (1 );
48+ }
49+
50+ print ('Success: Coverage meets the requirement.' );
51+ }
Original file line number Diff line number Diff line change 1+ import 'dart:convert' ;
2+ import 'dart:io' ;
3+
4+ void main () {
5+ final file = File ('pana_report.json' );
6+ if (! file.existsSync ()) {
7+ print ('Error: pana_report.json not found.' );
8+ exit (1 );
9+ }
10+
11+ final jsonString = file.readAsStringSync ();
12+ final Map <String , dynamic > report = jsonDecode (jsonString);
13+
14+ final scores = report['scores' ] as Map <String , dynamic >? ;
15+ if (scores == null ) {
16+ print ('Error: Could not find scores in pana report.' );
17+ exit (1 );
18+ }
19+
20+ final grantedPoints = scores['grantedPoints' ] as int ? ;
21+ final maxPoints = scores['maxPoints' ] as int ? ;
22+
23+ if (grantedPoints == null ) {
24+ print ('Error: Could not find grantedPoints in pana report.' );
25+ exit (1 );
26+ }
27+
28+ print ('Pana Score: $grantedPoints / ${maxPoints ?? "Unknown" }' );
29+
30+ if (grantedPoints < 160 ) {
31+ print (
32+ 'Failure: Pana score $grantedPoints is below the required threshold of 160.' ,
33+ );
34+ exit (1 );
35+ }
36+
37+ print ('Success: Pana score meets the requirement.' );
38+ }
You can’t perform that action at this time.
0 commit comments