version: 2.1 executors: base: docker: - image: circleci/ruby:2.6.0 environment: BUNDLE_PATH: vendor/bundle working_directory: ~/repo commands: # ref:https://discuss.circleci.com/t/using-bundler-2-0-during-ci-fails/27411 install-bundler: steps: - run: name: Install Bundler command: | echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV source $BASH_ENV gem install bundler # Which version of bundler? bundle -v # Read about caching dependencies: https://circleci.com/docs/2.0/caching/ restore-gem-cache: steps: - restore_cache: keys: - v1-dependencies-{{ checksum "Gemfile.lock" }} # fallback to using the latest cache if no exact match is found - v1-dependencies- install-gem: steps: - run: name: Install gem command: | # jobs=4は並列処理をして高速化するための設定(4つのjobで実行するって意味) bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 save-gem-cache: steps: - save_cache: paths: - ./vendor/bundle key: v1-dependencies-{{ checksum "Gemfile.lock" }} run-rubocop: steps: - run: name: Run RuboCop command: | bundle exec rubocop run-tests: steps: - run: name: Run tests command: | TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)" bundle exec rspec \ --format progress \ --format RspecJunitFormatter \ --out test_results/rspec.xml \ --format progress \ $TEST_FILES create-document: steps: - run: name: Create document command: | bundle exec yard collect-reports: steps: # ref:https://circleci.com/docs/ja/2.0/configuration-reference/#store_test_results - store_test_results: path: test_results - store_artifacts: # テスト結果をtest-resultsディレクトリに吐き出す path: test_results destination: test-results - store_artifacts: # カバレッジの結果をcoverage-resultsディレクトリに吐き出す path: coverage destination: coverage-results - store_artifacts: # ドキュメントの結果をyard-resultsディレクトリに吐き出す path: ./doc destination: yard-results # Deploy RubyGems deploy-rubygems: steps: - run: name: Deploy RubyGems command: | curl -u dodonki1223:$RUBYGEMS_PASSWORD https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials git config user.name dodonki1223 git config user.email $RUBYGEMS_EMAIL bundle exec rake build bundle exec rake release jobs: setup: executor: base steps: - checkout - install-bundler - restore-gem-cache - install-gem - save-gem-cache lint: executor: base steps: - checkout - install-bundler - restore-gem-cache - run-rubocop test: executor: base steps: - checkout - install-bundler - restore-gem-cache - run-tests - create-document - collect-reports deploy: executor: base steps: - checkout - install-bundler - restore-gem-cache - deploy-rubygems workflows: version: 2.1 main: jobs: - setup - lint: requires: - setup - test: requires: - setup - deploy: requires: - lint - test filters: branches: only: master # masterブランチの時だけDeployJobを実行するようにする