
language: objective-c
osx_image: xcode10.1

env:
  global:
    - LC_CTYPE=en_US.UTF-8
    - LANG=en_US.UTF-8

notifications:
  email: false

addons:
  homebrew:
    packages:
    - curl # Fix the codecov upload issue

cache: cocoapods
podfile: Examples/Podfile

before_install:
    - env
    - locale
    - gem install cocoapods --no-rdoc --no-ri --no-document --quiet
    - gem install xcpretty --no-rdoc --no-ri --no-document --quiet
    - pod --version
    - pod repo update --silent
    - xcpretty --version
    - xcodebuild -version
    - xcodebuild -showsdks

script:
    - set -o pipefail

    - echo Check if the library described by the podspec can be built
    - pod lib lint --allow-warnings --skip-tests # Will run test below

    - echo Build as static library
    - xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage static' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Debug | xcpretty -c
    - xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage static' -sdk watchsimulator -configuration Debug | xcpretty -c

    - echo Clean DerivedData
    - rm -rf ~/Library/Developer/Xcode/DerivedData/

    - echo Build as dynamic frameworks
    - xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage' -sdk macosx -configuration Debug | xcpretty -c
    - xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Debug | xcpretty -c
    - xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage' -sdk appletvsimulator -configuration Debug | xcpretty -c
    - xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage' -sdk watchsimulator -configuration Debug | xcpretty -c
    - xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImageMapKit' -sdk macosx -configuration Debug | xcpretty -c
    - xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImageMapKit' -sdk iphonesimulator PLATFORM_NAME=iphonesimulator -configuration Debug | xcpretty -c
    - xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImageMapKit' -sdk appletvsimulator -configuration Debug | xcpretty -c

    - echo Build the Demo apps
    - pod install --project-directory=Examples
    - xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage OSX Demo' -sdk macosx -configuration Debug | xcpretty -c
    - xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage iOS Demo' -configuration Debug -destination 'name=iPhone XS' | xcpretty -c
    - xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage TV Demo' -sdk appletvsimulator -configuration Debug | xcpretty -c
    - xcodebuild build -workspace SDWebImage.xcworkspace -scheme 'SDWebImage Watch Demo' -configuration Debug -destination 'name=iPhone XS' | xcpretty -c

    - echo Clean DerivedData
    - rm -rf ~/Library/Developer/Xcode/DerivedData/
    - mkdir DerivedData

    - echo Run the tests
    - pod install --project-directory=Tests
    - xcodebuild test -workspace SDWebImage.xcworkspace -scheme 'Tests' -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone XS' -configuration Debug | xcpretty -c
    - mv ~/Library/Developer/Xcode/DerivedData/ ./DerivedData/iOS
    - xcodebuild test -workspace SDWebImage.xcworkspace -scheme 'Tests Mac' -sdk macosx -destination 'platform=OS X,arch=x86_64' -configuration Debug | xcpretty -c
    - mv ~/Library/Developer/Xcode/DerivedData/ ./DerivedData/macOS

after_success:
    - export PATH="/usr/local/opt/curl/bin:$PATH"
    - curl --version
    - bash <(curl -s https://codecov.io/bash) -D './DerivedData/macOS' -J '^SDWebImage$' -c -X gcov -F macos
    - bash <(curl -s https://codecov.io/bash) -D './DerivedData/iOS' -J '^SDWebImage$' -c -X gcov -F ios
