fix: Update CI/CD pipeline #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI/CD | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| jobs: | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 20 | |
| - name: Install dependencies | |
| working-directory: ./backend | |
| run: npm install | |
| - name: Build TypeScript | |
| working-directory: ./backend | |
| run: npm run build | |
| - name: Create .env file for CI | |
| working-directory: ./backend | |
| run: | | |
| echo "REDIS_CLUSTER_NODES=redis-node-1:6379,redis-node-2:6379,redis-node-3:6379,redis-node-4:6379,redis-node-5:6379,redis-node-6:6379" >> .env | |
| echo "PORT=3000" >> .env | |
| - name: Start all services | |
| run: docker-compose up --build -d | |
| - name: Wait for services to be ready | |
| run: sleep 20 | |
| - name: Check API health | |
| run: | | |
| curl -f http://localhost:3000/health || (echo "❌ Health check failed!" && docker-compose logs ratelimiterapi && exit 1) | |
| - name: Verify health response | |
| run: | | |
| response=$(curl -s http://localhost:3000/health) | |
| echo " Health response: $response" | |
| if echo "$response" | grep -q "OK"; then | |
| echo " API is healthy!" | |
| else | |
| echo " API health check failed!" | |
| exit 1 | |
| fi | |
| - name: Show container status | |
| run: docker-compose ps | |
| - name: Show logs on success | |
| run: docker-compose logs --tail=20 | |
| - name: Cleanup | |
| if: always() | |
| run: docker-compose down -v |