version: 2.1

install: &install
  name: Install bundle
  command: |
            gem install bundler
            bundle install --path vendor/bundle

missingdeps: &missingdeps
  name: Install missing dependecies
  command: |
            cat /etc/os-release
            printf "deb http://deb.debian.org/debian buster main\ndeb http://security.debian.org buster/updates main\ndeb-src http://security.debian.org buster/updates main" > /tmp/sources.list
            sudo cp /tmp/sources.list /etc/apt/sources.list
            sudo apt-get update
            sudo apt-get install cmake libicu-dev libssl-dev
  
test: &test
  name: Test bundle
  command: bundle exec rake test

executors:
  ruby-2-4:
    docker:
      - image: circleci/ruby:2.4.6
  ruby-2-5:
    docker:
      - image: circleci/ruby:2.5.5
  ruby-2-6:
    docker:
      - image: circleci/ruby:2.6.3
jobs:
  "ruby-test":
    parameters:
      ruby-version:
        type: executor
    executor: << parameters.ruby-version >>
    working_directory: ~/fluent-plugin-kubernetes_metadata_filter
    steps:
      - run: *missingdeps
      - checkout
      - run: *install
      - run: *test
      - store_test_results:
            path: coverage
      - store_artifacts:
            path: coverage

workflows:
  "test_multiple_ruby_versions":
    jobs:
      - ruby-test:
          ruby-version: ruby-2-4
      - ruby-test:
          ruby-version: ruby-2-5
      - ruby-test:
          ruby-version: ruby-2-6
