Skip to content

Commit c2ed249

Browse files
committed
added github actions integration
1 parent 461bac9 commit c2ed249

11 files changed

+255
-112
lines changed

.github/workflows/analyzer.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Analyzer
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
check_analyzer:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: subosito/[email protected]
15+
with:
16+
channel: 'stable'
17+
- run: flutter packages get
18+
- run: flutter analyze

.github/workflows/formatting.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Code Formatting
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
check_formatting:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: subosito/[email protected]
15+
with:
16+
channel: 'stable'
17+
- run: flutter packages get
18+
- run: dart format --set-exit-if-changed .

.github/workflows/test.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: subosito/[email protected]
15+
with:
16+
channel: 'stable'
17+
- run: flutter packages get
18+
- run: dart run ./tool/test_coverage_create_helper.dart
19+
- run: flutter test --coverage
20+
- run: dart run ./tool/test_coverage_filter.dart
21+
- run: dart run ./tool/test_coverage_validate_percentage.dart
22+
- name: Coveralls
23+
uses: coverallsapp/github-action@master
24+
with:
25+
github-token: ${{ secrets.GITHUB_TOKEN }} na

.travis.yml

-50
This file was deleted.

tool/test_coverage_create_helper.dart

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import 'dart:io';
2+
3+
const packageName = 'custom_image_crop';
4+
5+
void main() {
6+
Logger.debug('First create a file with all other files imported so flutter test coverage uses all files');
7+
final imports = Directory('lib').listSync(recursive: true).where((element) {
8+
if (Directory(element.path).existsSync()) return false;
9+
if (!element.path.endsWith('.dart')) return false;
10+
if (element.path.endsWith('.g.dart')) return false;
11+
if (element.path.endsWith('_web.dart')) return false;
12+
return true;
13+
}).map((element) {
14+
final importPath = element.path.replaceFirst('lib', packageName);
15+
return "import 'package:$importPath';";
16+
});
17+
final testFile = File('test/coverage_helper_test.dart');
18+
if (!testFile.existsSync()) {
19+
testFile.createSync();
20+
}
21+
final sortedImports = imports.toList()..sort((e1, e2) => e1.compareTo(e2));
22+
final content = '${sortedImports.join('\n')}\nvoid main(){}';
23+
testFile.writeAsStringSync(content);
24+
Logger.debug('Created the test/coverage_helper_test.dart');
25+
}
26+
27+
class Logger {
28+
Logger._();
29+
30+
static void debug(Object value) => print(value); // ignore: avoid_print
31+
}

