name: patrol_cli prepare

on:
  workflow_dispatch:
  pull_request:
    paths:
      - 'packages/patrol_cli/**'

jobs:
  main:
    name: Flutter ${{ matrix.flutter-version }} on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest]
        flutter-version: ['3.24.x']
        flutter-channel: ['stable']

    defaults:
      run:
        working-directory: packages/patrol_cli

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

      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          flutter-version: ${{ matrix.flutter-version }}
          channel: ${{ matrix.flutter-channel }}

      - name: Run flutter tool (to dismiss the first run experience)
        run: flutter

      - name: dart pub get
        run: dart pub get

      - name: Build executable
        run: dart pub global activate --source path .

      - name: Run executable (smoke test)
        run: patrol

      - name: dart test
        run: dart test

      - name: Run analyzer
        if: success() || failure()
        run: |
          flutter analyze
          dart run custom_lint

      - name: dart format
        run: dart format --set-exit-if-changed .

      - name: dart pub publish --dry-run
        run: dart pub publish --dry-run