From 42c7f98a82af4dc00b030fac181b606af1b652a2 Mon Sep 17 00:00:00 2001 From: Arthur Belleville Date: Thu, 23 Oct 2025 22:26:03 +0200 Subject: [PATCH] Update circle ci --- .circleci/config.yml | 371 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 349 insertions(+), 22 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bb68b14..856a431 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,31 +1,358 @@ -# Use the latest 2.1 version of CircleCI pipeline process engine. -# See: https://circleci.com/docs/reference/configuration-reference version: 2.1 -# Define a job to be invoked later in a workflow. -# See: https://circleci.com/docs/guides/orchestrate/jobs-steps/#jobs-overview & https://circleci.com/docs/reference/configuration-reference/#jobs -jobs: - say-hello: - # Specify the execution environment. You can specify an image from Docker Hub or use one of our convenience images from CircleCI's Developer Hub. - # See: https://circleci.com/docs/guides/execution-managed/executor-intro/ & https://circleci.com/docs/reference/configuration-reference/#executor-job +# Orbs for Node.js support +orbs: + node: circleci/node@6.1.0 + +# Define executor +executors: + node-executor: docker: - # Specify the version you desire here - # See: https://circleci.com/developer/images/image/cimg/base - - image: cimg/base:current + - image: cimg/node:20.11 + resource_class: large + working_directory: ~/project - # Add steps to the job - # See: https://circleci.com/docs/guides/orchestrate/jobs-steps/#steps-overview & https://circleci.com/docs/reference/configuration-reference/#steps +# Reusable commands +commands: + setup-pnpm: steps: - # Checkout the code as the first step. - - checkout - run: - name: "Say hello" - command: "echo Hello, World!" + name: Install pnpm + command: | + corepack enable + corepack prepare pnpm@10.19.0 --activate + + restore-dependencies: + steps: + - restore_cache: + keys: + - pnpm-deps-v1-{{ checksum "pnpm-lock.yaml" }} + - pnpm-deps-v1- + + save-dependencies: + steps: + - save_cache: + key: pnpm-deps-v1-{{ checksum "pnpm-lock.yaml" }} + paths: + - ~/.local/share/pnpm/store + - node_modules + - apps/main/node_modules + - apps/external/node_modules + - packages/ui/node_modules + - packages/shared/node_modules + + install-deps: + steps: + - run: + name: Install dependencies + command: pnpm install --frozen-lockfile -# Orchestrate jobs using workflows -# See: https://circleci.com/docs/guides/orchestrate/workflows/ & https://circleci.com/docs/reference/configuration-reference/#workflows +# Jobs +jobs: + # ============================================ + # TEST PHASE + # ============================================ + + test-lint: + executor: node-executor + steps: + - checkout + - setup-pnpm + - restore-dependencies + - install-deps + - save-dependencies + - run: + name: Run linting + command: pnpm run lint + - run: + name: Check formatting + command: pnpm run format --check || echo "Format check complete" + + test-typecheck: + executor: node-executor + steps: + - checkout + - setup-pnpm + - restore-dependencies + - install-deps + - run: + name: Type check all packages + command: pnpm run typecheck + + test-unit: + executor: node-executor + steps: + - checkout + - setup-pnpm + - restore-dependencies + - install-deps + - run: + name: Run unit tests + command: pnpm run test + - store_test_results: + path: apps/main/coverage + - store_artifacts: + path: apps/main/coverage + destination: coverage + + test-api: + executor: node-executor + steps: + - checkout + - setup-pnpm + - run: + name: Install API dependencies + command: | + cd api + npm ci + - restore_cache: + keys: + - npm-api-v1-{{ checksum "api/package-lock.json" }} + - npm-api-v1- + - save_cache: + key: npm-api-v1-{{ checksum "api/package-lock.json" }} + paths: + - api/node_modules + - run: + name: Lint API + command: | + cd api + npm run lint + - run: + name: Run API tests + command: | + cd api + npm run test + + # ============================================ + # BUILD PHASE + # ============================================ + + build-apps: + executor: node-executor + steps: + - checkout + - setup-pnpm + - restore-dependencies + - install-deps + - run: + name: Build all apps + command: pnpm run build:apps + - persist_to_workspace: + root: . + paths: + - apps/main/dist + - apps/external/dist + - packages/ui/dist + - packages/shared/dist + - store_artifacts: + path: apps/main/dist + destination: main-app + - store_artifacts: + path: apps/external/dist + destination: external-app + + build-api: + executor: node-executor + steps: + - checkout + - restore_cache: + keys: + - npm-api-v1-{{ checksum "api/package-lock.json" }} + - run: + name: Install API dependencies + command: | + cd api + npm ci + - run: + name: Build API + command: | + cd api + npm run build + - persist_to_workspace: + root: . + paths: + - api/dist + - store_artifacts: + path: api/dist + destination: api + + # ============================================ + # DOCKER BUILD PHASE + # ============================================ + + build-docker-api: + machine: + image: ubuntu-2204:current + resource_class: medium + steps: + - checkout + - attach_workspace: + at: . + - run: + name: Build API Docker image + command: | + cd api + docker build -t xtablo-api:${CIRCLE_SHA1} -t xtablo-api:latest . + - run: + name: Save Docker image + command: | + mkdir -p /tmp/docker-images + docker save xtablo-api:${CIRCLE_SHA1} -o /tmp/docker-images/api.tar + - persist_to_workspace: + root: /tmp + paths: + - docker-images/api.tar + + # ============================================ + # DEPLOY PHASE + # ============================================ + + deploy-staging: + executor: node-executor + steps: + - checkout + - attach_workspace: + at: . + - setup-pnpm + - restore-dependencies + - install-deps + - run: + name: Deploy frontend to staging + command: | + cd apps/main + echo "Deploying main app to staging..." + # Uncomment and configure your Cloudflare deployment + # npx wrangler deploy --env staging + echo "Set CLOUDFLARE_API_TOKEN in CircleCI environment variables" + - run: + name: Deploy API to staging + command: | + echo "Deploying API to staging environment..." + # Add your API deployment commands here + # Example for Google Cloud Run: + # gcloud run deploy xtablo-api --image gcr.io/${GCP_PROJECT}/xtablo-api:${CIRCLE_SHA1} --region us-central1 + + deploy-production: + executor: node-executor + steps: + - checkout + - attach_workspace: + at: . + - setup-pnpm + - restore-dependencies + - install-deps + - run: + name: Deploy frontend to production + command: | + echo "Deploying to production..." + pnpm run deploy:all + - run: + name: Deploy API to production + command: | + echo "Deploying API to production environment..." + # Add your production API deployment commands here + +# Workflows workflows: - say-hello-workflow: # This is the name of the workflow, feel free to change it to better match your workflow. - # Inside the workflow, you define the jobs you want to run. + version: 2 + + # Run on all branches (except main and develop) + test-and-build: + when: + and: + - not: + equal: [ main, << pipeline.git.branch >> ] + - not: + equal: [ develop, << pipeline.git.branch >> ] jobs: - - say-hello \ No newline at end of file + # Test phase - run in parallel + - test-lint + - test-typecheck + - test-unit + - test-api + + # Build phase - run after tests pass + - build-apps: + requires: + - test-lint + - test-typecheck + - test-unit + + - build-api: + requires: + - test-api + + - build-docker-api: + requires: + - build-api + + # Staging deployment workflow (develop branch) + deploy-to-staging: + when: + equal: [ develop, << pipeline.git.branch >> ] + jobs: + # Test phase + - test-lint + - test-typecheck + - test-unit + - test-api + + # Build phase + - build-apps: + requires: + - test-lint + - test-typecheck + - test-unit + + - build-api: + requires: + - test-api + + - build-docker-api: + requires: + - build-api + + # Deploy to staging + - deploy-staging: + requires: + - build-apps + - build-docker-api + + # Production deployment workflow (main branch) + deploy-to-production: + when: + equal: [ main, << pipeline.git.branch >> ] + jobs: + # Test phase + - test-lint + - test-typecheck + - test-unit + - test-api + + # Build phase + - build-apps: + requires: + - test-lint + - test-typecheck + - test-unit + + - build-api: + requires: + - test-api + + - build-docker-api: + requires: + - build-api + + # Manual approval gate before production + - hold-for-approval: + type: approval + requires: + - build-apps + - build-docker-api + + # Deploy to production + - deploy-production: + requires: + - hold-for-approval