From 5a72f4d0c84ca87e5e23e030f87718ace26c4be4 Mon Sep 17 00:00:00 2001 From: Sojan Date: Fri, 7 Mar 2025 02:31:52 -0800 Subject: [PATCH] chore: grok version --- .circleci/config.yml | 231 +++++++++++++++++++------------------------ 1 file changed, 99 insertions(+), 132 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7e2f00c88..3bd146c4a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,197 +3,164 @@ version: 2.1 orbs: node: circleci/node@6.1.0 -parameters: - ruby-version: - type: string - default: "3.3.3" - node-version: - type: string - default: "23.7" - bundler-version: - type: string - default: "2.5.16" - +# Define reusable defaults defaults: &defaults working_directory: ~/build machine: image: ubuntu-2204:2024.05.1 - resource_class: large + resource_class: large environment: RAILS_LOG_TO_STDOUT: false COVERAGE: true LOG_LEVEL: warn - BUNDLE_JOBS: 4 - BUNDLE_RETRY: 3 + parallelism: 4 -caches: - apt-cache: &apt-cache - key: v1-apt-{{ .Branch }}-{{ epoch }} - ruby-cache: &ruby-cache - key: v1-ruby-{{ checksum ".ruby-version" }}-{{ checksum "Gemfile.lock" }} - node-cache: &node-cache - key: v1-node-{{ checksum "package.json" }}-{{ checksum "pnpm-lock.yaml" }} +# Cache keys +cache_keys: &cache_keys + node_cache_key: v1-node-{{ checksum "package.json" }}-{{ checksum "pnpm-lock.yaml" }} + gem_cache_key: v1-gems-{{ checksum "Gemfile" }}-{{ checksum "Gemfile.lock" }} jobs: - setup: + build: <<: *defaults + steps: + # Initial setup - checkout - - restore_cache: *apt-cache - - restore_cache: *ruby-cache - - restore_cache: *node-cache + # Node.js setup with caching - node/install: - node-version: << pipeline.parameters.node-version >> + node-version: '23.7' - node/install-pnpm + - restore_cache: + keys: + - *node_cache_keys - node/install-packages: pkg-manager: pnpm - cache-key: *node-cache - + override-ci-command: pnpm i + - save_cache: + key: *node_cache_keys + paths: + - node_modules + + # System dependencies (combined into one step with caching) + - restore_cache: + keys: + - v1-system-deps-{{ .Environment.CIRCLE_JOB }} - run: - name: Setup System Dependencies + name: Install System Dependencies command: | - sudo apt-get update sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - - sudo apt-get update + sudo apt-get update -y DEBIAN_FRONTEND=noninteractive sudo apt-get install -y \ libpq-dev redis-server postgresql-common postgresql-16 postgresql-16-pgvector \ build-essential git curl libssl-dev zlib1g-dev libreadline-dev libyaml-dev \ openjdk-11-jdk jq software-properties-common ca-certificates imagemagick \ libxml2-dev libxslt1-dev file g++ gcc autoconf gnupg2 patch ruby-dev \ liblzma-dev libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libvips + - save_cache: + key: v1-system-deps-{{ .Environment.CIRCLE_JOB }} + paths: + - /var/cache/apt + # Ruby setup with caching + - restore_cache: + keys: + - v1-rvm-ruby-3.3.3 - run: - name: Install Ruby + name: Install RVM and Ruby command: | + gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB curl -sSL https://get.rvm.io | bash -s stable + echo 'source ~/.rvm/scripts/rvm' >> $BASH_ENV source ~/.rvm/scripts/rvm - rvm install << pipeline.parameters.ruby-version >> - rvm use << pipeline.parameters.ruby-version >> --default - gem install bundler -v << pipeline.parameters.bundler-version >> + rvm install "3.3.3" + rvm use 3.3.3 --default + gem install bundler -v 2.5.16 + - save_cache: + key: v1-rvm-ruby-3.3.3 + paths: + - ~/.rvm + # Bundle install with caching + - restore_cache: + keys: + - *gem_cache_key - run: - name: Install Dependencies + name: Install Ruby Dependencies command: | - bundle config set --local path 'vendor/bundle' - bundle install + source ~/.rvm/scripts/rvm + bundle install --jobs=4 --retry=3 + - save_cache: + key: *gem_cache_key + paths: + - vendor/bundle + # Setup tools - run: - name: Setup Environment + name: Setup Tools command: | + mkdir -p ~/tmp curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ~/tmp/cc-test-reporter chmod +x ~/tmp/cc-test-reporter + curl -L https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/6.3.0/openapi-generator-cli-6.3.0.jar > ~/tmp/openapi-generator-cli-6.3.0.jar + + # Swagger verification + - run: + name: Verify Swagger API Specification + command: | + bundle exec rake swagger:build + git diff --exit-code swagger/swagger.json || (echo "ERROR: swagger.json is out of sync" && exit 1) + java -jar ~/tmp/openapi-generator-cli-6.3.0.jar validate -i swagger/swagger.json + + # Database setup + - run: + name: Database Setup + command: | pg_pass=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 15) sed -i "s/REPLACE_WITH_PASSWORD/${pg_pass}/g" .circleci/setup_chatwoot.sql sudo -u postgres psql -f .circleci/setup_chatwoot.sql cp .env.example .env sed -i '/^FRONTEND_URL/d' .env - sed -i "s|^REDIS_URL=.*|REDIS_URL=redis://localhost:6379|" .env - sed -i "s|^POSTGRES_HOST=.*|POSTGRES_HOST=localhost|" .env - sed -i "s|^POSTGRES_USERNAME=.*|POSTGRES_USERNAME=chatwoot|" .env - sed -i "s|^POSTGRES_PASSWORD=.*|POSTGRES_PASSWORD=${pg_pass}|" .env + sed -i "s|REDIS_URL=.*|REDIS_URL=redis://localhost:6379|" .env + sed -i "s|POSTGRES_HOST=.*|POSTGRES_HOST=localhost|" .env + sed -i "s|POSTGRES_USERNAME=.*|POSTGRES_USERNAME=chatwoot|" .env + sed -i "s|POSTGRES_PASSWORD=.*|POSTGRES_PASSWORD=${pg_pass}|" .env echo "INSTALLATION_ENV=circleci" >> .env bundle exec rails db:chatwoot_prepare - - save_cache: *apt-cache - - save_cache: *ruby-cache - - save_cache: *node-cache - - - persist_to_workspace: - root: ~/build - paths: - - . - - lint: - <<: *defaults - steps: - - attach_workspace: - at: ~/build + # Quality checks - run: - name: Run Linting + name: Run Linting and Security Checks command: | - bundle exec rubocop --parallel + bundle exec bundle audit update && bundle exec bundle audit check -v + bundle exec rubocop pnpm run eslint - bundle exec bundle audit check --update - bundle exec rake swagger:build - curl -L https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/6.3.0/openapi-generator-cli-6.3.0.jar > ~/tmp/openapi-generator-cli.jar - java -jar ~/tmp/openapi-generator-cli.jar validate -i swagger/swagger.json - test-frontend: - <<: *defaults - parallelism: 4 - steps: - - attach_workspace: - at: ~/build + # Tests - run: - name: Run Frontend Tests + name: Run Tests command: | - mkdir -p coverage/frontend - TEST_FILES=$(circleci tests glob "**/*.test.js" | circleci tests split --split-by=timings) - ~/tmp/cc-test-reporter before-build - pnpm run test:coverage -- --test-files="${TEST_FILES}" - ~/tmp/cc-test-reporter format-coverage -t lcov -o "coverage/frontend/codeclimate.frontend_$CIRCLE_NODE_INDEX.json" - - persist_to_workspace: - root: ~/build - paths: - - coverage/frontend - - test-backend: - <<: *defaults - parallelism: 4 - steps: - - attach_workspace: - at: ~/build - - run: - name: Run Backend Tests - command: | - mkdir -p coverage/backend tmp/test-results - TEST_FILES=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings) + mkdir -p ~/build/coverage/{frontend,backend} ~/tmp/test-{results,artifacts} ~/tmp/cc-test-reporter before-build + pnpm run test:coverage + TESTFILES=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings) bundle exec rspec --format progress \ --format RspecJunitFormatter \ - --out tmp/test-results/rspec.$CIRCLE_NODE_INDEX.xml \ - --profile \ - -- ${TEST_FILES} - ~/tmp/cc-test-reporter format-coverage -t simplecov -o "coverage/backend/codeclimate.$CIRCLE_NODE_INDEX.json" + --out ~/tmp/test-results/rspec.xml \ + -- ${TESTFILES} + no_output_timeout: 30m + + # Coverage reporting + - run: + name: Process Test Coverage + command: | + ~/tmp/cc-test-reporter format-coverage -t lcov -o "~/build/coverage/frontend/codeclimate.frontend_$CIRCLE_NODE_INDEX.json" + ~/tmp/cc-test-reporter format-coverage -t simplecov -o "~/build/coverage/backend/codeclimate.$CIRCLE_NODE_INDEX.json" + + # Store results - persist_to_workspace: root: ~/build paths: - - coverage/backend - - tmp/test-results - - report: - <<: *defaults - steps: - - attach_workspace: - at: ~/build - - store_test_results: - path: ~/build/tmp/test-results - - store_artifacts: - path: ~/build/coverage - - run: - name: Upload Coverage - command: | - ~/tmp/cc-test-reporter sum-coverage coverage/*/codeclimate.*.json -p 8 -o coverage/total.json - ~/tmp/cc-test-reporter upload-coverage -i coverage/total.json - -workflows: - build-and-test: - jobs: - - setup - - lint: - requires: - - setup - - test-frontend: - requires: - - setup - - test-backend: - requires: - - setup - - report: - requires: - - lint - - test-frontend - - test-backend - context: github-status # Assumes you have a context with GitHub token \ No newline at end of file + - coverage \ No newline at end of file