name: CI/CD Pipeline on: push: branches: [master, develop] pull_request: branches: [master, develop] jobs: test: runs-on: ubuntu-latest services: postgres: image: postgres:15 env: POSTGRES_PASSWORD: postgres POSTGRES_DB: test_db options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 5432:5432 redis: image: redis:7 options: >- --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 6379:6379 steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.11' cache: 'pip' - name: Install dependencies run: | pip install -r requirements/base.txt pip install -r requirements/dev.txt - name: Run linters run: | black --check app/ tests/ isort --check-only app/ tests/ flake8 app/ tests/ - name: Run type checker run: | mypy app/ --ignore-missing-imports - name: Run tests env: DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test_db REDIS_URL: redis://localhost:6379/0 LINE_CHANNEL_ACCESS_TOKEN: test_token LINE_CHANNEL_SECRET: test_secret OPENAI_API_KEY: test_key SECRET_KEY: test_secret_key run: | pytest --cov=app --cov-report=xml --cov-report=term-missing - name: Upload coverage if: always() uses: actions/upload-artifact@v4 with: name: coverage-report path: coverage.xml build: needs: test runs-on: ubuntu-latest if: github.event_name == 'push' steps: - uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Build Docker image uses: docker/build-push-action@v5 with: context: . push: false tags: smart-line-bot:latest cache-from: type=registry cache-to: type=inline deploy-staging: needs: build runs-on: ubuntu-latest if: github.ref == 'refs/heads/develop' environment: staging steps: - name: Deploy to staging run: | echo "Deploy to staging environment" # Add your deployment commands here deploy-production: needs: build runs-on: ubuntu-latest if: github.ref == 'refs/heads/master' environment: production steps: - name: Deploy to production run: | echo "Deploy to production environment" # Add your deployment commands here