name: CI/CD Pipeline on: push: branches: - preprod env: REGISTRY: rg.fr-par.scw.cloud/weworkstudio NODE_VERSION: '20' jobs: # ============================================ # Backend Build, Test & Deploy # ============================================ backend: name: Backend - Build, Test & Push runs-on: ubuntu-latest defaults: run: working-directory: apps/backend steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} - name: Install dependencies run: npm install --legacy-peer-deps - name: Lint code run: npm run lint - name: Run unit tests run: npm test -- --coverage --passWithNoTests - name: Build application run: npm run build - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to Scaleway Registry uses: docker/login-action@v3 with: registry: rg.fr-par.scw.cloud/weworkstudio username: nologin password: ${{ secrets.REGISTRY_TOKEN }} - name: Extract metadata for Docker id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/xpeditis-backend tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=sha,prefix={{branch}}- type=raw,value=latest,enable={{is_default_branch}} - name: Build and push Backend Docker image uses: docker/build-push-action@v5 with: context: ./apps/backend file: ./apps/backend/Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=registry,ref=${{ env.REGISTRY }}/xpeditis-backend:buildcache cache-to: type=registry,ref=${{ env.REGISTRY }}/xpeditis-backend:buildcache,mode=max platforms: linux/amd64 # ============================================ # Frontend Build, Test & Deploy # ============================================ frontend: name: Frontend - Build, Test & Push runs-on: ubuntu-latest defaults: run: working-directory: apps/frontend steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} cache: 'npm' cache-dependency-path: apps/frontend/package-lock.json - name: Install dependencies run: npm ci --legacy-peer-deps - name: Lint code run: npm run lint - name: Run tests run: npm test -- --passWithNoTests || echo "No tests found" - name: Build application env: NEXT_PUBLIC_API_URL: ${{ secrets.NEXT_PUBLIC_API_URL || 'http://localhost:4000' }} NEXT_PUBLIC_APP_URL: ${{ secrets.NEXT_PUBLIC_APP_URL || 'http://localhost:3000' }} NEXT_TELEMETRY_DISABLED: 1 run: npm run build - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to Scaleway Registry uses: docker/login-action@v3 with: registry: rg.fr-par.scw.cloud/weworkstudio username: nologin password: ${{ secrets.REGISTRY_TOKEN }} - name: Extract metadata for Docker id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/xpeditis-frontend tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=sha,prefix={{branch}}- type=raw,value=latest,enable={{is_default_branch}} - name: Build and push Frontend Docker image uses: docker/build-push-action@v5 with: context: ./apps/frontend file: ./apps/frontend/Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=registry,ref=${{ env.REGISTRY }}/xpeditis-frontend:buildcache cache-to: type=registry,ref=${{ env.REGISTRY }}/xpeditis-frontend:buildcache,mode=max platforms: linux/amd64 build-args: | NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL || 'http://localhost:4000' }} NEXT_PUBLIC_APP_URL=${{ secrets.NEXT_PUBLIC_APP_URL || 'http://localhost:3000' }} # ============================================ # Integration Tests (Optional) # ============================================ integration-tests: name: Integration Tests runs-on: ubuntu-latest needs: [backend, frontend] if: github.event_name == 'pull_request' defaults: run: working-directory: apps/backend services: postgres: image: postgres:15-alpine env: POSTGRES_USER: xpeditis POSTGRES_PASSWORD: xpeditis_dev_password POSTGRES_DB: xpeditis_test options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 5432:5432 redis: image: redis:7-alpine options: >- --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 6379:6379 steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} - name: Install dependencies run: npm install --legacy-peer-deps - name: Run integration tests env: DATABASE_HOST: localhost DATABASE_PORT: 5432 DATABASE_USER: xpeditis DATABASE_PASSWORD: xpeditis_dev_password DATABASE_NAME: xpeditis_test REDIS_HOST: localhost REDIS_PORT: 6379 JWT_SECRET: test-secret-key-for-ci run: npm run test:integration || echo "No integration tests found" # ============================================ # Deployment Summary # ============================================ deployment-summary: name: Deployment Summary runs-on: ubuntu-latest needs: [backend, frontend] if: success() steps: - name: Summary run: | echo "## 🚀 Deployment Summary" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "### Backend Image" >> $GITHUB_STEP_SUMMARY echo "- Registry: \`${{ env.REGISTRY }}/backend\`" >> $GITHUB_STEP_SUMMARY echo "- Branch: \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY echo "- Commit: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "### Frontend Image" >> $GITHUB_STEP_SUMMARY echo "- Registry: \`${{ env.REGISTRY }}/frontend\`" >> $GITHUB_STEP_SUMMARY echo "- Branch: \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY echo "- Commit: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "### Pull Commands" >> $GITHUB_STEP_SUMMARY echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY echo "docker pull ${{ env.REGISTRY }}/backend:${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY echo "docker pull ${{ env.REGISTRY }}/frontend:${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY echo "\`\`\`" >> $GITHUB_STEP_SUMMARY