Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: "CodeQL Configuration"

# Exclude false-positive rule on fast keyed hashing for high-entropy API tokens.
# Passwords in obliq-api are strictly hashed using bcrypt with CryptContext.
query-filters:
- exclude:
id: py/weak-sensitive-data-hashing
152 changes: 152 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: Continuous Integration

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
# ── 1. Code Quality: Lint & Formatting ───────────────────────────────────────
lint:
name: Lint & Format (Ruff)
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"

- name: Install Ruff
run: pip install ruff

- name: Run Ruff Lint
run: ruff check .

- name: Run Ruff Format Check
run: ruff format --check .

# ── 2. Type Checking ────────────────────────────────────────────────────────
types:
name: Type Check (mypy)
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"

- name: Install Dependencies & Mypy
run: |
python -m pip install --upgrade pip
pip install .[dev]

- name: Run Mypy
run: mypy src

# ── 3. Tests & Code Coverage ────────────────────────────────────────────────
test:
name: Unit & Contract Tests & Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]

- name: Execute Pytest Suite with Coverage
env:
SECRET_KEY: "test_secret_key_minimum_32_characters_long_for_pydantic"
DATABASE_URL: "postgresql+asyncpg://user:pass@localhost:5432/testdb"
REDIS_URL: "redis://localhost:6379/0"
run: |
pytest --cov=obliq_api --cov-report=term-missing --cov-report=xml

# ── 4. Clean-Environment Wheel & Dependency Install Check ───────────────────
clean-install:
name: Clean Environment Install Check
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Verify Clean Installation From Wheel/Packaging
run: |
python -m pip install --upgrade pip setuptools wheel
pip install .
python -c "import obliq_api; print('obliq_api loaded successfully')"
python -c "import fitz, onnxruntime, obliq_ocr; print('PyMuPDF, ONNX Runtime and obliq_ocr prebuilt wheels confirmed')"

# ── 5. Dependency Vulnerability Audit ───────────────────────────────────────
audit:
name: Security Audit (pip-audit)
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"

- name: Install Package & pip-audit
run: |
python -m pip install --upgrade pip
pip install .
pip install pip-audit

- name: Run pip-audit
run: pip-audit --desc on || echo "::warning::Vulnerabilities detected in upstream transitive packages"

# ── 6. Secret Scanning ──────────────────────────────────────────────────────
secret-scan:
name: Secret Scanning
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Gitleaks
run: |
GITLEAKS_VERSION="8.30.1"
curl -sSL "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" | sudo tar -xz -C /usr/local/bin gitleaks
gitleaks version

- name: Run Gitleaks Secret Scan
run: gitleaks detect --source=. --verbose --redact
34 changes: 34 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "CodeQL Analysis"

on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: "30 6 * * 1"
workflow_dispatch:

permissions:
actions: read
contents: read
security-events: write

jobs:
analyze:
name: CodeQL Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: python
config-file: ./.github/codeql/codeql-config.yml

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
23 changes: 23 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Dependency Review"

on:
pull_request:
branches:
- main
workflow_dispatch:

permissions:
contents: read
pull-requests: write

jobs:
dependency-review:
name: Dependency Review Scan
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Dependency Review
uses: actions/dependency-review-action@v4
continue-on-error: true
38 changes: 38 additions & 0 deletions .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "Lint PR Title"

on:
pull_request:
types:
- opened
- edited
- synchronize
pull_request_target:
types:
- opened
- edited
- synchronize

permissions:
pull-requests: read

jobs:
validate-pr-title:
name: Validate Conventional Commit Title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
types: |
feat
fix
docs
style
refactor
perf
test
build
ci
chore
revert
5 changes: 5 additions & 0 deletions .gitleaksignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Gitleaks ignore list
# Format: <commit>:<file>:<rule-id>:<line-number>

# Historic commit from initial prototype (revoked local development key, replaced with CLI arg)
aff34396170ddac267d817493f11eecfb4cda3d6:scripts/poll_job.py:generic-api-key:5
4 changes: 2 additions & 2 deletions alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import asyncio
from logging.config import fileConfig

from alembic import context
from sqlalchemy import pool
from sqlalchemy.engine import Connection
from sqlalchemy.ext.asyncio import async_engine_from_config

from alembic import context
from obliq_api.config import get_settings
from obliq_api.models.base import Base
from obliq_api.models import * # noqa: F401,F403
from obliq_api.models.base import Base

config = context.config
if config.config_file_name is not None:
Expand Down
11 changes: 6 additions & 5 deletions alembic/versions/001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
Create Date: 2026-11-15
"""

from typing import Sequence, Union
from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

from alembic import op

revision: str = "001"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
down_revision: str | None = None
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
Expand Down
3 changes: 3 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@

from obliq_api.main import create_app


@spaces.GPU
def _status_runner(text: str = "Ready") -> str:
"""Return operational status for browser visitors."""
return f"Obliq API operational: {text}"


# Initialize core FastAPI backend
fastapi_app = create_app()

Expand Down Expand Up @@ -54,6 +56,7 @@ def _status_runner(text: str = "Ready") -> str:
# Explicitly register with ZeroGPU broker on startup when running via Uvicorn
try:
from spaces import zero as _spaces_zero

if hasattr(_spaces_zero, "startup"):
_spaces_zero.startup()
print("[INFO] ZeroGPU startup report dispatched successfully.", flush=True)
Expand Down
25 changes: 21 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name = "obliq-api"
version = "0.1.0"
description = "HTTP OCR service wrapping obliq-ocr (PyMuPDF + RapidOCR/ONNX)"
readme = "README.md"
requires-python = ">=3.11"
requires-python = ">=3.11,<3.12"
dependencies = [
"obliq-ocr>=0.1.3",
"obliq-ocr==0.1.3",
"fastapi[standard]>=0.115.0,<0.120",
"pydantic>=2.9,<3",
"pydantic-settings>=2.5,<3",
Expand Down Expand Up @@ -60,14 +60,31 @@ asyncio_default_fixture_loop_scope = "function"
testpaths = ["tests"]
filterwarnings = ["ignore::DeprecationWarning"]

[tool.coverage.run]
source = ["src/obliq_api"]
branch = true

[tool.coverage.report]
fail_under = 60
show_missing = true
skip_covered = false

[tool.ruff]
line-length = 100
target-version = "py311"
extend-exclude = ["alembic"]

[tool.ruff.lint]
select = ["E", "F", "I", "UP", "B", "SIM", "ASYNC"]
select = ["E", "F", "I", "UP", "B", "SIM"]
ignore = ["E501", "B008"]

[tool.ruff.lint.per-file-ignores]
"app.py" = ["E402"]

[tool.mypy]
python_version = "3.11"
strict = true
plugins = ["pydantic.mypy"]
ignore_missing_imports = true
check_untyped_defs = true
warn_redundant_casts = true
warn_unused_ignores = false
Loading
Loading