name: appdistribution

on:
  pull_request:
    paths:
    - 'FirebaseAppDistribution**'
    - '.github/workflows/appdistribution.yml'
    - 'Gemfile*'
  schedule:
    # Run every day at 1am (PST) - cron uses UTC times
    - cron: '0 9 * * *'

jobs:
  pod-lib-lint:
    # Don't run on private repo unless it is a PR.
    if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request'

    runs-on: macos-latest
    strategy:
      matrix:
        target: [ios]
    steps:
    - uses: actions/checkout@v2
    - name: Setup Bundler
      run: scripts/setup_bundler.sh
    - name: Build and test
      run: |
       scripts/third_party/travis/retry.sh scripts/pod_lib_lint.rb FirebaseAppDistribution.podspec \
         --platforms=${{ matrix.target }}

  spm:
    # Don't run on private repo unless it is a PR.
    if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request'

    runs-on: macOS-latest
    steps:
    - uses: actions/checkout@v2
    - name: Initialize xcodebuild
      run: scripts/setup_spm_tests.sh
    - name: iOS Unit Tests
      run: scripts/third_party/travis/retry.sh ./scripts/build.sh AppDistributionUnit iOS spm

  catalyst:
    # Don't run on private repo unless it is a PR.
    if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request'

    runs-on: macOS-latest
    steps:
    - uses: actions/checkout@v2
    - name: Setup Bundler
      run: scripts/setup_bundler.sh
    - name: Setup project and Build for Catalyst
      run: scripts/test_catalyst.sh FirebaseAppDistribution test FirebaseAppDistribution-Unit-unit

  appdistribution-cron-only:
    if: github.event_name == 'schedule' && github.repository == 'Firebase/firebase-ios-sdk'

    runs-on: macos-latest
    strategy:
      matrix:
        target: [ios]
        flags: [
          '--use-static-frameworks',
          '--use-libraries'
        ]
    needs: pod-lib-lint
    steps:
    - uses: actions/checkout@v2
    - name: Setup Bundler
      run: scripts/setup_bundler.sh
    - name: PodLibLint App Distribution Cron
      run: |
       scripts/third_party/travis/retry.sh scripts/pod_lib_lint.rb FirebaseAppDistribution.podspec \
         --platforms=${{ matrix.target }} ${{ matrix.flags }}
