on:
  pull_request:
    paths-ignore:
      - ".github/**"
      - "docs"
      - "Jenkinsfile"
      - "**/*.md"

name: Analyze and test

env:
  FLUTTER_VERSION: 3.32.8

jobs:
  analyze-test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        modules:
          - default
          - core
          - model
          - contact
          - forward
          - rule_filter
          - fcm
          - email_recovery
          - server_settings
      fail-fast: false

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup flutter
        uses: subosito/flutter-action@v2
        with:
          flutter-version: ${{ env.FLUTTER_VERSION }}
          channel: "stable"
          cache: true
          cache-key: "deps-${{ hashFiles('**/pubspec.lock') }}"
          cache-path: ${{ runner.tool_cache }}/flutter # optional, change this to specify the cache path

      - name: Setup Firebase env
        env:
          FIREBASE_ENV: ${{ secrets.FIREBASE_ENV }}
        run: ./scripts/setup-firebase.sh

      - name: Run prebuild
        run: ./scripts/prebuild.sh

      - name: Analyze
        uses: zgosalvez/github-actions-analyze-dart@v1

      - name: Test
        env:
          MODULES: ${{ matrix.modules }}
        run: ./scripts/test.sh

      - name: Upload test reports
        if: success() || failure() # Always upload report
        uses: actions/upload-artifact@v4
        with:
          name: test-reports-${{ matrix.modules }}
          path: test-report*.json
