bigcommerce/gruf-rspec

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
version: 2.1

orbs:
  code-climate: bigcommerce/internal-codeclimate@volatile

ruby_env: &ruby_env
  working_directory: ~/repo
  environment:
    BUNDLE_JOBS: 4
    BUNDLE_RETRY: 3
    BUNDLE_PATH: vendor/bundle
    RACK_ENV: test
    RAILS_ENV: test
    RUBY_VERSION: <<parameters.ruby-version>>
  docker:
    - image: cimg/ruby:<<parameters.ruby-version>>

executors:
  ruby_3_0:
    <<: *ruby_env
    parameters:
      ruby-version:
        type: string
        default: "3.0"
  ruby_3_1:
    <<: *ruby_env
    parameters:
      ruby-version:
        type: string
        default: "3.1"
  ruby_3_2:
    <<: *ruby_env
    parameters:
      ruby-version:
        type: string
        default: "3.2"
  ruby_3_3:
    <<: *ruby_env
    parameters:
      ruby-version:
        type: string
        default: "3.3"

commands:
  pre-setup:
    steps:
      - add_ssh_keys
      - checkout
  bundle-install:
    parameters:
      gem_cache_key:
        type: string
        default: gem-cache-v3
      grpc_ruby_build_procs:
        type: integer
        default: 4
    steps:
      - restore_cache:
          keys:
            - <<parameters.gem_cache_key>>-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
            - <<parameters.gem_cache_key>>-{{ arch }}-{{ .Branch }}
            - <<parameters.gem_cache_key>>
      - run:
          name: "Bundle install"
          command: |
            export GRPC_RUBY_BUILD_PROCS=<<parameters.grpc_ruby_build_procs>>
            bundle config set --local path 'vendor/bundle'
            bundle lock --add-platform x86_64-linux
            bundle check || bundle install
            bundle clean
      - save_cache:
          key: <<parameters.gem_cache_key>>-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle
  rspec-unit:
    parameters:
      additional_args:
        type: string
        default: ""
      glob:
        type: string
        default: ""
      code-climate:
        type: boolean
        default: false
    steps:
      - run: mkdir ~/rspec
      - when:
          condition: <<parameters.code-climate>>
          steps:
            - code-climate/setup
      - run:
          name: "Run rspec tests"
          command: |
            TESTFILES=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
            echo "Running: ${TESTFILES}"
            bundle exec rspec --format progress --format RspecJunitFormatter -o ~/rspec/rspec.xml <<parameters.additional_args>> -- ${TESTFILES}
          when: always
      - when:
          condition: <<parameters.code-climate>>
          steps:
            - code-climate/store-report:
                coverage-format: "simplecov"
            - code-climate/sum-coverage
            - code-climate/after-build:
                coverage-format: "simplecov"
      - store_test_results:
          path: ~/rspec
  bundle-audit:
    parameters:
      additional_args:
        type: string
        default: ""
    steps:
      - run: bundle exec bundle-audit update
      - run: bundle exec bundle-audit check -v <<parameters.additional_args>>
  rubocop:
    steps:
      - run: bundle exec rubocop -p

jobs:
  bundle-audit:
    executor: <<parameters.e>>
    parameters:
      e:
        type: executor
        default: "ruby_3_0"
    steps:
      - pre-setup
      - bundle-install
      - bundle-audit
  rubocop:
    executor: <<parameters.e>>
    parameters:
      e:
        type: executor
        default: "ruby_3_0"
    steps:
      - pre-setup
      - bundle-install
      - bundle-audit
  rspec-unit:
    executor: <<parameters.e>>
    parameters:
      e:
        type: executor
        default: "ruby_3_0"
      code-climate:
        type: boolean
        default: false
    steps:
      - pre-setup
      - bundle-install
      - rspec-unit:
          code-climate: <<parameters.code-climate>>

workflows:
  version: 2
  ruby_3_0:
    jobs:
      - bundle-audit:
          name: "ruby-3_0-bundle_audit"
          e: "ruby_3_0"
      - rubocop:
          name: "ruby-3_0-rubocop"
          e: "ruby_3_0"
      - rspec-unit:
          name: "ruby-3_0-rspec"
          e: "ruby_3_0"
          code-climate: true
  ruby_3_1:
    jobs:
      - bundle-audit:
          name: "ruby-3_1-bundle_audit"
          e: "ruby_3_1"
      - rubocop:
          name: "ruby-3_1-rubocop"
          e: "ruby_3_1"
      - rspec-unit:
          name: "ruby-3_1-rspec"
          e: "ruby_3_1"
  ruby_3_2:
    jobs:
      - bundle-audit:
          name: "ruby-3_2-bundle_audit"
          e: "ruby_3_2"
      - rubocop:
          name: "ruby-3_2-rubocop"
          e: "ruby_3_2"
      - rspec-unit:
          name: "ruby-3_2-rspec"
          e: "ruby_3_2"
  ruby_3_3:
    jobs:
      - bundle-audit:
          name: "ruby-3_3-bundle_audit"
          e: "ruby_3_3"
      - rubocop:
          name: "ruby-3_3-rubocop"
          e: "ruby_3_3"
      - rspec-unit:
          name: "ruby-3_3-rspec"
          e: "ruby_3_3"