name: Test project in a PR
on: [pull_request]
jobs:
  test_mac:
    runs-on: macos-latest
    defaults:
      run:
        # Run everything from within the super_editor project directory
        working-directory: ./super_editor
    steps:
      # Checkout the PR branch
      - uses: actions/checkout@v3

      # Setup Flutter environment
      - uses: subosito/flutter-action@v2
        with:
          channel: "master"
          architecture: x64

      # Download all the packages that the app uses
      - run: flutter pub get

      # TODO: run static analysis here when we get to zero analysis warnings

      # Run all tests
      - run: flutter test

  test_windows:
    runs-on: windows-latest
    defaults:
      run:
        # Run everything from within the super_editor project directory
        working-directory: ./super_editor
    steps:
      # Checkout the PR branch
      - uses: actions/checkout@v3

      # Setup Flutter environment
      - uses: subosito/flutter-action@v2
        with:
          channel: "master"

      # Download all the packages that the app uses
      - run: flutter pub get

      # TODO: run static analysis here when we get to zero analysis warnings

      # Run all tests
      - run: flutter test

  test_linux:
    runs-on: ubuntu-latest
    defaults:
      run:
        # Run everything from within the super_editor project directory
        working-directory: ./super_editor
    steps:
      # Checkout the PR branch
      - uses: actions/checkout@v3

      # Setup Flutter environment
      - uses: subosito/flutter-action@v2
        with:
          channel: "master"

      # Download all the packages that the app uses
      - run: flutter pub get

      # TODO: run static analysis here when we get to zero analysis warnings

      # Run all tests
      - run: flutter test

  test_goldens_super_editor:
    if: ${{ github.base_ref == 'main' }}
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./super_editor
    steps:
      # Checkout the PR branch
      - uses: actions/checkout@v3

      # Setup Flutter environment
      - uses: subosito/flutter-action@v2
        with:
          channel: "master"
          architecture: x64

      # Download all the packages that the app uses
      - run: flutter pub get

      # Run all golden tests
      - run: flutter test test_goldens

      # Archive golden failures
      - uses: actions/upload-artifact@v3
        if: failure()
        with:
          name: golden-failures
          path: "**/failures/**/*.png"

  test_super_editor_markdown:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./super_editor_markdown
    steps:
      # Checkout the PR branch
      - uses: actions/checkout@v3

      # Setup Flutter environment
      - uses: subosito/flutter-action@v2
        with:
          channel: "master"

      # Download all the packages that the app uses
      - run: flutter pub get

      # TODO: Enforce static analysis

      # Run all tests
      - run: flutter test

  test_super_editor_quill:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./super_editor_quill
    steps:
      # Checkout the PR branch
      - uses: actions/checkout@v3

      # Setup Flutter environment
      - uses: subosito/flutter-action@v2
        with:
          channel: "master"

      # Download all the packages that the app uses
      - run: flutter pub get

      # TODO: Enforce static analysis

      # Run all tests
      - run: flutter test

  analyze_super_keyboard:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./super_keyboard
    steps:
      # Checkout the PR branch
      - uses: actions/checkout@v3

      # Setup Flutter environment
      - uses: subosito/flutter-action@v2
        with:
          channel: "master"

      # Download all the packages that the app uses
      - run: flutter pub get

      # Enforce static analysis
      - run: flutter analyze

  test_super_keyboard:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./super_keyboard
    steps:
      # Checkout the PR branch
      - uses: actions/checkout@v3

      # Setup Flutter environment
      - uses: subosito/flutter-action@v2
        with:
          channel: "master"

      # Download all the packages that the app uses
      - run: flutter pub get

      # Run all tests
      - run: flutter test


  analyze_super_text_layout:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./super_text_layout
    steps:
      # Checkout the PR branch
      - uses: actions/checkout@v3

      # Setup Flutter environment
      - uses: subosito/flutter-action@v2
        with:
          channel: "master"

      # Download all the packages that the app uses
      - run: flutter pub get

      # Enforce static analysis
      - run: flutter analyze

  test_super_text_layout:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./super_text_layout
    steps:
      # Checkout the PR branch
      - uses: actions/checkout@v3

      # Setup Flutter environment
      - uses: subosito/flutter-action@v2
        with:
          channel: "master"

      # Download all the packages that the app uses
      - run: flutter pub get

      # Run all tests
      - run: flutter test

  test_goldens_super_text_layout:
    if: ${{ github.base_ref == 'main' }}
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./super_text_layout
    steps:
      # Checkout the PR branch
      - uses: actions/checkout@v3

      # Setup Flutter environment
      - uses: subosito/flutter-action@v2
        with:
          channel: "master"
          architecture: x64

      # Download all the packages that the app uses
      - run: flutter pub get

      # Run all golden tests
      - run: flutter test test_goldens

      # Archive golden failures
      - uses: actions/upload-artifact@v3
        if: failure()
        with:
          name: golden-failures
          path: "**/failures/**/*.png"

  analyze_attributed_text:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./attributed_text
    steps:
      # Checkout the PR branch
      - uses: actions/checkout@v3

      # Setup Dart
      - uses: dart-lang/setup-dart@v1

      # Install app dependencies
      - run: dart pub get

      # Enforce static analysis
      - run: dart analyze

  test_attributed_text:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./attributed_text
    steps:
      # Checkout the PR branch
      - uses: actions/checkout@v3

      # Setup Dart
      - uses: dart-lang/setup-dart@v1

      # Install app dependencies
      - run: dart pub get

      # Run all tests
      - run: dart test