FarmBot/Farmbot-Web-App

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
version: 2.1

executors:
  build-executor:
    machine:
      image: ubuntu-2404:current
    resource_class: xlarge
    working_directory: /home/circleci/project

commands:
  build-commands:
    steps:
      - checkout
      - restore_cache:
          keys:
            - cache-v1-{{ .Revision }}-{{ .Environment.CIRCLE_WORKFLOW_ID }}
      - run:
          name: After cache restore
          command: |
            git clean -xdn
            mkdir -p docker_cache
            ls docker_cache
            #sudo docker images
            #if [ -f docker_cache/images.tar.gz ]; then gunzip -c docker_cache/images.tar.gz | sudo docker load; fi
      - run:
          name: Build and Install Deps
          command: |
            mv .circleci/circle_envs .env
            echo -e '\ndocker_volumes/db/pg_wal/*' >> .dockerignore
            sudo docker compose run web gem install bundler
            sudo docker compose run web bundle install
            sudo docker compose run web npm install
            sudo docker compose run web bundle exec rails db:create
            sudo docker compose run web bundle exec rails db:migrate
            sudo docker compose run web rake keys:generate
      - run:
          name: After cache update
          command: |
            mkdir -p /tmp/test-results
            git clean -xdn
            ls docker_cache
            #sudo docker images
            #if [ ! -f docker_cache/images.tar.gz ]; then sudo docker save $(sudo docker images ruby -q) | gzip > docker_cache/images.tar.gz; fi
      # - save_cache:
      #     key: cache-v1-{{ .Revision }}-{{ .Environment.CIRCLE_WORKFLOW_ID }}
      #     paths:
      #       - docker_volumes
      #       - node_modules
      #       - docker_cache
  rspec-commands:
    steps:
      - run:
          name: Run Ruby Tests
          command: |
            sudo docker compose run web rspec spec --format progress --format RspecJunitFormatter --out /tmp/test-results/rspec/rspec.xml
      - run:
          name: Upload to Codecov
          command: |
            curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import
            curl -Os https://uploader.codecov.io/latest/linux/codecov
            curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
            curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig
            gpgv codecov.SHA256SUM.sig codecov.SHA256SUM
            shasum -a 256 -c codecov.SHA256SUM
            chmod +x codecov
            ./codecov -t $CODECOV_TOKEN -f coverage_api/coverage.xml
  jest-commands:
    steps:
      - run:
          name: Run JS tests
          command: |
            sudo docker compose run web npm run test-slow -- -c .circleci/jest-ci.config.js
            echo 'export COVERAGE_AVAILABLE=true' >> $BASH_ENV
  lint-commands:
    steps:
      - run:
          name: Run JS Linters
          command: |
            sudo docker compose run web npm run linters
          when: always
  coverage-commands:
    steps:
      - run:
          name: Check coverage status
          command: |
            sudo docker compose run -e CIRCLE_SHA1="$CIRCLE_SHA1" -e CIRCLE_BRANCH="$CIRCLE_BRANCH" -e CIRCLE_PULL_REQUEST="$CIRCLE_PULL_REQUEST" web rake coverage:run || [ $CIRCLE_BRANCH == "staging" ]
          when: always
      - run:
          name: Report coverage to Coveralls
          command: |
            if [ "$CIRCLE_BRANCH" == "staging" ]; then set +eo pipefail; fi
            if [ "$COVERAGE_AVAILABLE" ] && [ "$COVERALLS_REPO_TOKEN" ]
            then
              curl -sLO https://github.com/coverallsapp/coverage-reporter/releases/latest/download/coveralls-linux.tar.gz
              curl -sLO https://github.com/coverallsapp/coverage-reporter/releases/latest/download/coveralls-checksums.txt
              cat coveralls-checksums.txt | grep coveralls-linux.tar.gz | sha256sum --check
              tar -xzf coveralls-linux.tar.gz
              ./coveralls report coverage_fe/lcov.info
            fi
            if [ "$CIRCLE_BRANCH" == "staging" ]; then echo; fi
          when: always # change to `on_success` for a stricter comparison


workflows:
  version: 2
  build_and_test:
    jobs:
      #- build
      - all
      #- test-api:
      #    requires:
      #      - build
      #- run-linters:
      #    requires:
      #      - build
      #- test-fe:
      #    requires:
      #      - build

jobs:
  build:
    executor: build-executor
    steps:
      - build-commands
  all:
    executor: build-executor
    steps:
      - build-commands
      - rspec-commands
      - lint-commands
      - jest-commands
      - store_test_results:
          path: /tmp/test-results
      - coverage-commands
  test-api:
    executor: build-executor
    steps:
      - build-commands
      - rspec-commands
      - store_test_results:
          path: /tmp/test-results
  run-linters:
    executor: build-executor
    steps:
      - build-commands
      - lint-commands
  test-fe:
    executor: build-executor
    parallelism: 4
    steps:
      - build-commands
      - run:
          name: Run JS Tests
          command: |
            circleci tests glob **/__tests__/**/*.ts* | circleci tests split > /tmp/tests-to-run
            sudo docker compose run web npm run test-very-slow -- -c .circleci/jest-ci.config.js $(cat /tmp/tests-to-run)
      - store_test_results:
          path: /tmp/test-results