language: objective-c
osx_image: xcode10.2
gemfile: Gemfile
addons:
  homebrew:
    packages:
    - swiftlint
    update: true

branches:
  only:
    - master
    - stable
    - travis-stages

cache:
  - cocoapods
  - bundler
  - $HOME/Library/Caches/Homebrew

env:
   global:
   - LANG=en_US.UTF-8

   - IOS_SCHEME="IGListKit"

   - IOS_SDK=iphonesimulator12.2
   - MACOS_SDK=macosx10.14
   - TVOS_SDK=appletvsimulator12.2

   - IOS_EXAMPLE_WORKSPACE="Examples/Examples-iOS/IGListKitExamples.xcworkspace"
   - TVOS_EXAMPLE_WORKSPACE="Examples/Examples-tvOS/IGListKitExamples.xcworkspace"
   - MACOS_EXAMPLE_WORKSPACE="Examples/Examples-macOS/IGListKitExamples.xcworkspace"
   - EXAMPLE_SCHEME="IGListKitExamples"

   # iOS Destinations
   - IOS_DESTINATION_9="OS=9.3,name=iPad Air 2"
   - IOS_DESTINATION_10="OS=10.3.1,name=iPhone 7"
   - IOS_DESTINATION_11="OS=11.3,name=iPhone X"
   - IOS_DESTINATION_12="OS=12.2,name=iPhone Xʀ"

   # macOS Destinations
   - MACOS_DESTINATION="arch=x86_64"

   # tvOS Destinations
   - TVOS_DESTINATION_10="OS=10.2,name=Apple TV 1080p"
   - TVOS_DESTINATION_11="OS=11.3,name=Apple TV 4K"
   - TVOS_DESTINATION_12="OS=12.2,name=Apple TV 4K"

before_install:
  # Bundler 2.0
  - gem update --system
  - gem install bundler

jobs:
  include:
    - stage: pod lint
      name: Cocoapods Lint
      # We need to pass all of the podspecs here so that Cocoapods uses the local version,
      # rather than searching the specs repository for the other specs in the repo.
      script: 
        - bundle exec pod lib lint IGListDiffKit.podspec --allow-warnings
        - bundle exec pod lib lint IGListKit.podspec --allow-warnings "--include-podspecs=IGListDiffKit.podspec"
        - bundle exec pod lib lint IGListSwiftKit.podspec --allow-warnings "--include-podspecs=*.podspec"
        
    # Build example projects
    - &build-examples
      stage: build examples
      name: "iOS 12.2"
      env: DESTINATION="$IOS_DESTINATION_12" WORKSPACE="$IOS_EXAMPLE_WORKSPACE" SDK="$IOS_SDK" SCHEME="$IOS_SCHEME"
      script:
        - set -o pipefail
        - xcodebuild -version -sdk
        - xcodebuild build -workspace "$WORKSPACE" -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION" ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO | bundle exec xcpretty -c;

    - <<: *build-examples
      name: "iOS 11.3"
      env: DESTINATION="$IOS_DESTINATION_11" WORKSPACE="$IOS_EXAMPLE_WORKSPACE" SDK="$IOS_SDK" SCHEME="$IOS_SCHEME"

    - <<: *build-examples
      name: "iOS 10.3.1"
      env: DESTINATION="$IOS_DESTINATION_10" WORKSPACE="$IOS_EXAMPLE_WORKSPACE" SDK="$IOS_SDK" SCHEME="$IOS_SCHEME"

    - <<: *build-examples
      name: "iOS 9.3"
      env: DESTINATION="$IOS_DESTINATION_9" WORKSPACE="$IOS_EXAMPLE_WORKSPACE" SDK="$IOS_SDK" SCHEME="$IOS_SCHEME"

    - <<: *build-examples
      name: "macOS 10.13"
      env: DESTINATION="$MACOS_DESTINATION" WORKSPACE="$MACOS_EXAMPLE_WORKSPACE" SDK="$MACOS_SDK" SCHEME="$EXAMPLE_SCHEME"

    - <<: *build-examples
      name: "tvOS 12.3"
      env: DESTINATION="$TVOS_DESTINATION_12" WORKSPACE="$TVOS_EXAMPLE_WORKSPACE" SDK="$TVOS_SDK" SCHEME="$EXAMPLE_SCHEME"

    - <<: *build-examples
      name: "tvOS 11.3"
      env: DESTINATION="$TVOS_DESTINATION_11" WORKSPACE="$TVOS_EXAMPLE_WORKSPACE" SDK="$TVOS_SDK" SCHEME="$EXAMPLE_SCHEME"

    - <<: *build-examples
      name: "tvOS 10.3"
      env: DESTINATION="$TVOS_DESTINATION_10" WORKSPACE="$TVOS_EXAMPLE_WORKSPACE" SDK="$TVOS_SDK" SCHEME="$EXAMPLE_SCHEME"

    # UI Tests
    - stage: tests
      name: "UI Tests: iOS 12.2"
      env: DESTINATION="$IOS_DESTINATION_12" WORKSPACE="$IOS_EXAMPLE_WORKSPACE" SDK="$IOS_SDK" SCHEME="$EXAMPLE_SCHEME"
      script:
        - set -o pipefail
        - xcodebuild build test -workspace "$WORKSPACE" -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO | bundle exec xcpretty -c;

    # Unit Tests
    - &unit-tests
      stage: tests
      name: "Tests: iOS 12.2"
      env: DESTINATION="$IOS_DESTINATION_12" WORKSPACE="IGListKit.xcworkspace" SDK="$IOS_SDK" SCHEME="$IOS_SCHEME"
      script:
        - set -o pipefail
        - xcodebuild build build-for-testing -workspace "$WORKSPACE" -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES ONLY_ACTIVE_ARCH=YES | bundle exec xcpretty -c;
        - xcodebuild analyze test-without-building -workspace "$WORKSPACE" -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES ONLY_ACTIVE_ARCH=YES | bundle exec xcpretty -c;
      after_success:
        - bundle exec slather

    - <<: *unit-tests
      name: "Tests: iOS 11.3"
      env: DESTINATION="$IOS_DESTINATION_11" WORKSPACE="IGListKit.xcworkspace" SDK="$IOS_SDK" SCHEME="$IOS_SCHEME"

    # Danger
    - stage: Danger
      script: bundle exec danger --verbose

stages:
  - pod lint
  - build examples
  - tests
  - danger
