Hanamiのcircle ci設定例


ほぼほぼcirciel ci公式のrubyの例のコピペですが覚書としておいておきます。

version: 2 # use CircleCI 2.0
jobs: # a collection of steps
  build: # runs not using Workflows must have a `build` job as entry point
    parallelism: 1
    docker: # run the steps with Docker
      - image: circleci/ruby:2.6.1 # ...with this image as the primary container; this is where all `steps` will run
        environment: # environment variables for primary container
          BUNDLE_JOBS: 3
          BUNDLE_RETRY: 3
          BUNDLE_PATH: vendor/bundle
          PGHOST: 127.0.0.1
          PGUSER: postgres
          HANAMI_ENV: test
      - image: circleci/postgres:9.5-alpine # database image
        environment: # environment variables for database
          POSTGRES_USER: postgres
          POSTGRES_DB: bookshelf_test
          POSTGRES_PASSWORD: "postgres"
    steps: # a collection of executable commands
      - checkout # special step to check out source code to working directory

      # Which version of bundler?
      - run:
          name: Which bundler?
          command: bundle -v

      # Restore bundle cache
      # Read about caching dependencies: https://circleci.com/docs/2.0/caching/
      - restore_cache:
          keys:
            - bookshelf-v2-{{ checksum "Gemfile.lock" }}
            - bookshelf-v2-

      - run: # Install Ruby dependencies
          name: Bundle Install
          command: bundle check || bundle install

      - run: sudo apt update
      - run: sudo apt install -y postgresql-client || true

      # Store bundle cache for Ruby dependencies
      - save_cache:
          key: bookshelf-v2-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle

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

      - run:
          name: Database setup
          command: bundle exec hanami db prepare

      - run:
          name: Run rspec
          command: bundle exec rspec

      # Save test results for timing analysis
      - store_test_results: # Upload test results for display in Test Summary: https://circleci.com/docs/2.0/collect-test-data/
          path: test_results
      # See https://circleci.com/docs/2.0/deployment-integrations/ for example deploy configs

参考 : https://circleci.com/docs/2.0/language-ruby/#sample-configuration