defaults: &defaults
  working_directory: ~/SmartThingsCommunity/SmartThingsPublic
  docker:
    - image: smartthings-docker-build.jfrog.io/releng/build-common:latest
      command: /sbin/init
      auth:
        username: $ARTIFACTORY_USERNAME
        password: $ARTIFACTORY_PASSWORD
  shell: /bin/bash --login
  parallelism: 1
version: 2
jobs:
  build:
    <<: *defaults
    steps:
      - checkout
      - run: ./gradlew check -PsmartThingsArtifactoryUserName="$ARTIFACTORY_USERNAME" -PsmartThingsArtifactoryPassword="$ARTIFACTORY_PASSWORD"
      - run: ./gradlew compileSmartappsGroovy compileDevicetypesGroovy -PsmartThingsArtifactoryUserName="$ARTIFACTORY_USERNAME" -PsmartThingsArtifactoryPassword="$ARTIFACTORY_PASSWORD"
  deploy-dev:
    <<: *defaults
    steps:
      - checkout
      - run: ./gradlew deployArchives -PsmartThingsArtifactoryUserName="$ARTIFACTORY_USERNAME" -PsmartThingsArtifactoryPassword="$ARTIFACTORY_PASSWORD" -Ps3Buckets="$S3_BUCKETS_DEV"
      - run: ./gradlew slackSendMessage -PsmartThingsArtifactoryUserName="$ARTIFACTORY_USERNAME" -PsmartThingsArtifactoryPassword="$ARTIFACTORY_PASSWORD" -Pbranch="$CIRCLE_BRANCH" -PslackToken="$SLACK_TOKEN" -PslackWebhookUrl="$SLACK_WEBHOOK_URL" -PslackChannel="$SLACK_CHANNEL" --stacktrace
  deploy-stage:
    <<: *defaults
    steps:
      - checkout
      - run: ./gradlew deployArchives -PsmartThingsArtifactoryUserName="$ARTIFACTORY_USERNAME" -PsmartThingsArtifactoryPassword="$ARTIFACTORY_PASSWORD" -Ps3Buckets="$S3_BUCKETS_STAGE"
      - run: ./gradlew slackSendMessage -PsmartThingsArtifactoryUserName="$ARTIFACTORY_USERNAME" -PsmartThingsArtifactoryPassword="$ARTIFACTORY_PASSWORD" -Pbranch="$CIRCLE_BRANCH" -PslackToken="$SLACK_TOKEN" -PslackWebhookUrl="$SLACK_WEBHOOK_URL" -PslackChannel="$SLACK_CHANNEL" --stacktrace
workflows:
  version: 2
  deploy:
    jobs:
      - build
      - deploy-dev:
          requires:
            - build
          filters:
            branches:
              only: master
      - deploy-stage:
          requires:
            - build
          filters:
            branches:
              only: staging