Skip to content

Commit

Permalink
Merge pull request #139 from icapps/github-actions
Browse files Browse the repository at this point in the history
added github actions integration
  • Loading branch information
vanlooverenkoen committed Aug 21, 2023
2 parents 461bac9 + 7d87b66 commit 212efb5
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 90 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/analyzer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Analyzer

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
check_analyzer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2.8.0
with:
channel: 'stable'
- run: flutter packages get
- run: flutter analyze
18 changes: 18 additions & 0 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Code Formatting

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
check_formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2.8.0
with:
channel: 'stable'
- run: flutter packages get
- run: dart format --set-exit-if-changed .
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2.8.0
with:
channel: 'stable'
- run: flutter packages get
- run: dart run ./tool/test_coverage_create_helper.dart
- run: flutter test --coverage
- run: dart run ./tool/test_coverage_filter.dart
- run: dart run ./tool/test_coverage_validate_percentage.dart
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
50 changes: 0 additions & 50 deletions .travis.yml

This file was deleted.

3 changes: 1 addition & 2 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ linter:
- file_names
- hash_and_equals
- implementation_imports
- iterable_contains_unrelated_type
- collection_methods_unrelated_type
- join_return_with_assignment
- library_names
- library_prefixes
- list_remove_unrelated_type
- literal_only_boolean_expressions
- no_adjacent_strings_in_list
- no_duplicate_case_values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,31 @@ import 'dart:io';

const packageName = 'model_generator';

