Skip to content

Commit

Permalink
ci: add coverage to pr action
Browse files Browse the repository at this point in the history
  • Loading branch information
thelukewalton committed Jun 19, 2024
1 parent 9659e70 commit bb69316
Show file tree
Hide file tree
Showing 19 changed files with 230 additions and 76 deletions.
17 changes: 17 additions & 0 deletions .github/scripts/parse_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

lcov --capture --directory coverage --output-file coverage/lcov.info &> /dev/null

# Remove unnecessary files from the report
lcov --remove coverage/lcov.info 'lib/*/*.g.dart' 'lib/*/*.freezed.dart' -o coverage/lcov.info &> /dev/null

# Generate the HTML report
genhtml coverage/lcov.info --output-directory coverage/html &> /dev/null

# Save output of coverage
output=$(lcov --summary coverage/lcov.info )

# Trim output
output="${output##*....:}"
output="${output%%functions*}"

echo $output
23 changes: 19 additions & 4 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
with:
ref: ${{ github.head_ref }}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Install lcov
run: sudo apt-get install -y lcov
- name: Get branch name
id: branch-name
uses: tj-actions/[email protected]
Expand Down Expand Up @@ -43,20 +45,27 @@ jobs:
id: test
run: |
cd example
# Allows code to run after an error.
set -e
# Runs flutter test; saves output and if it fails.
out=$(flutter test) || failed='true'
out=$(flutter test --coverage) || failed='true'
echo "$out"
# Saves output to either success or failure variables.
if [ "$failed" == "true" ]; then
echo "FAILURE=true" >> $GITHUB_OUTPUT
exit 1
fi
- name: Check test coverage
if: always()
id: coverage
run: |
var=$(sh .github/scripts/parse_coverage.sh)
echo $var
echo "coverage='$(var)'" >> $GITHUB_OUTPUT
- name: Check for modified files
id: git-check
run: echo "modified=$(if [ -n "$(git status --porcelain)" ]; then echo "true"; else echo "false"; fi)" >> $GITHUB_ENV
Expand All @@ -68,8 +77,8 @@ jobs:
git add -A
git commit -m '[automated commit] lint format and import sort'
git push
- name: Print outputs
if: always()
env:
GH_TOKEN: ${{ github.token }}
run: |
Expand All @@ -87,6 +96,12 @@ jobs:
template="$template ✅ - All tests passed</br>"
fi
if [ -n "${{steps.coverage.outputs.coverage}}" ]; then
template="$template 🧪 ${{steps.coverage.outputs.coverage}}</br>"
else
echo 'Coverage does not work'
fi
# Add / amend comment on PR.
gh pr comment ${{github.event.pull_request.number}} --body="${template}" --edit-last -R ${{github.repository}} || gh pr comment ${{github.event.pull_request.number}} --body="${template}" -R ${{github.repository}} || echo 'Token not working'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: CI - Pull Request
on:
pull_request_target:
pull_request:

