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
55 changes: 38 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,66 @@ on:
pull_request:
branches: ["main", "master"]

# Restrict default GITHUB_TOKEN permissions to read-only
permissions:
contents: read

jobs:
lint-and-test:
lint:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v4

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

- name: Install flake8
run: pip install flake8

- name: Lint — blocking (syntax errors / undefined names)
run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics

- name: Lint — style warnings (non-blocking)
run: flake8 . --count --exit-zero --max-line-length=100 --statistics

test:
needs: lint
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Lint with flake8
run: |
pip install flake8
# Stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# Treat all other issues as warnings (non-blocking)
flake8 . --count --exit-zero --max-line-length=100 --statistics
- name: Run tests with coverage
env:
OPENAI_API_KEY: "offline-mode-no-key-required"
run: pytest test_chatbot.py -v --tb=short --cov=. --cov-report=xml

- name: Run tests
run: pytest test_chatbot.py -v
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.python-version }}
path: coverage.xml

docker-build:
needs: test
runs-on: ubuntu-latest
needs: lint-and-test
permissions:
contents: read

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 0 additions & 2 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ def clear_all_sessions() -> None:

def _get_or_create_session(session_id: Optional[str]) -> tuple[str, ChatBot]:
"""Return (session_id, ChatBot) for the given session; create if missing."""
global _default_bot

if session_id is None:
# Create a new session
session_id = str(uuid.uuid4())
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ uvicorn[standard]>=0.23.0

# Testing
pytest>=7.4.0
pytest-cov>=4.0.0
httpx>=0.25.0