.circleci/config.yml

Summary

Maintainability
Test Coverage
# Python CircleCI 2.0 configuration file
# Check https://circleci.com/docs/2.0/language-python/ for more details
version: 2
jobs:
  build:
    docker:
      # CircleCI maintains a library of pre-built images documented at
      # https://circleci.com/docs/2.0/circleci-images/
      # use `-browsers` prefix for selenium tests, e.g. `<image_name>-browsers`

      # Python
      - image: circleci/python:3.5.3
        environment:
          TZ: America/New_York
          SQLA_TEST_CONN: postgresql://postgres@0.0.0.0/cfdm_unit_test

      # PostgreSQL
      - image: circleci/postgres:9.6.2
        environment:
          POSTGRES_USER: postgres
          POSTGRES_DB: cfdm_unit_test

    working_directory: ~/repo

    steps:
      - checkout

      - run:
          name: Install system dependencies
          # Commands listed here are from the CircleCI PostgreSQL config docs:
          # https://circleci.com/docs/2.0/postgres-config/#postgresql-circleci-configuration-example
          command: |
            sudo apt-get update -qq && sudo apt-get install -y build-essential postgresql-client
            echo 'export PATH=/usr/lib/postgresql/9.6/bin/:$PATH' >> $BASH_ENV

      - run:
          name: Install flyway
          command: |
            sudo apt-get update && sudo apt-get install -y default-jdk
            mkdir flyway
            curl -s https://repo.maven.apache.org/maven2/org/flywaydb/flyway-commandline/5.0.2/flyway-commandline-5.0.2-linux-x64.tar.gz | tar zxv -C flyway
            echo 'export PATH=./flyway/flyway-5.0.2:$PATH' >> $BASH_ENV

      - restore_cache:
          keys:
          - fec-api-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "requirements-dev.txt" }}-{{ checksum "requirements-ci.txt" }}-{{ checksum "package.json" }}
          # fallback to using the latest cache if no exact match is found
          - fec-api-dependencies-

      - run:
          name: Install node dependencies
          command: |
            curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash
            echo ". ~/.nvm/nvm.sh" >> $BASH_ENV
            export NVM_DIR="$HOME/.nvm"
            [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
            [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
            nvm install 8.9.1
            nvm use 8.9.1
            nvm alias default 8.9.1
            npm install -g npm swagger-tools
            npm install
            npm run build

      - run:
          name: Install Python dependencies
          command: |
            python3 -m venv venv
            . venv/bin/activate
            pip install -r requirements.txt -r requirements-dev.txt -r requirements-ci.txt

      - save_cache:
          paths:
            - ./venv
            - ./node_modules
          key: fec-api-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "requirements-dev.txt" }}-{{ checksum "requirements-ci.txt" }}-{{ checksum "package.json" }}

      - run:
          name: Ensure database is available
          command: dockerize -wait tcp://localhost:5432 -timeout 1m

      - run:
          name: Run tests
          command: |
            . venv/bin/activate
            py.test

      - run:
          name: Perform post-test checks
          command: |
            . venv/bin/activate
            codecov

      - store_artifacts:
          path: test-reports
          destination: test-reports

      - run:
          name: Install cf cli
          command: |
            mkdir -p $HOME/bin
            export PATH=$HOME/bin:$PATH
            curl -L "https://cli.run.pivotal.io/stable?release=linux64-binary&version=6.32.0" | tar xzv -C $HOME/bin
            cf install-plugin autopilot -f -r CF-Community

      - deploy:
          name: Deploy API
          command: |
            export PATH=$HOME/bin:$PATH
            export NVM_DIR="$HOME/.nvm"
            [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
            [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
            . venv/bin/activate
            nvm use default
            invoke deploy --branch $CIRCLE_BRANCH --login True --yes