<commit_before>---
version: 2.1

# To get the list of Gobierto modules
# find test/ -name '*_test.rb' -type f | awk -v FS='/' '{print $3}' | grep gobierto | grep -v test | sort | uniq

aliases:
  - &working_directory ~/gobierto

defaults: &defaults
  working_directory: *working_directory
  docker:
    - image: circleci/ruby:2.7.1-node-browsers
      environment:
        RAILS_ENV: test
        PGHOST: localhost
        PGUSER: gobierto
        # Disable spring so bin/rails works. See: https://github.com/rails/spring/pull/546
        DISABLE_SPRING: true
    - image: postgres:12
      environment:
        POSTGRES_USER: gobierto
        POSTGRES_DB: gobierto_test
        POSTGRES_PASSWORD: <PASSWORD>to
    - image: elasticsearch:2.4.1
    - image: redis:4.0.9

commands:
  restore_bundler_cache:
    steps:
      - restore_cache:
          name: "[Bundler] Restore cache"
          keys:
            - gobierto-bundler-{{ checksum "Gemfile.lock" }}
  restore_yarn_cache:
    steps:
      - restore_cache:
          name: "[Yarn] Restore cache"
          keys:
            - gobierto-yarn-{{ checksum "yarn.lock" }}
  restore_assets_cache:
    steps:
      - restore_cache:
          name: "Restore cached assets"
          keys:
            - gobierto-{{ .Environment.CACHE_VERSION }}-asset-cache-{{ .Branch }}
            - gobierto-{{ .Environment.CACHE_VERSION }}-asset-cache-
  prepare_workspace:
    steps:
      - checkout
      - attach_workspace:
          at: *working_directory
      - restore_bundler_cache
      - restore_yarn_cache
      - restore_assets_cache
      - run: bundle --path vendor/bundle
      - run: yarn install
      # Wait for DB containers to be ready
      - run: dockerize -wait tcp://localhost:5432 -timeout 1m
      - run: dockerize -wait tcp://localhost:9200 -timeout 1m
      - run: dockerize -wait tcp://localhost:6379 -timeout 1m

      # Install postgres 12
      - run: wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
      - run: echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" | sudo tee  /etc/apt/sources.list.d/pgdg.list
      - run: sudo apt update
      - run: sudo apt -y install postgresql-12 postgresql-client-12

      # Copy database config
      - run: cp config/database.yml.example config/database.yml

      # Setup the database
      - run: bin/rails db:create db:migrate

      # Install custom engines
      - run: script/custom_engines_ci_setup

      - run:
          name: Setup budgets seeds
          command: |
            bin/rails gobierto_budgets:elastic_search_schemas:manage:reset
            bin/rails gobierto_budgets:elastic_search_schemas:manage:create
            bin/rails gobierto_budgets:fixtures:load
            echo '::BudgetsSeeder.seed!' | bin/rails c

jobs:
  bundle_dependencies:
    <<: *defaults
    steps:
      - checkout
      - attach_workspace:
          at: *working_directory

      - restore_bundler_cache
      - run:
          name: "[Bundler] Install dependencies"
          command: bundle install --path vendor/bundle --jobs=4 --retry=3  --without development
      - save_cache:
          name: "[Bundler] Cache dependencies"
          key: gobierto-bundler-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle

      - restore_yarn_cache
      - run:
          name: "[Yarn] Install dependencies"
          command: yarn install
      - save_cache:
          name: "[Yarn] Cache dependencies"
          key: gobierto-yarn-{{ checksum "yarn.lock" }}
          paths:
            - node_modules

      # Copy database config
      - run: cp config/database.yml.example config/database.yml

      # Install custom engines
      - run: script/custom_engines_ci_setup

      # Compile I18n JS file
      - run: bin/rails i18n:js:export

      # Compile assets
      - restore_assets_cache
      - run: bin/rails assets:precompile
      - save_cache:
          name: "Cache assets"
          key: gobierto-{{ .Environment.CACHE_VERSION }}-asset-cache-{{ .Branch }}
          paths:
            - public/assets
            - public/packs-test

      - persist_to_workspace:
          root: *working_directory
          paths:
            - db
            - tmp/cache

  tests_admin:
    <<: *defaults
    parallelism: 2
    steps:
      - prepare_workspace
      - run:
          name: Run tests
          command: |
            TEST_FILES="$(find test -path '*gobierto_admin*' -name '*_test.rb' | grep -v 'gobierto_admin\/gobierto_' | circleci tests split --split-by=timings)"
            bin/rails test $TEST_FILES
      - store_test_results:
          path: test/reports

  tests_attachments:
    <<: *defaults
    steps:<commit_msg>Try to prevent cache re-compile<commit_after>---
version: 2.1

