Skip to content

Commit 212efb5

Browse files
Merge pull request #139 from icapps/github-actions
added github actions integration
2 parents 461bac9 + 7d87b66 commit 212efb5

11 files changed

+234
-90
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 }}

.travis.yml

-50
This file was deleted.

example/analysis_options.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ linter:
5555
- file_names
5656
- hash_and_equals
5757
- implementation_imports
58-
- iterable_contains_unrelated_type
58+
- collection_methods_unrelated_type
5959
- join_return_with_assignment
6060
- library_names
6161
- library_prefixes
62-
- list_remove_unrelated_type
6362
- literal_only_boolean_expressions
6463
- no_adjacent_strings_in_list
6564
- no_duplicate_case_values

tool/travis/test_coverage_helper.dart renamed to tool/test_coverage_create_helper.dart

+8-11
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,31 @@ import 'dart:io';
22

33
const packageName = 'model_generator';
44

5-
main() {
6-
Logger.debug('====');
5+
void main() {
76
Logger.debug(
87
'First create a file with all other files imported so flutter test coverage uses all files');
9-
Logger.debug('====');
10-
118
final imports = Directory('lib').listSync(recursive: true).where((element) {
129
if (Directory(element.path).existsSync()) return false;
10+
if (!element.path.endsWith('.dart')) return false;
1311
if (element.path.endsWith('.g.dart')) return false;
12+
if (element.path.endsWith('_web.dart')) return false;
1413
return true;
1514
}).map((element) {
1615
final importPath = element.path.replaceFirst('lib', packageName);
17-
return 'import "package:$importPath";';
16+
return "import 'package:$importPath';";
1817
});
1918
final testFile = File('test/coverage_helper_test.dart');
2019
if (!testFile.existsSync()) {
2120
testFile.createSync();
2221
}
23-
final content = '${imports.join('\n')}\nvoid main(){}';
22+
final sortedImports = imports.toList()..sort((e1, e2) => e1.compareTo(e2));
23+
final content = '${sortedImports.join('\n')}\nvoid main(){}';
2424
testFile.writeAsStringSync(content);
25-
26-
Logger.debug('====');
27-
Logger.debug('Finished');
28-
Logger.debug('====');
25+
Logger.debug('Created the test/coverage_helper_test.dart');
2926
}
3027

3128
class Logger {
3229
Logger._();
3330

34-
static debug(value) => print(value); // ignore: avoid_print
31+
static void debug(Object value) => print(value); // ignore: avoid_print
3532
}

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,41 @@
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(
28+
'TIS IS ABOVE THE MIN REQUIRED TARGET of $minRequiredCoverage%\n');
29+
} else {
30+
printMessage('\nCODE COVERAGE IS TO LOW!!\n');
31+
printMessage('COVERAGE IS ${codeCoveragePercentage.toStringAsFixed(2)}%\n');
32+
printMessage('AMOUNT OF LINES:$totalLines');
33+
printMessage('AMOUNT OF COVERED:$totalLinesCovered\n');
34+
exit(-1);
35+
}
36+
}
37+
38+
void printMessage(String message) {
39+
// ignore: avoid_print
40+
print(message);
41+
}

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.

0 commit comments

Comments
 (0)