# .circleci/config.yml

# Specify the config version - version 2 is latest.
version: 2

# Define the jobs for the current project.
jobs:
  build-and-test:

    environment:
      - DESTINATION: "platform=iOS Simulator,name=iPhone XS"

    # Specify the Xcode version to use.
    macos:
      xcode: "10.0.0"

    # Define the steps required to build the project.
    steps:

      # Get the code from the VCS provider.
      - checkout
      - run:
          name: Update Homebrew
          command: brew update
      - run:
          name: Bootstrap Carthage
          command: carthage bootstrap --platform ios
      - run:
          name: Build framework
          command: xcodebuild build -project MessageKit.xcodeproj -scheme MessageKit -destination "$DESTINATION" CODE_SIGNING_REQUIRED=NO | xcpretty -c
      - run:
          name: Build and run tests
          command: xcodebuild test -project MessageKit.xcodeproj -scheme MessageKitTests -destination "$DESTINATION" CODE_SIGNING_REQUIRED=NO | xcpretty -c
      - run: 
          name: Fetch CocoaPods Specs
          command: curl -sS https://cocoapods-specs.circleci.com/fetch-cocoapods-repo-from-s3.sh | bash
      - run:
          name: Update Pods
          command: cd Example && pod install
      - run:
          name: Build and analyze Example
          command: xcodebuild build analyze -workspace Example/ChatExample.xcworkspace -scheme ChatExample -destination "$DESTINATION" ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO | xcpretty -c

      # Run tests.
      #- run:
      #    name: Run tests
      #    command: fastlane scan
      #    environment:
      #      SCAN_DEVICE: iPhone 6
      #      SCAN_SCHEME: WebTests

      # Collect XML test results data to show in the UI,
      # and save the same XML files under test-results folder
      # in the Artifacts tab.
      #- store_test_results:
      #    path: test_output/report.xml
      #- store_artifacts:
      #    path: /tmp/test-results
      #    destination: scan-test-results
      #- store_artifacts:
      #    path: ~/Library/Logs/scan
      #    destination: scan-logs

workflows:
  version: 2
  build-and-deploy:
    jobs:
      - build-and-test
