Gitea runs on its own LXC, and stpvm's localhost:2222 forwarder to it is being removed. stpvm pins git.adam-french.co.uk to the LXC's LAN IP in /etc/hosts, so the self-hosted job reaches it directly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
75 lines
3.4 KiB
YAML
75 lines
3.4 KiB
YAML
# 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 Gitea over the LAN
|
|
# (http://git.adam-french.co.uk:3000, pinned in stpvm's /etc/hosts).
|
|
# `ubuntu-latest` jobs run in a docker container, which sees neither that
|
|
# pin nor the host, so actions/checkout couldn'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://[email protected]: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"
|