<commit_before>version: 2.1
# This CircleCI orb doesn't seem to work, so I gave up:
# orbs:
#   browser-tools: circleci/browser-tools@1.1.1
# When I try to later run "browser-tools/install-browser-tools" or similar,
# CircleCI reports that the file doesn't exist (which is true).
# It's not clear *why* the file doesn't exist. So we instead force-install
# a browser for testing below.
jobs:
  build:
    working_directory: ~/coreinfrastructure/best-practices-badge
    parallelism: 1
    shell: /bin/bash --login
    environment:
      CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
      CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
    docker:
    - image: drdavidawheeler/cii-bestpractices:3.0.1-browsers
      environment:
        PG_HOST: localhost
        PG_USER: ubuntu
        RAILS_ENV: test
        RACK_ENV: test
    - image: circleci/postgres:11.5-ram
      environment:
        POSTGRES_USER: ubuntu
        POSTGRES_DB: circle_ruby_test
    steps:
    - checkout
    - run: pwd
    - run: ls -l
    # This should install the orb, but it doesn't work.
    # - run:
    #     name: Install browser tools
    #     command: browser-tools/install-browser-tools
    #
    # We instead manually force installation of Chrome using a code
    # snippet from the browser tools. See:
    # https://github.com/CircleCI-Public/browser-tools-orb/blob/master/src/commands/install-chrome.yml#L131
    - run:
        name: Install Chrome
        command: |
          SUDO='sudo'
          CHROME_VERSION='latest'
          if [[ "$CHROME_VERSION" == "latest" ]]; then
            CHROME_URL="https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"
          else
            CHROME_URL="https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}-1_amd64.deb"
          fi
          curl --silent --show-error --location --fail --retry 3 \
            --output google-chrome.deb $CHROME_URL
          $SUDO apt-get update
          # The pipe will install any dependencies missing
          $SUDO dpkg -i google-chrome.deb || $SUDO apt-get -fy install
          rm -rf google-chrome.deb
          $SUDO sed -i 's|HERE/chrome"|HERE/chrome" --disable-setuid-sandbox --no-sandbox|g' "/opt/google/chrome/google-chrome"
          which google-chrome
          google-chrome --version
    # Prepare for artifact and test results
    - run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
    # Force cleanup to make deterministic.
    # See https://circleci.com/docs/2.0/caching
    # - run: bundle clean --force
    # Dependencies
    # Restore the dependency cache
    - restore_cache:
        keys:
        # Find the most recently generated cache used
        # Find a cache corresponding to this particular Gemfile.lock checksum
        - v7-dep-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
        - v7-dep-{{ arch }}-{{ .Branch }}-
        - v7-dep-{{ arch }}-
        # This was suggested, but it seems like a bad idea to me:
        # - v7-dep-
    # This would show what we restored
    # - run: find ~/.rubygems || true
    - run:
        name: Update Rubygems
        command: sudo gem update --system --silent --no-document
        environment:
          REALLY_GEM_UPDATE_SYSTEM: 1
    - run:
        name: Update bundler to match Gemfile.lock
        command: >
          sudo sh -c 'yes | gem install bundler --force --no-document
          -v "$(cat Gemfile.lock | tail -1 | tr -d \\\\" \\\\")"'
    - run:
        name: Bundler Version
        command: bundle --version
    - run:
        name: Install Bundle
        # Note: --path=vendor/bundle removed, we don't need it.
        command: >
          bundle check ||
          bundle install --jobs=4 --retry=3
    - run:
       name: Update Chromedriver
       command: bundle exec rake update_chromedriver
    # Here's how we could show more:
    # - run: find ~/.rubygems || true
    # - run: find ~/.bundle || true
    # - run: find ~/.rbenv || true
    # - run: find vendor/bundle || true
    # - run: find ~ -name "*rack-timeout*" || true
    # Save dependency cache
    - save_cache:
        key: v7-dep-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
        paths:
          - ~/.rubygems
          - ~/.bundle
          # Not used in current config; we include these just in case they
          # get used later:
          - ~/.rbenv/versions
          - vendor/bundle
    - run:
        name: Configure database
        command: |
          cd config/
          cp {database.ci,database}.yml
    - run:
        name: Create database
        command: bundle exec rake db:create db:schema:load --trace
    # Start testing
    - run:
        name: Check for whitespace issues.
        command: '[[ ! -s "$(git rev-parse --git-dir)/shallow" ]] || git fetch --unshallow'
    - run:
        name:  Run test suite (both system and non-system tests)
        command: bundle exec rails test:system test
    - run:
        name:  Run pronto GitHub
        command: >
          bundle exec pronto run -f github text
          -c=$(git log --pretty=format:%H | tail -1) --exit-code
    # Temporarily disable bundle doctor; trying to run it produces an error.
    # - run: bundle exec bundle doctor
    # Ignore CVE-2015-9284 (omniauth); We have mitigated this with a
    # third-party countermeasure (omniauth-rails_csrf_protection) in:
    # https://github.com/coreinfrastructure/best-practices-badge/pull/1298
    # - run: bundle exec bundle audit check --update
    - run: bundle exec bundle audit check --update --ignore CVE-2015-9284
    - run: bundle exec rake whitespace_check
    - run: bundle exec rake license_finder_report.html
    - run: script/report_code_statistics
    # Save test results
    - store_test_results:
        path: /tmp/circleci-test-results
    # Save artifacts
    - store_artifacts:
        path: /tmp/circleci-artifacts
    - store_artifacts:
        path: coverage
    - store_artifacts:
        path: license_finder_report.html
    - store_artifacts:
        path: log/test.log
    - store_artifacts:
        path: tmp/capybara
    - store_artifacts:
        path: test/html_reports
    - store_artifacts:
        path: /tmp/circleci-test-results
  # I haven't found a reliable way to calculate HEROKU_APP just once,
  # so it gets recalculated. This approach still greatly reduces
  # duplication.
  deploy:
    docker:
      - image: buildpack-deps:bionic
    steps:
      - checkout
      - run:
          name: Deploy to Heroku
          command: |
            echo 'heroku.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAu8erSx6jh+8ztsfHwkNeFr/SZaSOcvoa8AyMpaerGIPZDB2TKNgNkMSYTLYGDK2ivsqXopo2W7dpQRBIVF80q9mNXy5tbt1WE04gbOBB26Wn2hF4bk3Tu+BNMFbvMjPbkVlC2hcFuQJdH4T2i/dtauyTpJbD/6ExHR9XYVhdhdMs0JsjP/Q5FNoWh2ff9YbZVpDQSTPvusUp4liLjPfa/i0t+2LpNCeWy8Y+V9gUlDWiyYwrfMVI0UwNCZZKHs1Unpc11/4HLitQRtvuk0Ot5qwwBxbmtvCDKZvj1aFBid71/mYdGRPYZMIxq1zgP1acePC1zfTG/lvuQ7d0Pe0kaw==' >> ~/.ssh/known_hosts
            export HEROKU_APP="$CIRCLECI_BRANCH"-bestpractices
            if [ "$HEROKU_APP" = 'main-bestpractices' ] ; then export HEROKU_APP='master-bestpractices'; fi
            echo "Deploying to $HEROKU_APP"
            heroku --app "$HEROKU_APP" maintenance:on
            # Give production site a few seconds to complete ongoing work.
            [ "$HEROKU_APP" != 'production-bestpractices' ] || sleep 10<commit_msg>Install heroku CLI during CircleCI steps<commit_after>version: 2.1