main() {
Logger.debug('====');
void main() {
Logger.debug(
'First create a file with all other files imported so flutter test coverage uses all files');
Logger.debug('====');

final imports = Directory('lib').listSync(recursive: true).where((element) {
if (Directory(element.path).existsSync()) return false;
if (!element.path.endsWith('.dart')) return false;
if (element.path.endsWith('.g.dart')) return false;
if (element.path.endsWith('_web.dart')) return false;
return true;
}).map((element) {
final importPath = element.path.replaceFirst('lib', packageName);
return 'import "package:$importPath";';
return "import 'package:$importPath';";
});
final testFile = File('test/coverage_helper_test.dart');
if (!testFile.existsSync()) {
testFile.createSync();
}
final content = '${imports.join('\n')}\nvoid main(){}';
final sortedImports = imports.toList()..sort((e1, e2) => e1.compareTo(e2));
final content = '${sortedImports.join('\n')}\nvoid main(){}';
testFile.writeAsStringSync(content);

Logger.debug('====');
Logger.debug('Finished');
Logger.debug('====');
Logger.debug('Created the test/coverage_helper_test.dart');
}

class Logger {
Logger._();

static debug(value) => print(value); // ignore: avoid_print
static void debug(Object value) => print(value); // ignore: avoid_print
}
123 changes: 123 additions & 0 deletions tool/test_coverage_filter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import 'dart:io';

void main(List<String> args) {
printMessage('Start filtering the lcov.info file');
final file = File('coverage/lcov.info');
if (!file.existsSync()) {
printMessage('${file.path}" does not exist');
return;
}
const endOfRecord = 'end_of_record';
final sections = <LcovSection>[];
final lines = file.readAsLinesSync();
LcovSection? currentSection;
for (final line in lines) {
if (line.endsWith('.dart')) {
final filePath = line.replaceAll('SF:', '');
currentSection = LcovSection()
..header = line
..filePath = filePath;
} else if (line == endOfRecord) {
final currentSectionTmp = currentSection;
if (currentSectionTmp != null) {
currentSectionTmp.footer = line;
sections.add(currentSectionTmp);
}
} else {
currentSection?.body.add(line);
}
}
final filteredSections = getFilteredSections(sections);
final sb = StringBuffer();
for (final section in filteredSections) {
sb.write(section.toString());
}
file.writeAsStringSync(sb.toString());
printMessage('Filtered the lcov.info file');
}

class LcovSection {
String? filePath;
String? header;
final body = <String>[];
String? footer;

String? getBodyString() {
final filePathTmp = filePath;
if (filePathTmp == null) return null;
final file = File(filePathTmp);
final content = file.readAsLinesSync();
final sb = StringBuffer();
getFilteredBody(body, content).forEach((item) => sb
..write(item)
..write('\n'));
return sb.toString();
}

@override
String toString() {
return '$header\n${getBodyString()}$footer\n';
}
}

List<LcovSection> getFilteredSections(List<LcovSection> sections) {
return sections.where((section) {
final header = section.header;
if (header == null) return false;
if (!header.endsWith('.dart')) {
return false;
} else if (header.endsWith('.g.dart')) {
return false;
} else if (header.endsWith('.config.dart')) {
return false;
} else if (header.endsWith('injectable.dart')) {
return false;
} else if (header.startsWith('SF:lib/util/locale')) {
return false;
} else if (header.startsWith('SF:lib/widget')) {
return false;
} else if (header.startsWith('SF:lib/screen')) {
return false;
} else if (header.startsWith('SF:lib/navigator')) {
return false;
}
return true;
}).toList();
}

List<String> getFilteredBody(List<String> body, List<String> lines) {
return body.where((line) {
if (line.startsWith('DA:')) {
final sections = line.split(',');
final lineNr = int.parse(sections[0].replaceAll('DA:', ''));
final callCount = int.parse(sections[1]);
if (callCount == 0) {
final fileLine = lines[lineNr - 1].trim();
if (excludedLines.contains(fileLine)) {
return false;
}
for (final line in excludedStartsWithLines) {
if (fileLine.trim().startsWith(line)) {
return false;
}
}
}
}
return true;
}).toList();
}

const excludedLines = <String>[
'const TranslationWriter._();',
'const CaseUtil._();',
'const LocaleGenParser._();',
'const LocaleGenSbWriter._();',
'const LocaleGenWriter._();',
];

const excludedStartsWithLines = <String>[];

void printMessage(String message) {
// ignore: avoid_print
print(message);
}
41 changes: 41 additions & 0 deletions tool/test_coverage_validate_percentage.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'dart:io';

const minRequiredCoverage = 0;

void main(List<String> args) {
printMessage('Start checking the lcov.info file');
final file = File('coverage/lcov.info');
if (!file.existsSync()) {
printMessage('${file.path}" does not exist');
return;
}
var totalLines = 0;
var totalLinesCovered = 0;
final lines = file.readAsLinesSync();
for (final line in lines) {
if (line.startsWith('DA')) {
totalLines++;
} else if (line.startsWith('LH')) {
totalLinesCovered += int.parse(line.replaceAll('LH:', ''));
}
}
final codeCoveragePercentage = (totalLinesCovered / totalLines) * 100;
if (codeCoveragePercentage == 100) {
printMessage('\n100% CODE COVERAGE!!!!\n');
} else if (codeCoveragePercentage >= minRequiredCoverage) {
printMessage('COVERAGE IS ${codeCoveragePercentage.toStringAsFixed(2)}%\n');
printMessage(
'TIS IS ABOVE THE MIN REQUIRED TARGET of $minRequiredCoverage%\n');
} else {
printMessage('\nCODE COVERAGE IS TO LOW!!\n');
printMessage('COVERAGE IS ${codeCoveragePercentage.toStringAsFixed(2)}%\n');
printMessage('AMOUNT OF LINES:$totalLines');
printMessage('AMOUNT OF COVERED:$totalLinesCovered\n');
exit(-1);
}
}

void printMessage(String message) {
// ignore: avoid_print
print(message);
}
3 changes: 0 additions & 3 deletions tool/travis/analyze.sh

This file was deleted.

3 changes: 0 additions & 3 deletions tool/travis/format.sh

This file was deleted.

21 changes: 0 additions & 21 deletions tool/travis/test.sh

This file was deleted.

0 comments on commit 212efb5

Please sign in to comment.