version: 2
jobs:
  build:

    docker:
      - image: circleci/openjdk:8-jdk
        environment:
          SBT_VERSION: 0.13.9
      - image: circleci/postgres:9.3-alpine

    steps:
      - checkout

      - restore_cache:
          key: hyperion-{{ .Branch }}-{{ checksum "build.sbt" }}

      - run:
          name: Create PostgreSQL schema
          command: psql -f scripts/database/schema.sql circle_test
      - run:
          name: Collect test coverage
          # Specify different config file, see https://stackoverflow.com/a/21433585
          command: |
            sbt '; set javaOptions += "-Dconfig.resource=.circleci/application.conf" ; coverage test'
            sbt coverageAggregate

      - save_cache:
          paths:
            - ~/.sbt
            - ./.ivy2
          key: hyperion-{{ .Branch }}-{{ checksum "build.sbt" }}

      - run:
          name: Report coverage to Codacy
          command: sbt codacyCoverage

      - run:
          name: Create Debian packages
          command: sbt debian:packageBin

      - store_artifacts:
          path: "**/target/test-reports/*.xml"
      - store_artifacts:
          path: "**/target/*.deb"
version: 2
jobs:
  build:

    docker:
      - image: circleci/openjdk:8-jdk
        environment:
          SBT_VERSION: 0.13.9
      - image: circleci/postgres:9.3-alpine

    steps:
      - checkout

      - restore_cache:
          key: hyperion-{{ .Branch }}-{{ checksum "build.sbt" }}

      - run:
          name: Install PostgreSQL client
          command: sudo apt install postgresql-client
      - run:
          name: Install dockerize
          command: |
            wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
            tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
            rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
          environment:
            DOCKERIZE_VERSION: v0.5.0
      - run:
          name: Wait for database
          command: dockerize -wait tcp://localhost:5432 -timeout 1m

      - run:
          name: Create PostgreSQL schema
          command: psql -f scripts/database/schema.sql circle_test
      - run:
          name: Collect test coverage
          # Specify different config file, see https://stackoverflow.com/a/21433585
          command: |
            sbt '; set javaOptions += "-Dconfig.resource=.circleci/application.conf" ; coverage test'
            sbt coverageAggregate

      - save_cache:
          paths:
            - ~/.sbt
            - ./.ivy2
          key: hyperion-{{ .Branch }}-{{ checksum "build.sbt" }}

      - run:
          name: Report coverage to Codacy
          command: sbt codacyCoverage

      - run:
          name: Create Debian packages
          command: sbt debian:packageBin

      - store_artifacts:
          path: "**/target/test-reports/*.xml"
      - store_artifacts:
          path: "**/target/*.deb"
Migrate to CircleCI 2.0 - make sure we can use the database
Migrate to CircleCI 2.0 - make sure we can use the database
