This project includes a comprehensive CI/CD workflow that automatically runs tests whenever code is pushed to GitHub. The workflow is configured in .github/workflows/ci.yml and provides automated testing, code analysis, and build verification.
The CI workflow runs automatically on:
- Push to
main,master, ordevelopbranches - Pull requests to
main,master, ordevelopbranches - Manual dispatch (can be triggered manually from GitHub Actions tab)
This is the primary job that runs all Flutter unit tests and performs code quality checks:
Steps:
- ✅ Checkout repository
- ✅ Setup Java 17 (Oracle distribution)
- ✅ Setup Flutter 3.32.x (stable channel)
- ✅ Cache Flutter dependencies for faster builds
- ✅ Create environment file (
.env) with test configuration - ✅ Install Flutter dependencies
- ✅ Verify Flutter installation
- ✅ Analyze code with
flutter analyze --fatal-infos --fatal-warnings - ✅ Check code formatting with
dart format --set-exit-if-changed - ✅ Run tests with coverage using
flutter test --coverage --reporter expanded - ✅ Upload test results and coverage reports as artifacts
Verifies that the application builds correctly for Android:
Steps:
- ✅ Build Android APK (debug)
- ✅ Build Android App Bundle (debug)
- ✅ Runs only after tests pass successfully
Runs integration tests (if present):
Conditions:
- Only runs on pull requests or pushes to main/master branches
- Checks for
integration_testdirectory and runs tests if found - Skips gracefully if no integration tests exist
Provides a consolidated summary of all test results:
Features:
- ✅ Shows overall status of unit tests and build tests
- ✅ Displays success/failure status in GitHub Actions summary
- ✅ Runs regardless of previous job outcomes
- Static Analysis: Uses
flutter analyzewith strict settings - Code Formatting: Enforces consistent code formatting with
dart format - Test Coverage: Generates coverage reports for all tests
- Dependency Caching: Caches Flutter pub dependencies to reduce build times
- Parallel Jobs: Runs build tests in parallel with integration tests
- Conditional Execution: Integration tests only run when necessary
- Test Results: Uploaded as artifacts when tests fail (30-day retention)
- Coverage Reports: Generated and uploaded for every run (30-day retention)
- Summary Reports: Visible in GitHub Actions summary page
The workflow automatically handles environment configuration:
- Tries to copy
.env.exampleto.env - Creates a basic
.envfile if example doesn't exist - Uses test-appropriate configuration values
Required environment variables for testing:
# Test environment
API_BASE_URL=https://api.test.example.com
SEQ_API_KEY=test-keyThe workflow generates comprehensive test coverage reports:
- LCOV format:
coverage/lcov.info - HTML reports: Available in
coverage/directory - Artifacts: Uploaded to GitHub Actions for download
- ✅ Detailed test output is shown in the job logs
- ✅ Test files are uploaded as artifacts for investigation
- ✅ Build and integration tests are skipped to save resources
- ✅ Summary job still runs to provide consolidated status
- ✅ Analysis failures: Detailed warnings/errors shown in logs
- ✅ Formatting failures: Shows which files need formatting
- ✅ Build failures: Full build logs available for debugging
To run the same checks locally before pushing:
# Run all tests with coverage
flutter test --coverage --reporter expanded
# Run code analysis
flutter analyze --fatal-infos --fatal-warnings
# Check code formatting (120 column width)
dart format --set-exit-if-changed --page-width=120 .
# Build for Android
flutter build apk --debug
flutter build appbundle --debug- View workflow runs in the Actions tab of your repository
- Monitor success/failure rates over time
- Download artifacts (test results, coverage reports)
The workflow file is located at .github/workflows/ci.yml. Key maintenance tasks:
- Flutter Version Updates: Update
flutter-versionin the workflow - Java Version Updates: Modify
java-versionif needed - New Test Types: Add additional jobs for different test categories
- Environment Variables: Update environment file creation logic
-
Tests fail locally but pass on CI (or vice versa):
- Check environment file differences
- Verify Flutter and Dart versions match
- Ensure all dependencies are properly declared
-
Build failures:
- Check Java version compatibility
- Verify Android configuration
- Review dependency versions
-
Coverage issues:
- Ensure test files have proper imports
- Check that all source files are being tested
- Verify coverage path configuration
- Check the Actions tab for detailed logs
- Review failed job steps for specific error messages
- Compare successful runs with failed ones to identify changes
- Use
flutter doctor -vlocally to verify your environment matches CI
This CI/CD setup provides:
✅ Automated Quality Assurance: Catches issues before they reach production
✅ Consistent Environment: Same Flutter/Java versions across all builds
✅ Fast Feedback: Developers get immediate notification of test failures
✅ Code Coverage Tracking: Monitor test coverage trends over time
✅ Build Verification: Ensures app builds successfully on every change
✅ Professional Development: Industry-standard CI/CD practices