podemos-info/participa2

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
---

version: 2

jobs:
  coverage-setup:
    docker:
      - image: circleci/ruby:2.5.1

    steps:
      - run:
          name: Download Code Climate test-reporter
          command: |
            curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-0.6.3-linux-amd64 > /tmp/cc-test-reporter
            chmod +x /tmp/cc-test-reporter

      - persist_to_workspace:
          root: /tmp
          paths:
            - cc-test-reporter

  coverage-upload:
    docker:
      - image: circleci/ruby:2.5.1

    steps:
      - attach_workspace:
          at: /tmp

      - run:
          name: Upload coverage results to Code Climate
          command: |
            /tmp/cc-test-reporter sum-coverage /tmp/codeclimate.*.json --parts 5 --output /tmp/codeclimate.total.json
            /tmp/cc-test-reporter upload-coverage --input /tmp/codeclimate.total.json

  main:
    docker:
      - image: decidim/decidim@sha256:dd56d61390f588f6d3abf192049e63ef15d43a895d06a55979da4541a649b98e
        environment:
          DATABASE_USERNAME: postgres
          CENSUS_URL: http://mycensus:3001

      - image: postgres
        environment:
          POSTGRES_USER: postgres

    steps:
      - checkout

      - attach_workspace:
          at: /tmp

      - restore_cache:
          keys:
            - bundler-dependencies-{{ checksum "Gemfile.lock" }}

      - run:
          name: Install dependencies
          command: bundle install --path /home/circleci/project/vendor/bundle

      - save_cache:
          key: bundler-dependencies-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle

      - restore_cache:
          keys:
            - npm-dependencies-{{ checksum "package-lock.json" }}

      - run:
          name: Install npm dependencies
          command: npm install

      - save_cache:
          key: npm-dependencies-{{ checksum "package-lock.json" }}
          paths:
            - node_modules

      - run:
          name: Create and migrate DB
          command: bin/rails db:create db:migrate

      - run:
          name: Run tests
          command: SIMPLECOV=true bin/rspec

      - run:
          name: Generate code coverage report
          command: /tmp/cc-test-reporter format-coverage --output /tmp/codeclimate.$CIRCLE_JOB.json

      - persist_to_workspace:
          root: /tmp
          paths:
            - codeclimate.*.json

      - run:
          name: Run rubocop
          command: bin/rubocop

      - run:
          name: Run npm lints
          command: npm run lint

      - store_artifacts:
          path: /root/project/decidim-module-census_connector/spec/decidim_dummy_app/tmp/screenshots

  census_connector:
    docker:
      - image: decidim/decidim@sha256:dd56d61390f588f6d3abf192049e63ef15d43a895d06a55979da4541a649b98e
        environment:
          DATABASE_USERNAME: postgres
          CENSUS_URL: http://mycensus:3001

      - image: postgres
        environment:
          POSTGRES_USER: postgres

    steps:
      - checkout

      - attach_workspace:
          at: /tmp

      - restore_cache:
          keys:
            - bundler-dependencies-{{ checksum "Gemfile.lock" }}

      - run:
          name: Install dependencies
          command: bundle install

      - save_cache:
          key: bundler-dependencies-{{ checksum "Gemfile.lock" }}
          paths:
            - /usr/local/bundle

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

      - run:
          name: Generate test app
          command: cd decidim-module-census_connector && bundle exec rake test_app

      - run:
          name: Run RSpec tests
          command: cd decidim-module-census_connector && SIMPLECOV=true bundle exec rspec

      - run:
          name: Generate code coverage report
          command: /tmp/cc-test-reporter format-coverage --output /tmp/codeclimate.$CIRCLE_JOB.json

      - persist_to_workspace:
          root: /tmp
          paths:
            - codeclimate.*.json

      - store_artifacts:
          path: /root/project/decidim-module-census_connector/spec/decidim_dummy_app/tmp/screenshots

  crowdfundings:
    docker:
      - image: decidim/decidim@sha256:dd56d61390f588f6d3abf192049e63ef15d43a895d06a55979da4541a649b98e
        environment:
          DATABASE_USERNAME: postgres
          CENSUS_URL: http://mycensus:3001

      - image: postgres
        environment:
          POSTGRES_USER: postgres

    steps:
      - checkout

      - attach_workspace:
          at: /tmp

      - restore_cache:
          keys:
            - bundler-dependencies-{{ checksum "Gemfile.lock" }}

      - run:
          name: Install dependencies
          command: bundle install

      - save_cache:
          key: bundler-dependencies-{{ checksum "Gemfile.lock" }}
          paths:
            - /usr/local/bundle

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

      - run:
          name: Generate test app
          command: cd decidim-module-crowdfundings && bundle exec rake test_app

      - run:
          name: Run RSpec tests
          command: cd decidim-module-crowdfundings && SIMPLECOV=true bundle exec rspec

      - run:
          name: Generate code coverage report
          command: /tmp/cc-test-reporter format-coverage --output /tmp/codeclimate.$CIRCLE_JOB.json

      - persist_to_workspace:
          root: /tmp
          paths:
            - codeclimate.*.json

      - store_artifacts:
          path: /root/project/decidim-module-crowdfundings/spec/decidim_dummy_app/tmp/screenshots

  gravity_forms:
    docker:
      - image: decidim/decidim@sha256:dd56d61390f588f6d3abf192049e63ef15d43a895d06a55979da4541a649b98e
        environment:
          DATABASE_USERNAME: postgres

      - image: postgres
        environment:
          POSTGRES_USER: postgres

    steps:
      - checkout

      - attach_workspace:
          at: /tmp

      - restore_cache:
          keys:
            - bundler-dependencies-{{ checksum "Gemfile.lock" }}

      - run:
          name: Install dependencies
          command: bundle install

      - save_cache:
          key: bundler-dependencies-{{ checksum "Gemfile.lock" }}
          paths:
            - /usr/local/bundle

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

      - run:
          name: Generate test app
          command: cd decidim-module-gravity_forms && bundle exec rake test_app

      - run:
          name: Run RSpec tests
          command: cd decidim-module-gravity_forms && SIMPLECOV=true bundle exec rspec

      - run:
          name: Generate code coverage report
          command: /tmp/cc-test-reporter format-coverage --output /tmp/codeclimate.$CIRCLE_JOB.json

      - persist_to_workspace:
          root: /tmp
          paths:
            - codeclimate.*.json

      - store_artifacts:
          path: /root/project/decidim-module-gravity_forms/spec/decidim_dummy_app/tmp/screenshots

  votings:
    docker:
      - image: decidim/decidim@sha256:dd56d61390f588f6d3abf192049e63ef15d43a895d06a55979da4541a649b98e
        environment:
          DATABASE_USERNAME: postgres

      - image: postgres
        environment:
          POSTGRES_USER: postgres

    steps:
      - checkout

      - attach_workspace:
          at: /tmp

      - restore_cache:
          keys:
            - bundler-dependencies-{{ checksum "Gemfile.lock" }}

      - run:
          name: Install dependencies
          command: bundle install

      - save_cache:
          key: bundler-dependencies-{{ checksum "Gemfile.lock" }}
          paths:
            - /usr/local/bundle

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

      - run:
          name: Generate test app
          command: cd decidim-module-votings && bundle exec rake test_app

      - run:
          name: Run RSpec tests
          command: cd decidim-module-votings && SIMPLECOV=true bundle exec rspec

      - run:
          name: Generate code coverage report
          command: /tmp/cc-test-reporter format-coverage --output /tmp/codeclimate.$CIRCLE_JOB.json

      - persist_to_workspace:
          root: /tmp
          paths:
            - codeclimate.*.json

      - store_artifacts:
          path: /root/project/decidim-module-votings/spec/decidim_dummy_app/tmp/screenshots

  deploy:
    docker:
      - image: decidim/decidim@sha256:dd56d61390f588f6d3abf192049e63ef15d43a895d06a55979da4541a649b98e
        environment:
          DATABASE_USERNAME: postgres
          CENSUS_URL: http://mycensus:3001

    steps:
      - checkout

      - attach_workspace:
          at: /tmp

      - restore_cache:
          keys:
            - bundler-dependencies-{{ checksum "Gemfile.lock" }}

      - run:
          name: Install dependencies
          command: bundle install

      - save_cache:
          key: bundler-dependencies-{{ checksum "Gemfile.lock" }}
          paths:
            - /usr/local/bundle

      - add_ssh_keys:
          fingerprints:
            - "89:77:d0:7d:bd:74:28:09:09:b0:d7:25:3a:e7:3e:89"

      - deploy:
          command: bin/deploy-staging.sh

workflows:
  version: 2

  test_and_deploy:
    jobs:
      - coverage-setup

      - census_connector:
          requires:
            - coverage-setup

      - crowdfundings:
          requires:
            - coverage-setup

      - gravity_forms:
          requires:
            - coverage-setup

      - votings:
          requires:
            - coverage-setup

      - main:
          requires:
            - coverage-setup

      - coverage-upload:
          requires:
            - census_connector
            - crowdfundings
            - gravity_forms
            - votings
            - main

      - deploy:
          requires:
            - coverage-upload