|
| 1 | +name: Flutter Coverage |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + - stable |
| 7 | + pull_request: |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +defaults: |
| 11 | + run: |
| 12 | + shell: bash |
| 13 | + |
| 14 | +# These permissions are needed to interact with GitHub's OIDC Token endpoint. |
| 15 | +permissions: |
| 16 | + id-token: write |
| 17 | + contents: read |
| 18 | + |
| 19 | +# Cancels in-progress job when there is another push to same ref. |
| 20 | +concurrency: |
| 21 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 22 | + cancel-in-progress: true |
| 23 | + |
| 24 | +jobs: |
| 25 | + flutter-coverage: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + timeout-minutes: 90 |
| 28 | + steps: |
| 29 | + - name: Git Checkout |
| 30 | + uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # 4.0.0 |
| 31 | + |
| 32 | + - name: Git Submodules |
| 33 | + run: git submodule update --init |
| 34 | + |
| 35 | + - name: Setup Flutter |
| 36 | + uses: subosito/flutter-action@fd55f4c5af5b953cc57a2be44cb082c8f6635e8e # 2.21.0 |
| 37 | + with: |
| 38 | + cache: true |
| 39 | + channel: stable |
| 40 | + |
| 41 | + - name: Flutter Version |
| 42 | + run: flutter --version |
| 43 | + |
| 44 | + - name: Setup aft |
| 45 | + run: dart pub global activate -spath packages/aft |
| 46 | + |
| 47 | + - name: Bootstrap |
| 48 | + id: bootstrap |
| 49 | + timeout-minutes: 20 |
| 50 | + run: aft bootstrap --fail-fast --verbose |
| 51 | + |
| 52 | + - name: Install lcov |
| 53 | + run: | |
| 54 | + sudo apt-get update |
| 55 | + sudo apt-get install -y lcov |
| 56 | +
|
| 57 | + - name: Run Flutter Tests with Coverage |
| 58 | + run: dart pub global run aft run test:unit:flutter |
| 59 | + continue-on-error: true |
| 60 | + |
| 61 | + - name: Merge Coverage Files |
| 62 | + if: always() |
| 63 | + run: | |
| 64 | + mkdir -p coverage |
| 65 | + # Find all non-empty lcov.info files and merge them |
| 66 | + find packages -name "lcov.info" -type f ! -empty -exec echo "--add-tracefile {}" \; | \ |
| 67 | + xargs lcov --branch-coverage --ignore-errors inconsistent --output-file coverage/merged_lcov.info || true |
| 68 | +
|
| 69 | + - name: Coverage Summary |
| 70 | + if: always() |
| 71 | + run: | |
| 72 | + if [ -f coverage/merged_lcov.info ]; then |
| 73 | + echo "## Flutter Coverage Summary" >> $GITHUB_STEP_SUMMARY |
| 74 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 75 | + lcov --summary coverage/merged_lcov.info 2>&1 | tee -a $GITHUB_STEP_SUMMARY |
| 76 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 77 | + else |
| 78 | + echo "No coverage data generated" >> $GITHUB_STEP_SUMMARY |
| 79 | + fi |
| 80 | +
|
| 81 | + - name: Upload to Codecov |
| 82 | + if: always() |
| 83 | + uses: codecov/codecov-action@v5 |
| 84 | + with: |
| 85 | + name: flutter-dart-coverage |
| 86 | + flags: flutter-tests |
| 87 | + files: coverage/merged_lcov.info |
| 88 | + token: ${{ secrets.CODECOV_TOKEN }} |
0 commit comments