Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8fc8e95404 | ||
|
|
4201bc965e | ||
|
|
b7db7811d4 | ||
|
|
b411752612 | ||
|
|
20f27b6edf | ||
|
|
5a72f4d0c8 | ||
|
|
e911afe7f6 | ||
|
|
d3a8e83a95 | ||
|
|
335c06af7a | ||
|
|
8a720f9642 | ||
|
|
3ac946712b |
+196
-112
@@ -1,117 +1,117 @@
|
||||
version: 2.1
|
||||
orbs:
|
||||
node: circleci/node@6.1.0
|
||||
ruby: circleci/ruby@2.1.0
|
||||
|
||||
defaults: &defaults
|
||||
working_directory: ~/build
|
||||
machine:
|
||||
image: ubuntu-2204:2024.05.1
|
||||
resource_class: large
|
||||
environment:
|
||||
RAILS_LOG_TO_STDOUT: false
|
||||
COVERAGE: true
|
||||
LOG_LEVEL: warn
|
||||
parallelism: 4
|
||||
executors:
|
||||
app-executor:
|
||||
machine:
|
||||
image: ubuntu-2204:2024.05.1
|
||||
resource_class: large
|
||||
environment:
|
||||
RAILS_LOG_TO_STDOUT: false
|
||||
COVERAGE: true
|
||||
LOG_LEVEL: warn
|
||||
|
||||
jobs:
|
||||
build:
|
||||
<<: *defaults
|
||||
commands:
|
||||
setup_dependencies:
|
||||
steps:
|
||||
- checkout
|
||||
|
||||
# Setup Node with caching
|
||||
- node/install:
|
||||
node-version: '23.7'
|
||||
- node/install-pnpm
|
||||
- restore_cache:
|
||||
keys:
|
||||
- pnpm-deps-v1-{{ checksum "pnpm-lock.yaml" }}
|
||||
- node/install-packages:
|
||||
pkg-manager: pnpm
|
||||
override-ci-command: pnpm i
|
||||
- run: node --version
|
||||
- run: pnpm --version
|
||||
- save_cache:
|
||||
key: pnpm-deps-v1-{{ checksum "pnpm-lock.yaml" }}
|
||||
paths:
|
||||
- node_modules
|
||||
|
||||
# Setup Ruby with caching
|
||||
- ruby/install:
|
||||
version: '3.3.3'
|
||||
- restore_cache:
|
||||
keys:
|
||||
- gem-cache-v1-{{ checksum "Gemfile.lock" }}
|
||||
- run:
|
||||
name: Add PostgreSQL repository and update
|
||||
name: Install Bundler and Gems
|
||||
command: |
|
||||
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 -y
|
||||
|
||||
gem install bundler -v 2.5.16
|
||||
bundle config set --local path 'vendor/bundle'
|
||||
bundle install --jobs=4 --retry=3
|
||||
- save_cache:
|
||||
key: gem-cache-v1-{{ checksum "Gemfile.lock" }}
|
||||
paths:
|
||||
- vendor/bundle
|
||||
|
||||
# Install system dependencies using a layer caching approach
|
||||
- restore_cache:
|
||||
keys:
|
||||
- apt-cache-v1-{{ checksum ".circleci/apt-packages.txt" }}
|
||||
- run:
|
||||
name: Create apt packages list
|
||||
command: |
|
||||
mkdir -p .circleci
|
||||
cat > .circleci/apt-packages.txt \<< EOF
|
||||
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
|
||||
EOF
|
||||
- run:
|
||||
name: Install System Dependencies
|
||||
command: |
|
||||
sudo apt-get update
|
||||
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
|
||||
|
||||
- run:
|
||||
name: Install RVM and Ruby 3.3.3
|
||||
command: |
|
||||
sudo apt-get install -y gpg
|
||||
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 "3.3.3"
|
||||
rvm use 3.3.3 --default
|
||||
gem install bundler -v 2.5.16
|
||||
|
||||
- run:
|
||||
name: Install Application Dependencies
|
||||
command: |
|
||||
source ~/.rvm/scripts/rvm
|
||||
bundle install
|
||||
# pnpm install
|
||||
|
||||
- run:
|
||||
name: Download cc-test-reporter
|
||||
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
|
||||
|
||||
# Swagger verification
|
||||
- run:
|
||||
name: Verify swagger API specification
|
||||
command: |
|
||||
bundle exec rake swagger:build
|
||||
if [[ `git status swagger/swagger.json --porcelain` ]]
|
||||
then
|
||||
echo "ERROR: The swagger.json file is not in sync with the yaml specification. Run 'rake swagger:build' and commit 'swagger/swagger.json'."
|
||||
exit 1
|
||||
# Add PostgreSQL repository once
|
||||
if [ ! -f /etc/apt/sources.list.d/pgdg.list ]; then
|
||||
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 -y
|
||||
fi
|
||||
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
|
||||
java -jar ~/tmp/openapi-generator-cli-6.3.0.jar validate -i swagger/swagger.json
|
||||
|
||||
# we remove the FRONTED_URL from the .env before running the tests
|
||||
|
||||
# Install packages
|
||||
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y $(cat .circleci/apt-packages.txt)
|
||||
- save_cache:
|
||||
key: apt-cache-v1-{{ checksum ".circleci/apt-packages.txt" }}
|
||||
paths:
|
||||
- /var/cache/apt
|
||||
|
||||
# Set up database
|
||||
- run:
|
||||
name: Database Setup and Configure Environment Variables
|
||||
command: |
|
||||
@@ -128,39 +128,107 @@ jobs:
|
||||
sed -i -e "/POSTGRES_PASSWORD/ s/=.*/=$pg_pass/" .env
|
||||
echo -en "\nINSTALLATION_ENV=circleci" >> ".env"
|
||||
|
||||
# Database setup
|
||||
# Download code climate reporter just once and cache it
|
||||
- restore_cache:
|
||||
keys:
|
||||
- cc-test-reporter-v1
|
||||
- run:
|
||||
name: Run DB migrations
|
||||
command: bundle exec rails db:chatwoot_prepare
|
||||
name: Download cc-test-reporter
|
||||
command: |
|
||||
if [ ! -f ~/tmp/cc-test-reporter ]; then
|
||||
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
|
||||
fi
|
||||
- save_cache:
|
||||
key: cc-test-reporter-v1
|
||||
paths:
|
||||
- ~/tmp/cc-test-reporter
|
||||
|
||||
# Bundle audit
|
||||
workflows:
|
||||
version: 2
|
||||
build_and_test:
|
||||
jobs:
|
||||
- lint
|
||||
- test-frontend:
|
||||
requires:
|
||||
- lint
|
||||
- test-backend:
|
||||
requires:
|
||||
- lint
|
||||
- report-coverage:
|
||||
requires:
|
||||
- test-frontend
|
||||
- test-backend
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
executor: app-executor
|
||||
steps:
|
||||
- setup_dependencies
|
||||
|
||||
# Swagger verification
|
||||
- run:
|
||||
name: Verify swagger API specification
|
||||
command: |
|
||||
bundle exec rake swagger:build
|
||||
if [[ `git status swagger/swagger.json --porcelain` ]]
|
||||
then
|
||||
echo "ERROR: The swagger.json file is not in sync with the yaml specification. Run 'rake swagger:build' and commit 'swagger/swagger.json'."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Cache the openapi jar
|
||||
if [ ! -f ~/tmp/openapi-generator-cli-6.3.0.jar ]; then
|
||||
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
|
||||
fi
|
||||
java -jar ~/tmp/openapi-generator-cli-6.3.0.jar validate -i swagger/swagger.json
|
||||
|
||||
# Bundle audit - run only in lint job
|
||||
- run:
|
||||
name: Bundle audit
|
||||
command: bundle exec bundle audit update && bundle exec bundle audit check -v
|
||||
|
||||
|
||||
# Rubocop linting
|
||||
- run:
|
||||
name: Rubocop
|
||||
command: bundle exec rubocop
|
||||
|
||||
# ESLint linting
|
||||
|
||||
# ESLint
|
||||
- run:
|
||||
name: eslint
|
||||
command: pnpm run eslint
|
||||
|
||||
test-frontend:
|
||||
executor: app-executor
|
||||
steps:
|
||||
- setup_dependencies
|
||||
- run:
|
||||
name: Run DB migrations
|
||||
command: bundle exec rails db:chatwoot_prepare
|
||||
- run:
|
||||
name: Run frontend tests
|
||||
command: |
|
||||
mkdir -p ~/build/coverage/frontend
|
||||
~/tmp/cc-test-reporter before-build
|
||||
pnpm run test:coverage
|
||||
|
||||
- run:
|
||||
name: Code Climate Test Coverage (Frontend)
|
||||
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 lcov -o "~/build/coverage/frontend/codeclimate.json"
|
||||
- persist_to_workspace:
|
||||
root: ~/build
|
||||
paths:
|
||||
- coverage/frontend
|
||||
|
||||
# Run backend tests
|
||||
test-backend:
|
||||
executor: app-executor
|
||||
parallelism: 4
|
||||
steps:
|
||||
- setup_dependencies
|
||||
- run:
|
||||
name: Run DB migrations
|
||||
command: bundle exec rails db:chatwoot_prepare
|
||||
- run:
|
||||
name: Run backend tests
|
||||
command: |
|
||||
@@ -174,18 +242,34 @@ jobs:
|
||||
--out ~/tmp/test-results/rspec.xml \
|
||||
-- ${TESTFILES}
|
||||
no_output_timeout: 30m
|
||||
|
||||
- run:
|
||||
name: Code Climate Test Coverage (Backend)
|
||||
command: |
|
||||
~/tmp/cc-test-reporter format-coverage -t simplecov -o "~/build/coverage/backend/codeclimate.$CIRCLE_NODE_INDEX.json"
|
||||
|
||||
- run:
|
||||
name: List coverage directory contents
|
||||
command: |
|
||||
ls -R ~/build/coverage
|
||||
|
||||
- persist_to_workspace:
|
||||
root: ~/build
|
||||
paths:
|
||||
- coverage
|
||||
- coverage/backend
|
||||
- store_test_results:
|
||||
path: ~/tmp/test-results
|
||||
- store_artifacts:
|
||||
path: ~/tmp/test-artifacts
|
||||
|
||||
report-coverage:
|
||||
executor: app-executor
|
||||
steps:
|
||||
- attach_workspace:
|
||||
at: ~/build
|
||||
- run:
|
||||
name: Download cc-test-reporter
|
||||
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
|
||||
- run:
|
||||
name: Upload coverage results to Code Climate
|
||||
command: |
|
||||
# Sum the coverage reports
|
||||
~/tmp/cc-test-reporter sum-coverage ~/build/coverage/**/codeclimate*.json -p 5 -o ~/build/coverage/codeclimate.json
|
||||
# Upload the combined report
|
||||
~/tmp/cc-test-reporter upload-coverage -i ~/build/coverage/codeclimate.json
|
||||
Reference in New Issue
Block a user