lifull-dev/bucky-core

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
version: 2
jobs:
  generate_cache_for_system_test:
    machine: true
    steps:
      - checkout
      - restore_cache:
          key: docker-{{ checksum ".circleci/config.yml" }}-{{ checksum "docker-compose.system-test.yml" }}-{{ checksum "Dockerfile.system-test" }}-{{ checksum "bucky-core.gemspec" }}-{{ checksum ".dockerignore" }}
      - run:
          command: |
            if [ ! -f ~/caches/images.tar ]; then
              docker-compose -f docker-compose.system-test.yml build && \
              mkdir -p ~/caches && \
              docker save $(docker images | awk 'NR>=2 && ! /^<none>/{print $1}') -o ~/caches/images.tar
            fi
      - save_cache:
          key: docker-{{ checksum ".circleci/config.yml" }}-{{ checksum "docker-compose.system-test.yml" }}-{{ checksum "Dockerfile.system-test" }}-{{ checksum "bucky-core.gemspec" }}-{{ checksum ".dockerignore" }}
          paths: ~/caches/images.tar
  system_test:
    machine: true
    parallelism: 2
    steps:
      - checkout
      - restore_cache:
          key: docker-{{ checksum ".circleci/config.yml" }}-{{ checksum "docker-compose.system-test.yml" }}-{{ checksum "Dockerfile.system-test" }}-{{ checksum "bucky-core.gemspec" }}-{{ checksum ".dockerignore" }}
      - run:
          command: docker load -q -i ~/caches/images.tar
      - run:
          name: docker up
          command: docker-compose -f docker-compose.system-test.yml up -d
      - run:
          name: execute system testing
          command: 'circleci tests glob system_testing/testing_code/*.bats | xargs -n 1 -I {} docker exec bucky-core bats "/bucky-core/"{} | circleci tests split'
      - run:
          name: docker down
          command: docker-compose -f docker-compose.system-test.yml down
  unit_test:
    working_directory: ~/bucky-core
    docker:
      - image: circleci/ruby:2.5.8
        environment:
          CC_TEST_REPORTER_ID: fd7bd9d517bdf8953c4d4803ca4ad7539d12d5c760048b8daf80cbc7d54fb262
    steps:
      - checkout
      - type: cache-restore
        key: unit-test-{{ checksum "Gemfile.lock" }}
      - run: bundle install --path vendor/bundle --quiet
      - type: cache-save
        key: unit-test-{{ checksum "Gemfile.lock" }}
        paths:
          - vendor/bundle
      # Download test-reporter
      - run:
          name: Setup Code Climate test-reporter
          command: |
            curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
            chmod +x ./cc-test-reporter
      # Run rspec and show on code climate
      - run: |
          ./cc-test-reporter before-build
          bundle exec rspec
          ./cc-test-reporter after-build --coverage-input-type simplecov --exit-code $?
  static_code_analysis:
    docker:
      - image: circleci/ruby:2.5.8
    steps:
      - checkout
      - type: cache-restore
        key: syntax-check-{{ checksum "Gemfile.lock" }}
      - run: bundle install --path vendor/bundle --quiet
      - type: cache-save
        key: syntax-check-{{ checksum "Gemfile.lock" }}
        paths:
          - vendor/bundle
      - run: bundle exec rubocop -f html --out report.html
      - store_artifacts:
          path: report.html
  publish_to_rubygems:
    docker:
      - image: circleci/ruby:2.5.8
    steps:
      - add_ssh_keys:
          finerprints:
            - "6a:f3:d3:b5:a5:da:ce:e0:9f:22:f8:4a:2f:51:67:2b"
      - checkout
      - run:
          name: Setup Rubygems
          command: bash .circleci/setup_rubygems.sh
      - run:
          name: Update version.rb and publish on RubyGems
          command: bash .circleci/deploy_to_rubygems.sh
  publish_to_docker_hub:
    machine: true
    environment:
      DOCKER_REPO: lifullsetg/bucky-core
    steps:
      - checkout
      - run:
          name: Build and tagged image
          command: |
            docker build -t "$DOCKER_REPO":"${CIRCLE_TAG/v/}" .
            docker tag "$DOCKER_REPO":"${CIRCLE_TAG/v/}" "$DOCKER_REPO":latest
      - run:
          name: Login and push image
          command: |
            docker login -u "$DOCKER_HUB_USER" -p "$DOCKER_HUB_TOKEN"
            docker push "$DOCKER_REPO":"${CIRCLE_TAG/v/}"
            docker push "$DOCKER_REPO":latest
            docker logout
workflows:
  version: 2
  test:
    jobs:
      - static_code_analysis
      - unit_test
      - generate_cache_for_system_test
      - system_test:
          requires:
            - generate_cache_for_system_test
  deploy:
    jobs:
      - publish_to_rubygems:
          filters:
            tags:
              only: /^v[0-9]{1,}(\.[0-9]{1,}){2}$/
            branches:
              ignore: /.*/
      - publish_to_docker_hub:
          filters:
            tags:
              only: /^v[0-9]{1,}(\.[0-9]{1,}){2}$/
            branches:
              ignore: /.*/
          requires:
            - publish_to_rubygems