fga-eps-mds/2019.2-Vsign

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
version: 2

references:
  default_docker_ruby_executor: &default_docker_ruby_executor
    image: circleci/ruby:2.6.3-stretch-node
    environment:
      BUNDLE_JOBS: 3
      BUNDLE_RETRY: 3
      BUNDLE_PATH: vendor/bundle
      PGHOST: 127.0.0.1
      PGUSER: vsign
      PGPASSWORD: ""
      RAILS_ENV: test
      CC_TEST_REPORTER_ID: a2b3d9b3f56055d821bcf096662502532ca97f19975414753b3011d6054a16bb
  postgres: &postgres
    image: circleci/postgres:10.3
    environment:
      POSTGRES_USER: vsign
      POSTGRES_DB: vsign_test
      POSTGRES_PASSWORD: ""
  default_docker_node_executor: &default_docker_node_executor
    image: circleci/node:12.2.0

jobs:
  build:
    docker:
      - *default_docker_ruby_executor
      - *default_docker_node_executor
    steps:
      - checkout
      # RAILS - Which version of bundler?
      - run:
          name: Which bundler?
          command: bundle -v
      # bundle cache
      - restore_cache:
          keys:
            - vsign-{{ checksum "backend/Gemfile.lock" }}
            - vsign-
      - run:
          working_directory: ./backend
          name: Rails - Bundle Install
          command: bundle check || bundle install
      # Store bundle cache
      - save_cache:
          key: vsign-{{ checksum "backend/Gemfile.lock" }}
          paths:
            - vendor/bundle
            
       # REACT - Download and cache dependencies
      - restore_cache:
          keys:
            - vsign-{{ checksum "frontend/package.json" }}
            # fallback to using the latest cache if no exact match is found
            - vsign-

      - run: 
          working_directory: ./frontend
          name: React - Yarn Install
          command: yarn install

      - save_cache:
          paths:
            - node_modules
          key: vsign-{{ checksum "frontend/package.json" }}


  deploy_staging:
    docker:
      - image: buildpack-deps:trusty
    steps:
      - checkout
      - run:
          name: Deploy Backend to Heroku
          command: |
            git push https://heroku:$HEROKU_API_KEY@git.heroku.com/vsign-api-staging.git `git subtree split --prefix backend develop`:refs/heads/master --force
  deploy_production:
    docker:
      - image: buildpack-deps:trusty
    steps:
      - checkout
      - run:
          name: Deploy Backend to Heroku
          command: |
            git push https://heroku:$HEROKU_API_KEY@git.heroku.com/vsign-api.git `git subtree split --prefix backend master`:refs/heads/master --force
  test:
    #parallelism: 3
    docker:
      - *default_docker_ruby_executor
      - *postgres
    steps:
      - checkout
      - restore_cache:
          keys:
            - vsign-{{ checksum "backend/Gemfile.lock" }}
            - vsign-
      - run:
          working_directory: ./backend
          name: Bundle Install
          command: bundle check || bundle install

      - run:
          name: Install Code Climate Test Reporter
          working_directory: ./backend
          command: |
            curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
            chmod +x ./cc-test-reporter

      - run:
          working_directory: ./backend
          name: Wait for DB
          command: dockerize -wait tcp://localhost:5432 -timeout 1m

      - run:
          working_directory: ./backend
          name: Database setup
          command: bundle exec rails db:setup --trace

      - run:
          working_directory: ./backend
          name: RSpec
          command: |
            mkdir -p test-results/rspec test-artifacts
            ./cc-test-reporter before-build
            TESTFILES=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
            bundle exec rspec --profile 10 \
                              --color \
                              --order random \
                              --require rails_helper \
                              --format RspecJunitFormatter \
                              --out test-results/rspec/rspec.xml \
                              --format progress \
                              -- ${TESTFILES}

      - run:
          name: Code Climate Test Coverage
          working_directory: ./backend
          command: |
            ./cc-test-reporter format-coverage -t simplecov -o "coverage/codeclimate.$CIRCLE_NODE_INDEX.json"
      - persist_to_workspace:
          root: ./backend/coverage
          paths:
            - codeclimate.*.json

      - store_test_results:
          path: backend/test-results

      - store_artifacts:
          path: backend/test-artifacts

      - run:
          name: Upload Code Climate
          working_directory: ./backend
          command: |
            ./cc-test-reporter sum-coverage --output - coverage/codeclimate.*.json | ./cc-test-reporter upload-coverage --debug --input -

  mkdocs:
    docker:
      - image: circleci/python:3.6-jessie-browsers
    steps:
      - checkout
      - run:
          name: Install and configure dependencies
          command: |
            git config user.email "ci-buildd@vsign.com"
            git config user.name "ci-build"
            sudo pip install mkdocs
      - add_ssh_keys:
          fingerprints:
            - "54:92:51:fb:31:89:aa:2f:07:98:d8:6c:51:38:31:eb"
      - run:
          name: Before Deploy
          command: mkdocs build --clean
      - run:
          name: Deploy Docs
          command: mkdocs gh-deploy
      

workflows:
  version: 2
  build_and_test:
    jobs:
      - build
      - test:
          requires:
            - build
  build_and_deploy_production:
    jobs:
      - build
      - deploy_production:
          requires:
            - build
          filters:
            branches:
              only: master
  build_and_deploy_staging:
    jobs:
      - build
      - deploy_staging:
          requires:
            - build
          filters:
            branches:
              only: develop
  deploy_mkdocs:
    jobs:
      - mkdocs:
          filters:
            branches:
              only: master