From 827b7d0ff4406be29be657a7f23b88d1defe0c7c Mon Sep 17 00:00:00 2001 From: ChuufMaster Date: Thu, 30 May 2024 15:21:13 +0200 Subject: [PATCH] Added a workflow for running flutter tests and uploading code coverage --- .github/workflows/ci.yml | 61 ++++++++++++++++++++++++++++++++++++++++ analysis_options.yaml | 40 +++++++++++++++++++++++++- test/widget_test.dart | 2 +- 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..98213c5b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,61 @@ +name: CODECOV coverage upload +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubunutu-latest + + steps: + - name: Clone repository + uses: actions/checkout@v4 + - name: Set up Flutter + uses: subosito/flutter-action@v2 + with: + channel: stable + flutter-version-file: pubspec.yaml + + - name: Cache Flutter dependancies + uses: actions/cache@v3 + with: + path: | + ~./.pub-cache + ~./.flutter + keys: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.yaml') }} + restore-keys: | + ${{ runner.os }}-pub- + + - name: Install Flutter dependecies + run: flutter pub get + + - name: Run Flutter tests + run: flutter test --coverage + + - name: Upload coverage artifact + uses: actions/upload-artifact@v3 + with: + name: flutter-coverage-report + path: coverage/lcov.info + + codecov: + needs: test + runs-on: ubuntu-latest + steps: + - name: Download coverage artifact + uses: actions/download-artifact@v3 + with: + name: flutter-coverage-report + path: coverage + + - name: Upload Flutter Coverage to Codecov + uses: codecov/codecov-action@v3 + with: + files: coverage/lcov.info + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: true + verbose: true diff --git a/analysis_options.yaml b/analysis_options.yaml index 0d290213..cc93321f 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -22,7 +22,45 @@ linter: # producing the lint. rules: # avoid_print: false # Uncomment to disable the `avoid_print` rule - # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + # prefer_single_quotes # Uncomment to enable the `prefer_single_quotes` rule + - avoid_print # discourage using print statements + - prefer_const_constructors + - prefer_const_literals_to_create_immutables # Use const for immutable collections + - prefer_final_locals # Prefer final for local variables if they are not reassigned + - prefer_single_quotes # Prefer single quotes for strings + - annotate_overrides # Require @override for overridden methods + - always_declare_return_types # Always declare return types for methods and functions + - always_put_control_body_on_new_line # Control flow statements should have bodies on new lines + - always_use_package_imports # Use package imports for other files in the same package + - avoid_as # Avoid using `as` for type casts + - avoid_empty_else # Avoid empty else statements + - avoid_function_literals_in_foreach_calls # Avoid using function literals in forEach calls + - avoid_redundant_argument_values # Avoid passing redundant arguments + - avoid_types_on_closure_parameters # Avoid specifying types for closure parameters + - curly_braces_in_flow_control_structures # Use curly braces for all flow control structures + - empty_constructor_bodies # Constructors with empty bodies should be replaced with a semicolon + - implementation_imports # Avoid imports from implementation files + - library_prefixes # Use library prefixes for imports + - prefer_asserts_with_message # Use assert with messages + - prefer_typing_uninitialized_variables # Prefer typing for uninitialized variables + - slash_for_doc_comments # Use /// for documentation comments + - type_annotate_public_apis # Type annotate public APIs + - unnecessary_const # Remove unnecessary const + - unnecessary_new # Remove unnecessary new + - unnecessary_null_in_if_null_operators # Remove unnecessary null in if-null operators + - lines_longer_than_80_chars + - sort_constructors_first + - sort_child_properties_last + +# Override Flutter lints +analyzer: + errors: + avoid_print: warning # Set avoid_print as a warning instead of an error + +# Exclude generated files from analysis +exclude: + - '**/*.g.dart' + - '**/*.freezed.dart' # Additional information about this file can be found at # https://dart.dev/guides/language/analysis-options diff --git a/test/widget_test.dart b/test/widget_test.dart index 317b7122..b915a47f 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -11,7 +11,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:beakpeek/main.dart'; void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { + testWidgets('Counter increments smoke test', (tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const MyApp());