name: ci

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

jobs:
  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - uses: subosito/flutter-action@v1
        with:
          channel: "stable"

      - name: Get dependencies
        run: flutter pub get

      - name: Generate l10n
        run: |
          flutter gen-l10n
          dart format lib/l10n/gen/

      - name: Run lints
        run: flutter analyze

      - name: Check formatting
        run: flutter format --dry-run --set-exit-if-changed .

      - name: Run tests
        run: flutter test

  android:
    name: Android
    runs-on: ubuntu-latest
    needs: lint
    steps:
      - uses: actions/checkout@v2

      - uses: actions/setup-java@v1
        with:
          java-version: "12.x"

      - uses: subosito/flutter-action@v1
        with:
          channel: "stable"

      - name: Inject keystore
        working-directory: android/app
        run: |
          echo "${{ secrets.SIGNING_KEY }}" | base64 -d | tee key.jks >/dev/null

      - name: Android build
        env:
          ANDROID_KEY_ALIAS: ${{ secrets.ALIAS }}
          ANDROID_KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
          ANDROID_STORE_PATH: key.jks
          ANDROID_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }}
        run: flutter build apk --split-per-abi --release --target lib/main_prod.dart --flavor prod

  ios:
    name: iOS
    runs-on: macos-latest
    needs: lint
    steps:
      - uses: actions/checkout@v2

      - uses: subosito/flutter-action@v1
        with:
          channel: "stable"

      - run: flutter build ios --no-codesign --release --target lib/main_prod.dart --flavor prod

  linux:
    name: Linux
    runs-on: ubuntu-latest
    needs: lint
    steps:
      - uses: actions/checkout@v2

      - uses: subosito/flutter-action@v1
        with:
          channel: "stable"

      - name: Get additional dependencies
        run: |
          sudo apt-get update -y
          sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev libblkid-dev

      - name: Enable linux support
        run: |
          flutter config --enable-linux-desktop

      - name: Build
        run: |
          flutter build linux --release --target lib/main_prod.dart

  windows:
    name: Windows
    runs-on: windows-latest
    needs: lint
    steps:
      - uses: actions/checkout@v2

      - uses: subosito/flutter-action@v1
        with:
          channel: "stable"

      - name: Enable windows support
        run: |
          flutter config --enable-windows-desktop

      - name: Build
        run: |
          flutter build windows --release --target lib/main_prod.dart