# To get the list of Gobierto modules
# find test/ -name '*_test.rb' -type f | awk -v FS='/' '{print $3}' | grep gobierto | grep -v test | sort | uniq

aliases:
  - &working_directory ~/gobierto

defaults: &defaults
  working_directory: *working_directory
  docker:
    - image: circleci/ruby:2.7.1-node-browsers
      environment:
        RAILS_ENV: test
        PGHOST: localhost
        PGUSER: gobierto
        # Disable spring so bin/rails works. See: https://github.com/rails/spring/pull/546
        DISABLE_SPRING: true
    - image: postgres:12
      environment:
        POSTGRES_USER: gobierto
        POSTGRES_DB: gobierto_test
        POSTGRES_PASSWORD: <PASSWORD>
    - image: elasticsearch:2.4.1
    - image: redis:4.0.9

commands:
  restore_bundler_cache:
    steps:
      - restore_cache:
          name: "[Bundler] Restore cache"
          keys:
            - gobierto-bundler-{{ checksum "Gemfile.lock" }}
  restore_yarn_cache:
    steps:
      - restore_cache:
          name: "[Yarn] Restore cache"
          keys:
            - gobierto-yarn-{{ checksum "yarn.lock" }}
  restore_assets_cache:
    steps:
      - restore_cache:
          name: "Restore cached assets"
          keys:
            - gobierto-{{ .Environment.CACHE_VERSION }}-asset-cache-{{ .Branch }}
            - gobierto-{{ .Environment.CACHE_VERSION }}-asset-cache-
  prepare_workspace:
    steps:
      - checkout
      - attach_workspace:
          at: *working_directory
      - restore_bundler_cache
      - restore_yarn_cache
      - restore_assets_cache
      - run: bundle --path vendor/bundle
      - run: yarn install
      # Wait for DB containers to be ready
      - run: dockerize -wait tcp://localhost:5432 -timeout 1m
      - run: dockerize -wait tcp://localhost:9200 -timeout 1m
      - run: dockerize -wait tcp://localhost:6379 -timeout 1m

      # Install postgres 12
      - run: wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
      - run: echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" | sudo tee  /etc/apt/sources.list.d/pgdg.list
      - run: sudo apt update
      - run: sudo apt -y install postgresql-12 postgresql-client-12

      # Copy database config
      - run: cp config/database.yml.example config/database.yml

      # Setup the database
      - run: bin/rails db:create db:migrate

      # Install custom engines
      - run: script/custom_engines_ci_setup

      - run:
          name: Setup budgets seeds
          command: |
            bin/rails gobierto_budgets:elastic_search_schemas:manage:reset
            bin/rails gobierto_budgets:elastic_search_schemas:manage:create
            bin/rails gobierto_budgets:fixtures:load
            echo '::BudgetsSeeder.seed!' | bin/rails c

jobs:
  bundle_dependencies:
    <<: *defaults
    steps:
      - checkout
      - attach_workspace:
          at: *working_directory

      - restore_bundler_cache
      - run:
          name: "[Bundler] Install dependencies"
          command: bundle install --path vendor/bundle --jobs=4 --retry=3  --without development
      - save_cache:
          name: "[Bundler] Cache dependencies"
          key: gobierto-bundler-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle

      - restore_yarn_cache
      - run:
          name: "[Yarn] Install dependencies"
          command: yarn install
      - save_cache:
          name: "[Yarn] Cache dependencies"
          key: gobierto-yarn-{{ checksum "yarn.lock" }}
          paths:
            - node_modules

      # Copy database config
      - run: cp config/database.yml.example config/database.yml

      # Install custom engines
      - run: script/custom_engines_ci_setup

      # Compile I18n JS file
      - run: bin/rails i18n:js:export

      # Compile assets
      - restore_assets_cache
      - run: bin/rails assets:precompile
      - save_cache:
          name: "Cache assets"
          key: gobierto-{{ .Environment.CACHE_VERSION }}-asset-cache-{{ .Branch }}
          paths:
            - public/assets
            - public/packs-test
            - tmp/cache/webpacker

      - persist_to_workspace:
          root: *working_directory
          paths:
            - db

  tests_admin:
    <<: *defaults
    parallelism: 2
    steps:
      - prepare_workspace
      - run:
          name: Run tests
          command: |
            TEST_FILES="$(find test -path '*gobierto_admin*' -name '*_test.rb' | grep -v 'gobierto_admin\/gobierto_' | circleci tests split --split-by=timings)"
            bin/rails test $TEST_FILES
      - store_test_results:
          path: test/reports

  tests_attachments:
    <<: *defaults
    steps:
{'fraction_non_alphanumeric': 0.10297531124709855, 'fraction_numerical': 0.009917704156995147, 'mean_word_length': 1.9987345776652958, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6159074', 'n_tokens_mistral': 3051, 'n_tokens_neox': 2898, 'n_words': 687}