92 lines
2.7 KiB
YAML
92 lines
2.7 KiB
YAML
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/
|
|
|