From fa99c3076cd7ba6cc5b635b8c353295d08e308a6 Mon Sep 17 00:00:00 2001 From: Adam French Date: Fri, 23 Oct 2026 22:15:19 +0100 Subject: [PATCH] Run Gitea CI in host mode, and add uvicorn to the dev extra Every Gitea Actions run failed in actions/checkout: the stpvm runner is registered against http://localhost:3000, which an ubuntu-latest job container can't reach. Add .gitea/workflows/ci.yml, which Gitea uses in place of the GitHub workflow, following web_server's pattern: host mode, a plain git fetch over Gitea's SSH port, and ruff + pytest inside python:-slim containers. That surfaced a real failure: test_serve_refuses_without_token imports uvicorn, which only the web extra installed. Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/ci.yml | 73 +++++++++++++++++++++++++++++++++++++++++ README.md | 2 +- pyproject.toml | 1 + 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 .gitea/workflows/ci.yml diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..bda89e9 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,73 @@ +# ci.yml - ruff and pytest on every push, on each supported Python. +# +# Gitea runs this file instead of .github/workflows/ci.yml (it ignores +# .github/workflows once .gitea/workflows exists). The .github copy stays for +# GitHub, where `ubuntu-latest` + actions/checkout work. +# +# WHY NOT THE GITHUB WORKFLOW AS-IS +# The act_runner on stpvm is registered against http://localhost:3000. +# `ubuntu-latest` jobs run in a docker container, where localhost is the +# container itself, so actions/checkout can't reach Gitea and every run +# failed before a test ran. Like web_server's deploy.yaml, this runs in +# the runner's host mode (`self-hosted`), fetches the commit with plain git +# over Gitea's SSH port, and runs the checks inside pinned python images. +name: CI + +on: + push: + +jobs: + test: + runs-on: self-hosted + strategy: + matrix: + python: ["3.10", "3.12", "3.13"] + env: + # Passed through env rather than interpolated into the scripts, so + # a branch name can never be parsed as shell. + SHA: ${{ github.sha }} + REF: ${{ github.ref }} + PYTHON: ${{ matrix.python }} + REMOTE: ssh://git@localhost:2222/adamf/receipt_maker.git + GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no" + # Bare repo kept between runs so each fetch is incremental. + CACHE: /home/adamf/.cache/receipt_maker-ci/repo.git + # This run's tree, keyed by commit and Python so matrix jobs can't share one. + SRC: /home/adamf/.cache/receipt_maker-ci/src-${{ github.sha }}-${{ matrix.python }} + steps: + - name: Export the pushed commit to a scratch directory + shell: bash + run: | + set -eu + mkdir -p "$(dirname "$CACHE")" + [ -d "$CACHE" ] || git init --quiet --bare "$CACHE" + # Test $SHA, not FETCH_HEAD: the branch may have moved on since + # this run was queued. + git --git-dir="$CACHE" fetch --quiet --no-tags "$REMOTE" "$REF" + rm -rf "$SRC" + mkdir -p "$SRC" + git --git-dir="$CACHE" archive --format=tar "$SHA" | tar -x -C "$SRC" + test -f "$SRC/pyproject.toml" # catch a half-failed archive without pipefail + echo "Exported $SHA ($REF) to $SRC" + + # The source is mounted read-only (so the root container can't leave + # files the runner user can't delete) and copied inside, because + # pip builds the package in place. + - name: ruff and pytest + shell: bash + run: | + set -eu + docker run --rm \ + -v "$SRC":/src:ro \ + -v receipt_maker_ci_pip:/root/.cache/pip \ + -e PYTHONDONTWRITEBYTECODE=1 \ + "python:$PYTHON-slim" \ + sh -c 'cp -r /src /work && cd /work \ + && pip install --quiet --disable-pip-version-check --root-user-action=ignore ".[dev]" \ + && ruff check . \ + && python -m pytest -q -p no:cacheprovider' + + - name: Remove the scratch directory + if: always() + shell: bash + run: rm -rf "$SRC" diff --git a/README.md b/README.md index 083c43c..3bc5f1e 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ pytest # run the tests ruff check . # lint ``` -Both checks also run in CI on every push and pull request (`.github/workflows/ci.yml`). +Both checks also run in CI on every push, on Python 3.10, 3.12 and 3.13. Gitea Actions uses `.gitea/workflows/ci.yml`: the runner on stpvm runs it in host mode and does the checks inside `python:-slim` containers, because its docker-mode jobs can't reach Gitea for `actions/checkout`. `.github/workflows/ci.yml` is the same CI for GitHub. ## Files diff --git a/pyproject.toml b/pyproject.toml index b44afe8..1eaada7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ dev = [ "textual>=1.0", "rich>=13.0", "fastapi>=0.110", + "uvicorn>=0.29", # imported by receipt_web.serve(), which the tests call "python-multipart>=0.0.9", "httpx>=0.27", # FastAPI's TestClient ]