diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml new file mode 100644 index 0000000..11e24f7 --- /dev/null +++ b/.github/workflows/backend.yml @@ -0,0 +1,84 @@ +name: Backend CI + +on: + pull_request: + paths: + - "backend/**" + push: + branches: [master] + paths: + - "backend/**" + +jobs: + test: + runs-on: ubuntu-latest + defaults: + run: + working-directory: backend + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Set up uv + uses: astral-sh/setup-uv@v4 + with: + enable-cache: true + cache-dependency-glob: "backend/uv.lock" + + - name: Install dependencies + run: uv sync --dev + + - name: Run ruff + run: uv run ruff check . + + - name: Run mypy + run: uv run mypy src tests + + - name: Run pytest with coverage + run: uv run pytest --cov=src --cov-report=term-missing --cov-fail-under=70 + + deploy: + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + needs: lint-test + runs-on: ubuntu-latest + defaults: + run: + working-directory: backend + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Set up uv + uses: astral-sh/setup-uv@v4 + with: + enable-cache: true + cache-dependency-glob: "backend/uv.lock" + + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: "20" + + - name: Install npm dependencies + run: npm ci + + - name: Install Python dependencies + run: uv sync --dev + + - name: Deploy Cloudflare Worker + env: + CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }} + CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} + run: uv run pywrangler deploy diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d04548..e445f99 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,11 @@ name: Flutter Tests on: push: branches: [master] + paths-ignore: + - "backend/**" pull_request: + paths-ignore: + - "backend/**" jobs: test: diff --git a/.gitignore b/.gitignore index 3820a95..536a6fb 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,11 @@ app.*.map.json /android/app/debug /android/app/profile /android/app/release + +# Python +__pycache__/ +.venv/ +.pytest_cache/ +.ruff_cache/ +.coverage +htmlcov/ diff --git a/backend/src/worker.py b/backend/src/worker.py index b784546..39289ff 100644 --- a/backend/src/worker.py +++ b/backend/src/worker.py @@ -19,6 +19,7 @@ async def fetch(self, request: Request) -> Response: use_case=_USE_CASE, config=_CONFIG, ) + if result.body is None: return Response(status=result.status, headers=result.headers) return Response(result.body, status=result.status, headers=result.headers)