Fix test failures - disable strict_slashes to prevent 301 redirects #4
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 Pipeline | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| pull_request: | |
| branches: | |
| - main | |
| - master | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 0 * * 0' # 每週日 00:00 執行 | |
| jobs: | |
| lint-and-test: | |
| name: Code Quality & Testing | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| cache: 'pip' | |
| - name: Install dependencies | |
| working-directory: ./backend | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install flake8 pytest pytest-cov | |
| - name: Run linting (flake8) | |
| working-directory: ./backend | |
| run: | | |
| # Stop the build if there are Python syntax errors or undefined names | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
| # Exit-zero treats all errors as warnings | |
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
| - name: Run tests | |
| working-directory: ./backend | |
| run: | | |
| # 如果沒有測試文件,創建一個基本的測試 | |
| if [ ! -d "tests" ]; then | |
| mkdir -p tests | |
| echo "def test_placeholder():" > tests/test_basic.py | |
| echo " assert True" >> tests/test_basic.py | |
| fi | |
| pytest --cov=. --cov-report=term-missing | |
| - name: Frontend validation | |
| working-directory: ./frontend | |
| run: | | |
| # 檢查 HTML 文件是否存在 | |
| if [ -f "index.html" ]; then | |
| echo "✓ Frontend files validated" | |
| else | |
| echo "✗ index.html not found" | |
| exit 1 | |
| fi | |
| docker-build: | |
| name: Docker Build Test | |
| needs: lint-and-test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build Docker image | |
| working-directory: ./backend | |
| run: | | |
| if [ -f "Dockerfile" ]; then | |
| docker build -t mongo-updater:test . | |
| echo "✓ Docker image built successfully" | |
| else | |
| echo "⚠ No Dockerfile found, skipping Docker build" | |
| fi | |
| deploy-backend: | |
| name: Deploy Backend to Zeabur | |
| needs: [lint-and-test, docker-build] | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Trigger Zeabur Backend Deployment | |
| run: | | |
| echo "✅ Tests passed! Zeabur will auto-deploy backend from this Git push." | |
| echo "Backend Service ID: ${{ secrets.ZEABUR_BACKEND_SERVICE_ID }}" | |
| deploy-frontend: | |
| name: Deploy Frontend to Zeabur | |
| needs: [lint-and-test, docker-build] | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Trigger Zeabur Frontend Deployment | |
| run: | | |
| echo "✅ Tests passed! Zeabur will auto-deploy frontend from this Git push." | |
| echo "Frontend Service ID: ${{ secrets.ZEABUR_FRONTEND_SERVICE_ID }}" |