diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..1fd7a83 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,33 @@ +name: Flutter Tests & Coverage + +on: + push: + branches: [main, develop] + pull_request: + branches: [main, develop] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Flutter + uses: subosito/flutter-action@v2 + with: + flutter-version: "3.29.3" + architecture: "x64" + + - name: Install dependencies + run: flutter pub get + + - name: Verify formatting + run: dart format --set-exit-if-changed . + + - name: Analyze project source + run: flutter analyze + + - name: Run tests with coverage + run: flutter test --coverage diff --git a/.github/workflows/validate-resource.yml b/.github/workflows/validate-resource.yml new file mode 100644 index 0000000..21ab3ed --- /dev/null +++ b/.github/workflows/validate-resource.yml @@ -0,0 +1,15 @@ +name: Validate merge source +on: + pull_request: + branches: [main] + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - name: Check source branch + run: | + if [ "${{ github.head_ref }}" != "develop" ]; then + echo "Error: Only develop branch can merge to main" + exit 1 + fi diff --git a/README.md b/README.md index 4d6e966..25d10f6 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,23 @@ The setup script will: - Initialize Husky for git hooks (if present) - Add `.fvm/` to `.gitignore` if needed +## Testing + +### Local Testing + +Run tests with coverage locally: + +```bash +# Using the provided script (recommended) +./scripts/test_with_coverage.sh + +# Or manually +fvm flutter test --coverage +lcov --summary coverage/lcov.info +genhtml coverage/lcov.info -o coverage/html +open coverage/html/index.html +``` + ## Contributing Contributions are welcome! Please: @@ -38,6 +55,7 @@ Contributions are welcome! Please: - Follow the existing code style and patterns - Write clear commit messages (Commitlint and Husky are enabled) - Add or update tests for new features or bug fixes +- Ensure all tests pass before submitting a pull request - Open a pull request with a clear description ## License diff --git a/scripts/test_with_coverage.sh b/scripts/test_with_coverage.sh new file mode 100755 index 0000000..4815d16 --- /dev/null +++ b/scripts/test_with_coverage.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Flutter Policy Engine - Test with Coverage Script +# This script runs all tests and generates coverage reports + +set -e # Exit on any error + +echo "๐Ÿงช Running Flutter tests with coverage..." + +# Run tests with coverage +fvm flutter test --coverage + +echo "๐Ÿ“Š Generating coverage summary..." +lcov --summary coverage/lcov.info + +echo "๐ŸŒ Generating HTML coverage report..." +genhtml coverage/lcov.info -o coverage/html + +echo "โœ… Coverage report generated successfully!" +echo "๐Ÿ“ HTML report available at: coverage/html/index.html" + +# Open the coverage report in browser (macOS) +if [[ "$OSTYPE" == "darwin"* ]]; then + echo "๐Ÿ”— Opening coverage report in browser..." + open coverage/html/index.html +else + echo "๐Ÿ“– To view the coverage report, open: coverage/html/index.html" +fi + +echo "๐ŸŽ‰ Test coverage process completed!" \ No newline at end of file