name: spm

on:
  pull_request:
    paths:
    - '.github/workflows/spm.yml'
    - 'Package.swift'
    - 'Gemfile'
  schedule:
    # Run every day at 11pm (PST) - cron uses UTC times
    - cron:  '0 7 * * *'

# This workflow builds and tests the Swift Package Manager. Only iOS runs on PRs
# because each platform takes 15-20 minutes after adding Firestore.

jobs:
  swift-build-run:
    # 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: Xcode 12
      run: sudo xcode-select -s /Applications/Xcode_12.app/Contents/Developer
    - name: Initialize xcodebuild
      run: xcodebuild -list
    - name: iOS Unit Tests
      run: scripts/third_party/travis/retry.sh ./scripts/build.sh Firebase-Package iOS spm

  cron-only:
    # Don't run on private repo.
    if: github.event_name == 'schedule' && github.repository == 'Firebase/firebase-ios-sdk'

    runs-on: macOS-latest
    strategy:
      matrix:
        target: [tvOS, macOS, catalyst]
        # Full set of Firebase-Package tests only run on iOS because of Analytics.
        test: [objc-import-test, swift-test, version-test]
    steps:
    - uses: actions/checkout@v2
    - name: Xcode 12
      run: sudo xcode-select -s /Applications/Xcode_12.app/Contents/Developer
    - name: Initialize xcodebuild
      run: xcodebuild -list
    - name: Unit Tests
      run: scripts/third_party/travis/retry.sh ./scripts/build.sh ${{ matrix.test }} ${{ matrix.target }} spm
