name: build

on:
  push:
    branches:
      - master
      - main
  pull_request:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: 📚 Git Checkout
        uses: actions/checkout@v4

      - name: 🎯 Setup Dart
        uses: dart-lang/setup-dart@v1

      - name: 📦 Install Dependencies
        run: dart pub get

      - name: ✨ Check Formatting
        run: dart format --line-length 80 --set-exit-if-changed .

      - name: 🕵️ Analyze
        run: dart analyze --fatal-infos --fatal-warnings .

      - name: 🧪 Run Tests
        run: |
          dart pub global activate coverage 1.2.0
          dart test --coverage=coverage && dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info

      - name: 📊 Check Code Coverage
        uses: VeryGoodOpenSource/very_good_coverage@v2
        with:
          path: ./coverage/lcov.info
          min_coverage: 100

      - name: 📈 Upload coverage reports to Codecov
        uses: codecov/codecov-action@v3
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}