name: instanceid

on:
  pull_request:
    paths:
    - 'FirebaseInstanceID**'
    - 'Firebase/InstanceID/**'
    - 'Example/InstanceID/**'
    - '.github/workflows/instanceid.yml'
    - 'Gemfile'
  schedule:
    # Run every day at 11pm (PST) - cron uses UTC times
    - cron:  '0 7 * * *'

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
    env:
      plist_secret: ${{ secrets.GHASecretsGPGPassphrase1 }}
    strategy:
      matrix:
        target: [ios, tvos, macos]
    steps:
    - uses: actions/checkout@v2
    - name: Setup Bundler
      run: scripts/setup_bundler.sh
    - name: Install GoogleService-Info.plist
      run: |
        mkdir -p Example/InstanceID/Resources
        scripts/decrypt_gha_secret.sh scripts/gha-encrypted/Installations/GoogleService-Info.plist.gpg \
          Example/InstanceID/Resources/GoogleService-Info.plist "$plist_secret"
    - name: Get boolean for secrets available
      id: secrets
      run: echo "::set-output name=val::$([[ -z $plist_secret ]] && echo "0" || echo "1")"
    - name: Build and test
      run: |
       export FIR_IID_INTEGRATION_TESTS_REQUIRED=${{ steps.secrets.outputs.val }}
       scripts/third_party/travis/retry.sh scripts/pod_lib_lint.rb FirebaseInstanceID.podspec --platforms=${{ matrix.target }}

  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 FirebaseInstanceID test FirebaseInstanceID-Unit-unit

  instanceid-cron-only:
    # Don't run on private repo.
    if: github.event_name == 'schedule' && github.repository == 'Firebase/firebase-ios-sdk'
    runs-on: macos-latest
    env:
      plist_secret: ${{ secrets.GHASecretsGPGPassphrase1 }}
      FIR_IID_INTEGRATION_TESTS_REQUIRED: ${{ secrets.GHASecretsGPGPassphrase1 }}
    strategy:
      matrix:
        target: [ios, tvos, macos]
        flags: [
          '--use-static-frameworks',
          '--use-libraries'
        ]
    needs: pod-lib-lint
    steps:
    - uses: actions/checkout@v2
    - name: Setup Bundler
      run: scripts/setup_bundler.sh
    - name: Install GoogleService-Info.plist
      run: |
        mkdir -p Example/InstanceID/Resources
        scripts/decrypt_gha_secret.sh scripts/gha-encrypted/Installations/GoogleService-Info.plist.gpg \
          Example/InstanceID/Resources/GoogleService-Info.plist "$plist_secret"
    - name: Get boolean for secrets available
      id: secrets
      run: echo "::set-output name=val::$([[ -z $plist_secret ]] && echo "0" || echo "1")"
    - name: PodLibLint InstanceID Cron
      run: |
        export FIR_IID_INTEGRATION_TESTS_REQUIRED=${{ steps.secrets.outputs.val }}
        FIR_IID_INTEGRATION_TESTS_REQUIRED="$plist_secret" scripts/third_party/travis/retry.sh scripts/pod_lib_lint.rb FirebaseInstanceID.podspec --platforms=${{ matrix.target }} ${{ matrix.flags }}