# This CircleCI orb doesn't seem to work, so I gave up:
# orbs:
#   browser-tools: circleci/browser-tools@1.1.1
# When I try to later run "browser-tools/install-browser-tools" or similar,
# CircleCI reports that the file doesn't exist (which is true).
# It's not clear *why* the file doesn't exist. So we instead force-install
# a browser for testing below.
jobs:
  build:
    working_directory: ~/coreinfrastructure/best-practices-badge
    parallelism: 1
    shell: /bin/bash --login
    environment:
      CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
      CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
    docker:
    - image: drdavidawheeler/cii-bestpractices:3.0.1-browsers
      environment:
        PG_HOST: localhost
        PG_USER: ubuntu
        RAILS_ENV: test
        RACK_ENV: test
    - image: circleci/postgres:11.5-ram
      environment:
        POSTGRES_USER: ubuntu
        POSTGRES_DB: circle_ruby_test
    steps:
    - checkout
    - run: pwd
    - run: ls -l
    # This should install the orb, but it doesn't work.
    # - run:
    #     name: Install browser tools
    #     command: browser-tools/install-browser-tools
    #
    # We instead manually force installation of Chrome using a code
    # snippet from the browser tools. See:
    # https://github.com/CircleCI-Public/browser-tools-orb/blob/master/src/commands/install-chrome.yml#L131
    - run:
        name: Install Chrome
        command: |
          SUDO='sudo'
          CHROME_VERSION='latest'
          if [[ "$CHROME_VERSION" == "latest" ]]; then
            CHROME_URL="https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"
          else
            CHROME_URL="https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}-1_amd64.deb"
          fi
          curl --silent --show-error --location --fail --retry 3 \
            --output google-chrome.deb $CHROME_URL
          $SUDO apt-get update
          # The pipe will install any dependencies missing
          $SUDO dpkg -i google-chrome.deb || $SUDO apt-get -fy install
          rm -rf google-chrome.deb
          $SUDO sed -i 's|HERE/chrome"|HERE/chrome" --disable-setuid-sandbox --no-sandbox|g' "/opt/google/chrome/google-chrome"
          which google-chrome
          google-chrome --version
    # Prepare for artifact and test results
    - run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
    # Force cleanup to make deterministic.
    # See https://circleci.com/docs/2.0/caching
    # - run: bundle clean --force
    # Dependencies
    # Restore the dependency cache
    - restore_cache:
        keys:
        # Find the most recently generated cache used
        # Find a cache corresponding to this particular Gemfile.lock checksum
        - v7-dep-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
        - v7-dep-{{ arch }}-{{ .Branch }}-
        - v7-dep-{{ arch }}-
        # This was suggested, but it seems like a bad idea to me:
        # - v7-dep-
    # This would show what we restored
    # - run: find ~/.rubygems || true
    - run:
        name: Update Rubygems
        command: sudo gem update --system --silent --no-document
        environment:
          REALLY_GEM_UPDATE_SYSTEM: 1
    - run:
        name: Update bundler to match Gemfile.lock
        command: >
          sudo sh -c 'yes | gem install bundler --force --no-document
          -v "$(cat Gemfile.lock | tail -1 | tr -d \\\\" \\\\")"'
    - run:
        name: Bundler Version
        command: bundle --version
    - run:
        name: Install Bundle
        # Note: --path=vendor/bundle removed, we don't need it.
        command: >
          bundle check ||
          bundle install --jobs=4 --retry=3
    - run:
       name: Update Chromedriver
       command: bundle exec rake update_chromedriver
    # Here's how we could show more:
    # - run: find ~/.rubygems || true
    # - run: find ~/.bundle || true
    # - run: find ~/.rbenv || true
    # - run: find vendor/bundle || true
    # - run: find ~ -name "*rack-timeout*" || true
    # Save dependency cache
    - save_cache:
        key: v7-dep-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
        paths:
          - ~/.rubygems
          - ~/.bundle
          # Not used in current config; we include these just in case they
          # get used later:
          - ~/.rbenv/versions
          - vendor/bundle
    - run:
        name: Configure database
        command: |
          cd config/
          cp {database.ci,database}.yml
    - run:
        name: Create database
        command: bundle exec rake db:create db:schema:load --trace
    # Start testing
    - run:
        name: Check for whitespace issues.
        command: '[[ ! -s "$(git rev-parse --git-dir)/shallow" ]] || git fetch --unshallow'
    - run:
        name:  Run test suite (both system and non-system tests)
        command: bundle exec rails test:system test
    - run:
        name:  Run pronto GitHub
        command: >
          bundle exec pronto run -f github text
          -c=$(git log --pretty=format:%H | tail -1) --exit-code
    # Temporarily disable bundle doctor; trying to run it produces an error.
    # - run: bundle exec bundle doctor
    # Ignore CVE-2015-9284 (omniauth); We have mitigated this with a
    # third-party countermeasure (omniauth-rails_csrf_protection) in:
    # https://github.com/coreinfrastructure/best-practices-badge/pull/1298
    # - run: bundle exec bundle audit check --update
    - run: bundle exec bundle audit check --update --ignore CVE-2015-9284
    - run: bundle exec rake whitespace_check
    - run: bundle exec rake license_finder_report.html
    - run: script/report_code_statistics
    # Save test results
    - store_test_results:
        path: /tmp/circleci-test-results
    # Save artifacts
    - store_artifacts:
        path: /tmp/circleci-artifacts
    - store_artifacts:
        path: coverage
    - store_artifacts:
        path: license_finder_report.html
    - store_artifacts:
        path: log/test.log
    - store_artifacts:
        path: tmp/capybara
    - store_artifacts:
        path: test/html_reports
    - store_artifacts:
        path: /tmp/circleci-test-results
  # I haven't found a reliable way to calculate HEROKU_APP just once,
  # so it gets recalculated. This approach still greatly reduces
  # duplication.
  deploy:
    docker:
      - image: buildpack-deps:bionic
    steps:
      - checkout
      - run:
          name: Install Heroku CLI tools (to easily control maintenance mode)
          command: |
            sudo snap install --classic heroku
      - run:
          name: Deploy to Heroku
          command: |
            echo 'heroku.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAu8erSx6jh+8ztsfHwkNeFr/SZaSOcvoa8AyMpaerGIPZDB2TKNgNkMSYTLYGDK2ivsqXopo2W7dpQRBIVF80q9mNXy5tbt1WE04gbOBB26Wn2hF4bk3Tu+BNMFbvMjPbkVlC2hcFuQJdH4T2i/dtauyTpJbD/6ExHR9XYVhdhdMs0JsjP/Q5FNoWh2ff9YbZVpDQSTPvusUp4liLjPfa/i0t+2LpNCeWy8Y+V9gUlDWiyYwrfMVI0UwNCZZKHs1Unpc11/4HLitQRtvuk0Ot5qwwBxbmtvCDKZvj1aFBid71/mYdGRPYZMIxq1zgP1acePC1zfTG/lvuQ7d0Pe0kaw==' >> ~/.ssh/known_hosts
            export HEROKU_APP="$CIRCLECI_BRANCH"-bestpractices
            if [ "$HEROKU_APP" = 'main-bestpractices' ] ; then export HEROKU_APP='master-bestpractices'; fi
            echo "Deploying to $HEROKU_APP"
            heroku --app "$HEROKU_APP" maintenance:on
            # Give production site a few seconds to complete ongoing work.
            [ "$HEROKU_APP" != 'production-bestpractices' ] || sleep 10
{'fraction_non_alphanumeric': 0.10355187608492455, 'fraction_numerical': 0.014421151021498197, 'mean_word_length': 2.2478317432784043, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, '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': '7108183', 'n_tokens_mistral': 5081, 'n_tokens_neox': 4831, 'n_words': 1253}