tool/test_coverage_filter.dart

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import 'dart:io';
2+
3+
void main(List<String> args) {
4+
printMessage('Start filtering the lcov.info file');
5+
final file = File('coverage/lcov.info');
6+
if (!file.existsSync()) {
7+
printMessage('${file.path}" does not exist');
8+
return;
9+
}
10+
const endOfRecord = 'end_of_record';
11+
final sections = <LcovSection>[];
12+
final lines = file.readAsLinesSync();
13+
LcovSection? currentSection;
14+
for (final line in lines) {
15+
if (line.endsWith('.dart')) {
16+
final filePath = line.replaceAll('SF:', '');
17+
currentSection = LcovSection()
18+
..header = line
19+
..filePath = filePath;
20+
} else if (line == endOfRecord) {
21+
final currentSectionTmp = currentSection;
22+
if (currentSectionTmp != null) {
23+
currentSectionTmp.footer = line;
24+
sections.add(currentSectionTmp);
25+
}
26+
} else {
27+
currentSection?.body.add(line);
28+
}
29+
}
30+
final filteredSections = getFilteredSections(sections);
31+
final sb = StringBuffer();
32+
for (final section in filteredSections) {
33+
sb.write(section.toString());
34+
}
35+
file.writeAsStringSync(sb.toString());
36+
printMessage('Filtered the lcov.info file');
37+
}
38+
39+
class LcovSection {
40+
String? filePath;
41+
String? header;
42+
final body = <String>[];
43+
String? footer;
44+
45+
String? getBodyString() {
46+
final filePathTmp = filePath;
47+
if (filePathTmp == null) return null;
48+
final file = File(filePathTmp);
49+
final content = file.readAsLinesSync();
50+
final sb = StringBuffer();
51+
getFilteredBody(body, content).forEach((item) => sb
52+
..write(item)
53+
..write('\n'));
54+
return sb.toString();
55+
}
56+
57+
@override
58+
String toString() {
59+
return '$header\n${getBodyString()}$footer\n';
60+
}
61+
}
62+
63+
List<LcovSection> getFilteredSections(List<LcovSection> sections) {
64+
return sections.where((section) {
65+
final header = section.header;
66+
if (header == null) return false;
67+
if (!header.endsWith('.dart')) {
68+
return false;
69+
} else if (header.endsWith('.g.dart')) {
70+
return false;
71+
} else if (header.endsWith('.config.dart')) {
72+
return false;
73+
} else if (header.endsWith('injectable.dart')) {
74+
return false;
75+
} else if (header.startsWith('SF:lib/util/locale')) {
76+
return false;
77+
} else if (header.startsWith('SF:lib/widget')) {
78+
return false;
79+
} else if (header.startsWith('SF:lib/screen')) {
80+
return false;
81+
} else if (header.startsWith('SF:lib/navigator')) {
82+
return false;
83+
}
84+
return true;
85+
}).toList();
86+
}
87+
88+
List<String> getFilteredBody(List<String> body, List<String> lines) {
89+
return body.where((line) {
90+
if (line.startsWith('DA:')) {
91+
final sections = line.split(',');
92+
final lineNr = int.parse(sections[0].replaceAll('DA:', ''));
93+
final callCount = int.parse(sections[1]);
94+
if (callCount == 0) {
95+
final fileLine = lines[lineNr - 1].trim();
96+
if (excludedLines.contains(fileLine)) {
97+
return false;
98+
}
99+
for (final line in excludedStartsWithLines) {
100+
if (fileLine.trim().startsWith(line)) {
101+
return false;
102+
}
103+
}
104+
}
105+
}
106+
return true;
107+
}).toList();
108+
}
109+
110+
const excludedLines = <String>[
111+
'const TranslationWriter._();',
112+
'const CaseUtil._();',
113+
'const LocaleGenParser._();',
114+
'const LocaleGenSbWriter._();',
115+
'const LocaleGenWriter._();',
116+
];
117+
118+
const excludedStartsWithLines = <String>[];
119+
120+
void printMessage(String message) {
121+
// ignore: avoid_print
122+
print(message);
123+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import 'dart:io';
2+
3+
const minRequiredCoverage = 0;
4+
5+
void main(List<String> args) {
6+
printMessage('Start checking the lcov.info file');
7+
final file = File('coverage/lcov.info');
8+
if (!file.existsSync()) {
9+
printMessage('${file.path}" does not exist');
10+
return;
11+
}
12+
var totalLines = 0;
13+
var totalLinesCovered = 0;
14+
final lines = file.readAsLinesSync();
15+
for (final line in lines) {
16+
if (line.startsWith('DA')) {
17+
totalLines++;
18+
} else if (line.startsWith('LH')) {
19+
totalLinesCovered += int.parse(line.replaceAll('LH:', ''));
20+
}
21+
}
22+
final codeCoveragePercentage = (totalLinesCovered / totalLines) * 100;
23+
if (codeCoveragePercentage == 100) {
24+
printMessage('\n100% CODE COVERAGE!!!!\n');
25+
} else if (codeCoveragePercentage >= minRequiredCoverage) {
26+
printMessage('COVERAGE IS ${codeCoveragePercentage.toStringAsFixed(2)}%\n');
27+
printMessage('TIS IS ABOVE THE MIN REQUIRED TARGET of $minRequiredCoverage%\n');
28+
} else {
29+
printMessage('\nCODE COVERAGE IS TO LOW!!\n');
30+
printMessage('COVERAGE IS ${codeCoveragePercentage.toStringAsFixed(2)}%\n');
31+
printMessage('AMOUNT OF LINES:$totalLines');
32+
printMessage('AMOUNT OF COVERED:$totalLinesCovered\n');
33+
exit(-1);
34+
}
35+
}
36+
37+
void printMessage(String message) {
38+
// ignore: avoid_print
39+
print(message);
40+
}

tool/travis/analyze.sh

-3
This file was deleted.

tool/travis/format.sh

-3
This file was deleted.

tool/travis/test.sh

-21
This file was deleted.

tool/travis/test_coverage_helper.dart

-35
This file was deleted.

0 commit comments

Comments
 (0)