mirror of
https://github.com/onyx-dot-app/onyx.git
synced 2026-10-22 19:32:55 -05:00
93 lines
3.2 KiB
YAML
93 lines
3.2 KiB
YAML
name: Python Checks
|
|
|
|
on:
|
|
merge_group:
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
- 'release/**'
|
|
|
|
jobs:
|
|
mypy-check:
|
|
# See https://runs-on.com/runners/linux/
|
|
# Note: Mypy seems quite optimized for x64 compared to arm64.
|
|
# Similarly, mypy is single-threaded and incremental, so 2cpu is sufficient.
|
|
runs-on: [runs-on, runner=2cpu-linux-x64, "run-id=${{ github.run_id }}", "extras=s3-cache"]
|
|
|
|
steps:
|
|
- uses: runs-on/action@cd2b598b0515d39d78c38a02d529db87d2196d1e # ratchet:runs-on/action@v2
|
|
- name: Checkout code
|
|
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # ratchet:actions/checkout@v4
|
|
|
|
- name: Setup uv
|
|
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # ratchet:astral-sh/setup-uv@v6
|
|
with:
|
|
enable-cache: true
|
|
|
|
- name: Cache uv cache directory
|
|
uses: runs-on/cache@50350ad4242587b6c8c2baa2e740b1bc11285ff4 # ratchet:runs-on/cache@v4
|
|
with:
|
|
path: ~/.cache/uv
|
|
key: ${{ runner.os }}-uv-${{ hashFiles('backend/requirements/*.txt', 'backend/pyproject.toml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-uv-
|
|
|
|
- name: Setup Python
|
|
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # ratchet:actions/setup-python@v5
|
|
with:
|
|
python-version: "3.11"
|
|
|
|
- name: Create virtual environment
|
|
working-directory: ./backend
|
|
run: uv venv .venv
|
|
|
|
- name: Install Python dependencies with uv
|
|
working-directory: ./backend
|
|
run: |
|
|
uv pip install \
|
|
-r requirements/default.txt \
|
|
-r requirements/dev.txt \
|
|
-r requirements/model_server.txt
|
|
|
|
- name: Generate OpenAPI schema
|
|
working-directory: ./backend
|
|
env:
|
|
PYTHONPATH: "."
|
|
run: |
|
|
uv run python scripts/onyx_openapi_schema.py --filename generated/openapi.json
|
|
|
|
- name: Generate OpenAPI Python client
|
|
working-directory: ./backend
|
|
run: |
|
|
docker run --rm \
|
|
-v "${{ github.workspace }}/backend/generated:/local" \
|
|
openapitools/openapi-generator-cli generate \
|
|
-i /local/openapi.json \
|
|
-g python \
|
|
-o /local/onyx_openapi_client \
|
|
--package-name onyx_openapi_client \
|
|
--skip-validate-spec \
|
|
--openapi-normalizer "SIMPLIFY_ONEOF_ANYOF=true,SET_OAS3_NULLABLE=true"
|
|
|
|
- name: Cache mypy cache
|
|
if: ${{ vars.DISABLE_MYPY_CACHE != 'true' }}
|
|
uses: runs-on/cache@50350ad4242587b6c8c2baa2e740b1bc11285ff4 # ratchet:runs-on/cache@v4
|
|
with:
|
|
path: backend/.mypy_cache
|
|
key: mypy-${{ runner.os }}-${{ hashFiles('**/*.py', '**/*.pyi', 'backend/pyproject.toml') }}
|
|
restore-keys: |
|
|
mypy-${{ runner.os }}-
|
|
|
|
- name: Run MyPy
|
|
working-directory: ./backend
|
|
run: uv run mypy .
|
|
|
|
- name: Check import order with reorder-python-imports
|
|
working-directory: ./backend
|
|
run: |
|
|
find ./onyx -name "*.py" | xargs uv run reorder-python-imports --py311-plus
|
|
|
|
- name: Check code formatting with Black
|
|
working-directory: ./backend
|
|
run: uv run black --check .
|