jobs:
up-to-date:
Expand Down
1 change: 0 additions & 1 deletion example/lib/pages/components/button_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class ButtonExample extends StatefulWidget {
class _ButtonExampleState extends State<ButtonExample> {
Widget? fab;
late ScrollController _scrollController;
bool expanded = false;

@override
void initState() {
Expand Down
8 changes: 4 additions & 4 deletions lib/src/components/fabs/fab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ZetaFAB extends StatefulWidget {
class _ZetaFABState extends State<ZetaFAB> {
@override
Widget build(BuildContext context) {
bool _isExpanded = (widget.initiallyExpanded != null ? widget.initiallyExpanded! : widget.label != null);
final bool isExpanded = (widget.initiallyExpanded != null ? widget.initiallyExpanded! : widget.label != null);
final colors = widget.type.colors(context);
final backgroundColor = widget.type == ZetaFabType.inverse ? colors.shade80 : colors.shade60;

Expand All @@ -115,7 +115,7 @@ class _ZetaFABState extends State<ZetaFAB> {
focusNode: widget.focusNode,
style: ButtonStyle(
padding: const WidgetStatePropertyAll(EdgeInsets.zero),
shape: WidgetStatePropertyAll(widget.shape.buttonShape(isExpanded: _isExpanded, size: widget.size)),
shape: WidgetStatePropertyAll(widget.shape.buttonShape(isExpanded: isExpanded, size: widget.size)),
backgroundColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.disabled)) return Zeta.of(context).colors.surfaceDisabled;
if (states.contains(WidgetState.hovered)) return colors.hover;
Expand All @@ -135,14 +135,14 @@ class _ZetaFABState extends State<ZetaFAB> {
child: AnimatedContainer(
duration: ZetaAnimationLength.normal,
child: Padding(
padding: _isExpanded
padding: isExpanded
? const EdgeInsets.symmetric(horizontal: ZetaSpacingBase.x3_5, vertical: ZetaSpacing.medium)
: EdgeInsets.all(widget.size.padding),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(widget.icon, size: widget.size.iconSize),
if (_isExpanded && widget.label != null)
if (isExpanded && widget.label != null)
Row(
mainAxisSize: MainAxisSize.min,
children: [Text(widget.label!, style: ZetaTextStyles.labelLarge)],
Expand Down
5 changes: 5 additions & 0 deletions test/src/components/badge/indicator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';
import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('badge'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});
testWidgets('Default constructor initializes with correct parameters', (WidgetTester tester) async {
await tester.pumpWidget(const TestApp(home: ZetaIndicator()));

Expand Down
5 changes: 5 additions & 0 deletions test/src/components/badge/label_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';
import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('badge'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});
testWidgets('Initializes with correct parameters', (WidgetTester tester) async {
await tester.pumpWidget(const TestApp(home: ZetaLabel(label: 'Test Label')));

Expand Down
5 changes: 5 additions & 0 deletions test/src/components/badge/priority_pill_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('badge'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});
testWidgets('Initializes with correct label and index', (WidgetTester tester) async {
await tester.pumpWidget(
const TestApp(
Expand Down
5 changes: 5 additions & 0 deletions test/src/components/badge/status_label_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('badge'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});
group('ZetaStatusLabel Tests', () {
testWidgets('Initializes with correct properties', (WidgetTester tester) async {
await tester.pumpWidget(
Expand Down
5 changes: 5 additions & 0 deletions test/src/components/badge/tag_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('badge'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});
group('ZetaTag', () {
testWidgets('Initializes right with correct parameters', (WidgetTester tester) async {
await tester.pumpWidget(
Expand Down
6 changes: 6 additions & 0 deletions test/src/components/button/button_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('button'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});

group('ZetaButton Tests', () {
testWidgets('Initializes with correct Label', (WidgetTester tester) async {
await tester.pumpWidget(
Expand Down
6 changes: 6 additions & 0 deletions test/src/components/checkbox/checkbox_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('checkbox'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});

group('ZetaCheckbox Tests', () {
testWidgets('Initializes with correct parameters', (WidgetTester tester) async {
await tester.pumpWidget(
Expand Down
6 changes: 6 additions & 0 deletions test/src/components/dialpad/dialpad_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('dialpad'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});

group('ZetaDialPad Tests', () {
testWidgets('Initializes with correct parameters and is enabled', (WidgetTester tester) async {
String number = '';
Expand Down
6 changes: 6 additions & 0 deletions test/src/components/fabs/fab_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';
import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('fabs'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});

group('ZetaFAB Tests', () {
testWidgets('Initializes with correct parameters', (WidgetTester tester) async {
final scrollController = ScrollController();
Expand Down
6 changes: 6 additions & 0 deletions test/src/components/in_page_banner/in_page_banner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';
import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('in_page_banner'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});

group('ZetaInPageBanner Tests', () {
testWidgets('ZetaInPageBanner creation', (WidgetTester tester) async {
await tester.pumpWidget(
Expand Down
6 changes: 6 additions & 0 deletions test/src/components/tooltip/tooltip_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('tooltip'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});

group('ZetaTooltip Widget Tests', () {
testWidgets('renders with default properties', (WidgetTester tester) async {
await tester.pumpWidget(
Expand Down
Loading

0 comments on commit bb69316

Please sign in to comment.