# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: combine

on:
  pull_request:
    paths:
    # Combine sources
    - 'FirebaseCombineSwift/**'

    # Podspec
    - 'FirebaseCombineSwift.podspec'

    # This workflow
    - '.github/workflows/combine.yml'

    # Rebuild on Ruby infrastructure changes.
    - 'Gemfile'

  schedule:
    # Run every day at 11pm (PST) - cron uses UTC times
    - cron:  '0 7 * * *'

jobs:
  xcodebuild:
    # 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 build
      run:  scripts/install_prereqs.sh CombineSwift ${{ matrix.target }} xcodebuild

    - name: Build and test
      run:  scripts/third_party/travis/retry.sh scripts/build.sh CombineSwift ${{ matrix.target }} xcodebuild

  storage-combine-integration:
    # 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'
    env:
      plist_secret: ${{ secrets.GHASecretsGPGPassphrase1 }}
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v2
    - name: Setup Bundler
      run: scripts/setup_bundler.sh
    - name: Install Secret GoogleService-Info.plist
      run: scripts/decrypt_gha_secret.sh scripts/gha-encrypted/storage-db-plist.gpg \
          FirebaseStorage/Tests/Integration/Resources/GoogleService-Info.plist "$plist_secret"
    - name: Install Credentials.h
      run: scripts/decrypt_gha_secret.sh scripts/gha-encrypted/Storage/Credentials.h.gpg \
          FirebaseStorage/Tests/Integration/Credentials.h "$plist_secret"
    - name: Install Credentials.swift
      run: |
        scripts/decrypt_gha_secret.sh scripts/gha-encrypted/Storage/Credentials.swift.gpg \
          FirebaseStorage/Tests/SwiftIntegration/Credentials.swift "$plist_secret"
        cp FirebaseStorage/Tests/SwiftIntegration/Credentials.swift FirebaseStorageSwift/Tests/Integration/
    - name: BuildAndTest # can be replaced with pod lib lint with CocoaPods 1.10
      run: ([ -z $plist_secret ] || scripts/third_party/travis/retry.sh scripts/build.sh StorageCombine all)
