diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..567c9cd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,62 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +permissions: + contents: read + +concurrency: + group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: pip + cache-dependency-path: requirements-dev.txt + + - name: Install Ruff + run: pip install --disable-pip-version-check -r requirements-dev.txt + + - name: Ruff + run: ruff check api-service ingestion-service notification-service + + test: + name: Test (${{ matrix.service }}) + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + service: [api-service, ingestion-service, notification-service] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: pip + cache-dependency-path: ${{ matrix.service }}/requirements.txt + + - name: Install dependencies + run: pip install --disable-pip-version-check -r ${{ matrix.service }}/requirements.txt + + - name: Pytest + working-directory: ${{ matrix.service }} + run: python -m pytest tests/ -q diff --git a/scripts/run-ci.sh b/scripts/run-ci.sh new file mode 100755 index 0000000..2d02e75 --- /dev/null +++ b/scripts/run-ci.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# Run the same lint and test steps as .github/workflows/ci.yml locally. +set -euo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$ROOT" + +PYTHON="${PYTHON:-python3}" +LINT_VENV="$ROOT/.venv" + +ensure_lint_venv() { + if [[ ! -d "$LINT_VENV" ]]; then + "$PYTHON" -m venv "$LINT_VENV" + "$LINT_VENV/bin/pip" install --disable-pip-version-check -q --upgrade pip + "$LINT_VENV/bin/pip" install --disable-pip-version-check -q -r requirements-dev.txt + elif ! "$LINT_VENV/bin/python" -m ruff --version &>/dev/null; then + "$LINT_VENV/bin/pip" install --disable-pip-version-check -q -r requirements-dev.txt + fi +} + +run_service_tests() { + local service=$1 + local service_dir="$ROOT/$service" + local venv="$service_dir/.venv" + + echo "==> Test ($service)" + if [[ ! -d "$venv" ]]; then + "$PYTHON" -m venv "$venv" + "$venv/bin/pip" install --disable-pip-version-check -q --upgrade pip + "$venv/bin/pip" install --disable-pip-version-check -q -r "$service_dir/requirements.txt" + fi + + (cd "$service_dir" && "$venv/bin/python" -m pytest tests/ -q) +} + +echo "==> Lint (Ruff)" +ensure_lint_venv +"$LINT_VENV/bin/ruff" check api-service ingestion-service notification-service + +run_service_tests api-service +run_service_tests ingestion-service +run_service_tests notification-service + +echo "==> All CI checks passed"