From 91f87689d07039ef73527f22727c3abcf568e408 Mon Sep 17 00:00:00 2001 From: ngxstat-bot Date: Sat, 16 Aug 2025 04:57:20 -0500 Subject: [PATCH] ci: add Forgejo Actions workflow for lint, test, and sample reports artifact --- .forgejo/workflows/ci.yml | 92 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .forgejo/workflows/ci.yml diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml new file mode 100644 index 0000000..65439eb --- /dev/null +++ b/.forgejo/workflows/ci.yml @@ -0,0 +1,92 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + lint-and-test: + name: Lint and test (py${{ matrix.python }}) + # Adjust this label to match your Forgejo runner + runs-on: docker + container: + image: python:${{ matrix.python }}-bookworm + strategy: + fail-fast: false + matrix: + python: ["3.10", "3.11", "3.12"] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python (inside container) + run: | + python -m pip install --upgrade pip + pip --version + + - name: Install dependencies + run: | + pip install -r requirements.txt + pip install pytest + + - name: Format check (black) + run: black --check . + + - name: Lint (flake8) + run: flake8 . + + - name: Run tests (pytest) + env: + PYTHONDONTWRITEBYTECODE: "1" + run: pytest -q + + build-reports: + name: Build sample reports artifact + needs: lint-and-test + runs-on: docker + container: + image: python:3.11-bookworm + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Seed minimal DB and generate reports + run: | + python - <<'PY' + import sqlite3, pathlib + db = pathlib.Path('database/ngxstat.db') + db.parent.mkdir(parents=True, exist_ok=True) + conn = sqlite3.connect(db) + cur = conn.cursor() + cur.execute('''CREATE TABLE IF NOT EXISTS logs ( + id INTEGER PRIMARY KEY, + ip TEXT, + host TEXT, + time TEXT, + request TEXT, + status INTEGER, + bytes_sent INTEGER, + referer TEXT, + user_agent TEXT, + cache_status TEXT + )''') + cur.execute("INSERT INTO logs (ip, host, time, request, status, bytes_sent, referer, user_agent, cache_status) VALUES ('127.0.0.1','example.com','2024-01-01 10:00:00','GET / HTTP/1.1',200,100,'-','curl','MISS')") + cur.execute("INSERT INTO logs (ip, host, time, request, status, bytes_sent, referer, user_agent, cache_status) VALUES ('127.0.0.1','example.com','2024-01-01 10:05:00','GET /about HTTP/1.1',200,100,'-','curl','MISS')") + conn.commit(); conn.close() + PY + python scripts/generate_reports.py global + python scripts/generate_reports.py hourly + python scripts/generate_reports.py index + + - name: Upload reports artifact + uses: actions/upload-artifact@v4 + with: + name: ngxstat-reports + path: output/ +