code-corps/code-corps-api

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
jobs:
  build:
    working_directory: ~/code-corps-api
    docker:
      - image: circleci/elixir:1.6-node-browsers
      - image: circleci/postgres:9.4
        environment:
          POSTGRES_USER: ubuntu
    steps:
      - checkout
      - restore_cache:
          keys:
          - v1-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }}
          - v1-mix-cache-{{ .Branch }}
          - v1-mix-cache
      - restore_cache:
          keys:
          - v1-build-cache-{{ .Branch }}
          - v1-build-cache
      - run:
          name: Install PostgreSQL Client (for pg_dump, happening as part of ecto.migrate)
          command: sudo apt install postgresql-client
      - run: mix local.hex --force
      - run: mix local.rebar
      - run: mix deps.get
      - run:
          name: Run test suite and maybe report coverage
          command: |
            if [ ${CIRCLE_PR_USERNAME} ]; then
              MIX_ENV=test mix test;
            else
              MIX_ENV=test mix coveralls.circle --include acceptance:true;
            fi
      - save_cache:
          key: v1-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }}
          paths: "deps"
      - save_cache:
          key: v1-mix-cache-{{ .Branch }}
          paths: "deps"
      - save_cache:
          key: v1-mix-cache
          paths: "deps"
      - save_cache:
          key: v1-build-cache-{{ .Branch }}
          paths: "_build"
      - save_cache:
          key: v1-build-cache
          paths: "_build"
  deploy-remote-development:
    working_directory: ~/code-corps-api
    docker:
      - image: buildpack-deps:trusty
    steps:
      - checkout
      - run:
          name: Run Heroku setup script
          command: bash .circleci/setup-heroku.sh
      - add_ssh_keys:
          fingerprints:
            - "48:a0:87:54:ca:75:32:12:c6:9e:a2:77:a4:7a:08:a4"
      - run:
          name: Push to Remote Development
          command: |
            git push --force git@heroku.com:code-corps-remote-development.git HEAD:refs/heads/master
            heroku run "POOL_SIZE=2 mix ecto.migrate" --app code-corps-remote-development
            heroku restart --app code-corps-remote-development
  deploy-staging:
    working_directory: ~/code-corps-api
    docker:
      - image: buildpack-deps:trusty
    steps:
      - checkout
      - run:
          name: Run Heroku setup script
          command: bash .circleci/setup-heroku.sh
      - add_ssh_keys:
          fingerprints:
            - "db:3e:d6:de:66:8d:07:55:70:f6:36:0d:e1:11:28:71"
      - run:
          name: Push to Staging
          command: |
            git push --force git@heroku.com:code-corps-staging.git HEAD:refs/heads/master
            heroku run "POOL_SIZE=2 mix ecto.migrate" --app code-corps-staging
            heroku restart --app code-corps-staging
  deploy-production:
    working_directory: ~/code-corps-api
    docker:
      - image: buildpack-deps:trusty
    steps:
      - checkout
      - run:
          name: Run Heroku setup script
          command: bash .circleci/setup-heroku.sh
      - add_ssh_keys:
          fingerprints:
            - "48:a0:87:54:ca:75:32:12:c6:9e:a2:77:a4:7a:08:a4"
      - run:
          name: Deploy Master to Heroku Production
          command: |
            git push --force git@heroku.com:code-corps.git HEAD:refs/heads/master
            heroku run "POOL_SIZE=2 mix ecto.migrate" --app code-corps
            heroku restart --app code-corps
  deploy-staging-apiary:
    working_directory: ~/code-corps-api
    docker:
      - image: circleci/ruby:2.4
    steps:
      - checkout
      - run:
          name: Install Apiary
          command: gem install apiaryio
      - run:
          name: Deploy API Docs
          command: apiary publish --api-name="codecorpsapidevelop" --path ./blueprint/api.apib
  deploy-production-apiary:
    working_directory: ~/code-corps-api
    docker:
      - image: circleci/ruby:2.4
    steps:
      - checkout
      - run:
          name: Install Apiary
          command: gem install apiaryio
      - run:
          name: Deploy API Docs
          command: apiary publish --api-name="codecorpsapi" --path ./blueprint/api.apib
  deploy-exdocs:
    working_directory: ~/code-corps-api
    docker:
      - image: circleci/elixir:1.6
    steps:
      - checkout
      - restore_cache:
          keys:
          - v1-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }}
          - v1-mix-cache-{{ .Branch }}
          - v1-mix-cache
      - restore_cache:
          keys:
          - v1-build-cache-{{ .Branch }}
          - v1-build-cache
      - run: mix local.hex --force
      - run: mix local.rebar
      - run: mix deps.get
      - add_ssh_keys:
          fingerprints:
            - "db:3e:d6:de:66:8d:07:55:70:f6:36:0d:e1:11:28:71"
      - run:
          name: Identify as user on GitHub
          command: |
            git config --global user.email "josh@coderly.com"
            git config --global user.name "joshsmith"
      - run:
          name: Deploy Docs
          command: ./bin/deploy_docs.sh
      - save_cache:
          key: v1-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }}
          paths: "deps"
      - save_cache:
          key: v1-mix-cache-{{ .Branch }}
          paths: "deps"
      - save_cache:
          key: v1-mix-cache
          paths: "deps"
      - save_cache:
          key: v1-build-cache-{{ .Branch }}
          paths: "_build"
      - save_cache:
          key: v1-build-cache
          paths: "_build"

workflows:
  version: 2
  build-deploy:
    jobs:
      - build
      - deploy-remote-development:
          requires:
            - build
          filters:
            branches:
              only: develop
      - deploy-staging:
          requires:
            - build
          filters:
            branches:
              only: develop
      - deploy-production:
          requires:
            - build
          filters:
            branches:
              only: master
      - deploy-staging-apiary:
          requires:
            - build
          filters:
            branches:
              only: develop
      - deploy-production-apiary:
          requires:
            - build
          filters:
            branches:
              only: master
      - deploy-exdocs:
          requires:
            - build
          filters:
            branches:
              only: develop