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
105 changes: 39 additions & 66 deletions .github/actions/poetry_setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,88 +1,61 @@
# An action for setting up poetry install with caching.
# Using a custom action since the default action does not
# take poetry install groups into account.
# Action code from:
# https://github.com/actions/setup-python/issues/505#issuecomment-1273013236
name: poetry-install-with-caching
description: Poetry install with support for caching of dependency groups.
name: uv-sync-with-caching
description: Install deps with uv, with cache for uv and .venv.

inputs:
python-version:
description: Python version, supporting MAJOR.MINOR only
description: Python version (MAJOR.MINOR)
required: true

poetry-version:
description: Poetry version
required: true

uv-version:
description: uv version (optional; defaults to latest)
required: false
default: ""
cache-key:
description: Cache key to use for manual handling of caching
description: Extra cache key salt (e.g., CI job name)
required: true
uv-sync-flags:
description: Extra flags for `uv sync` (e.g., "--all-groups --all-extras")
required: false
default: ""

runs:
using: composite
steps:
- uses: actions/setup-python@v5
name: Setup python ${{ inputs.python-version }}
id: setup-python
name: Setup Python ${{ inputs.python-version }}
with:
python-version: ${{ inputs.python-version }}

- uses: actions/cache@v4
id: cache-bin-poetry
name: Cache Poetry binary - Python ${{ inputs.python-version }}
env:
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "1"
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
path: |
/opt/pipx/venvs/poetry
# This step caches the poetry installation, so make sure it's keyed on the poetry version as well.
key: bin-poetry-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-${{ inputs.poetry-version }}

- name: Refresh shell hashtable and fixup softlinks
if: steps.cache-bin-poetry.outputs.cache-hit == 'true'
shell: bash
env:
POETRY_VERSION: ${{ inputs.poetry-version }}
PYTHON_VERSION: ${{ inputs.python-version }}
run: |
set -eux
version: ${{ inputs.uv-version }}

# Refresh the shell hashtable, to ensure correct `which` output.
hash -r

# `actions/cache@v3` doesn't always seem able to correctly unpack softlinks.
# Delete and recreate the softlinks pipx expects to have.
rm /opt/pipx/venvs/poetry/bin/python
cd /opt/pipx/venvs/poetry/bin
ln -s "$(which "python$PYTHON_VERSION")" python
chmod +x python
cd /opt/pipx_bin/
ln -s /opt/pipx/venvs/poetry/bin/poetry poetry
chmod +x poetry

# Ensure everything got set up correctly.
/opt/pipx/venvs/poetry/bin/python --version
/opt/pipx_bin/poetry --version

- name: Install poetry
if: steps.cache-bin-poetry.outputs.cache-hit != 'true'
# Use a stable, repo-local cache dir so Actions cache works across runners.
- name: Set uv cache dir
shell: bash
env:
POETRY_VERSION: ${{ inputs.poetry-version }}
PYTHON_VERSION: ${{ inputs.python-version }}
# Install poetry using the python version installed by setup-python step.
run: pipx install "poetry==$POETRY_VERSION" --python '${{ steps.setup-python.outputs.python-path }}' --verbose
run: echo "UV_CACHE_DIR=$GITHUB_WORKSPACE/.uv_cache" >> "$GITHUB_ENV"

- name: Restore pip and poetry cached dependencies
- name: Restore uv and venv caches
uses: actions/cache@v4
env:
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "4"
with:
path: |
~/.cache/pip
~/.cache/pypoetry/virtualenvs
~/.cache/pypoetry/cache
~/.cache/pypoetry/artifacts
./.uv_cache
./.venv
key: py-deps-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-poetry-${{ inputs.poetry-version }}-${{ inputs.cache-key }}-${{ hashFiles('./poetry.lock') }}
key: >
uv-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-${{ inputs.cache-key }}-
${{ hashFiles('pyproject.toml') }}-
${{ hashFiles('uv.lock') }}
restore-keys: |
uv-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-${{ inputs.cache-key }}-
uv-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-
uv-${{ runner.os }}-${{ runner.arch }}-

- name: Sync dependencies with uv
shell: bash
run: uv sync ${{ inputs.uv-sync-flags }}

- name: Show env info
shell: bash
run: |
uv --version
uv pip list | head -n 50
41 changes: 32 additions & 9 deletions .github/workflows/clear-and-update-index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,52 @@ jobs:
build:
runs-on: ubuntu-latest
environment: Indexing

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v6
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: "3.11"

- name: Install uv
uses: astral-sh/setup-uv@v6

- name: Install Poetry
uses: snok/install-poetry@v1
- name: Pin uv cache dir
shell: bash
run: echo "UV_CACHE_DIR=$GITHUB_WORKSPACE/.uv_cache" >> "$GITHUB_ENV"

- name: Restore caches (.venv and uv)
uses: actions/cache@v4
with:
path: |
./.uv_cache
./.venv
key: >
index-${{ runner.os }}-${{ runner.arch }}-py-3.11-
${{ hashFiles('pyproject.toml') }}-
${{ hashFiles('uv.lock') }}
restore-keys: |
index-${{ runner.os }}-${{ runner.arch }}-py-3.11-
index-${{ runner.os }}-${{ runner.arch }}-

- name: Install dependencies
run: poetry install
- name: Sync dependencies
shell: bash
run: uv sync --all-groups --frozen

- name: Clear index
run: poetry run python _scripts/clear_index.py
shell: bash
run: uv run python _scripts/clear_index.py
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
WEAVIATE_URL: ${{ secrets.WEAVIATE_URL }}
WEAVIATE_API_KEY: ${{ secrets.WEAVIATE_API_KEY }}
RECORD_MANAGER_DB_URL: ${{ secrets.RECORD_MANAGER_DB_URL }}

- name: Ingest docs
run: poetry run python backend/ingest.py
shell: bash
run: uv run python backend/ingest.py
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
WEAVIATE_URL: ${{ secrets.WEAVIATE_URL }}
Expand Down
37 changes: 28 additions & 9 deletions .github/workflows/eval.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,37 @@ jobs:
runs-on: ubuntu-latest
environment: Evaluation
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Set up Python + Poetry
uses: "./.github/actions/poetry_setup"
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
poetry-version: "1.7.1"
cache-key: eval

- name: Install dependencies
run: poetry install --with dev
- name: Install uv
uses: astral-sh/setup-uv@v6

- name: Pin uv cache dir
shell: bash
run: echo "UV_CACHE_DIR=$GITHUB_WORKSPACE/.uv_cache" >> "$GITHUB_ENV"

- name: Restore caches (.venv and uv)
uses: actions/cache@v4
with:
path: |
./.uv_cache
./.venv
key: >
eval-${{ runner.os }}-${{ runner.arch }}-py-3.11-
${{ hashFiles('pyproject.toml') }}-
${{ hashFiles('uv.lock') }}
restore-keys: |
eval-${{ runner.os }}-${{ runner.arch }}-py-3.11-
eval-${{ runner.os }}-${{ runner.arch }}-

- name: Sync dependencies (frozen)
shell: bash
run: uv sync --all-groups --frozen

- name: Evaluate
env:
Expand All @@ -32,4 +51,4 @@ jobs:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
WEAVIATE_URL: ${{ secrets.WEAVIATE_URL }}
WEAVIATE_API_KEY: ${{ secrets.WEAVIATE_API_KEY }}
run: poetry run pytest backend/tests/evals
run: uv run pytest backend/tests/evals
60 changes: 34 additions & 26 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ on:
pull_request:

env:
POETRY_VERSION: "1.7.1"

# This env var allows us to get inline annotations when ruff has complaints.
# For inline annotations from ruff
RUFF_OUTPUT_FORMAT: github

jobs:
Expand All @@ -23,38 +21,48 @@ jobs:
# GitHub rate-limits how many jobs can be running at any one time.
# Starting new jobs is also relatively slow,
# so linting on fewer versions makes CI faster.
python-version:
- "3.11"
python-version: ["3.11"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
cache-key: lint
version: "0.8.23"

- name: Check Poetry File
- name: Pin uv cache dir
shell: bash
run: poetry check

- name: Check lock file
shell: bash
run: poetry lock --check

- name: Install dependencies
run: poetry install --with dev
run: echo "UV_CACHE_DIR=$GITHUB_WORKSPACE/.uv_cache" >> "$GITHUB_ENV"

- name: Get .mypy_cache to speed up mypy
uses: actions/cache@v3
env:
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "2"
- name: Restore caches (.venv and uv)
uses: actions/cache@v4
with:
path: |
./.uv_cache
./.venv
./.mypy_cache
key: mypy-lint-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{ hashFiles('./poetry.lock') }}
key: >
lint-${{ runner.os }}-${{ runner.arch }}-py-${{ matrix.python-version }}-
${{ hashFiles('pyproject.toml') }}-
${{ hashFiles('uv.lock') }}
restore-keys: |
lint-${{ runner.os }}-${{ runner.arch }}-py-${{ matrix.python-version }}-
lint-${{ runner.os }}-${{ runner.arch }}-

- name: Analysing the code with our lint
# Ensure deps match the lock (fails if lock is stale)
- name: Sync dependencies (frozen)
shell: bash
run: uv sync --all-groups --frozen

- name: Show tool versions
shell: bash
run: |
make lint
uv --version
.venv/bin/python -V
.venv/bin/ruff -V || true
.venv/bin/mypy -V || true

- name: Lint
shell: bash
run: uv run make lint
43 changes: 34 additions & 9 deletions .github/workflows/update-index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,48 @@ on:
default: false
type: boolean
schedule:
- cron: '0 13 * * 1'
- cron: '0 13 * * 1'

jobs:
build:
runs-on: ubuntu-latest
environment: Indexing
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v6
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install dependencies
run: poetry install
python-version: "3.11"

- name: Install uv
uses: astral-sh/setup-uv@v6

- name: Pin uv cache dir
shell: bash
run: echo "UV_CACHE_DIR=$GITHUB_WORKSPACE/.uv_cache" >> "$GITHUB_ENV"

- name: Restore caches (.venv and uv)
uses: actions/cache@v4
with:
path: |
./.uv_cache
./.venv
key: >
update-index-${{ runner.os }}-${{ runner.arch }}-py-3.11-
${{ hashFiles('pyproject.toml') }}-
${{ hashFiles('uv.lock') }}
restore-keys: |
update-index-${{ runner.os }}-${{ runner.arch }}-py-3.11-
update-index-${{ runner.os }}-${{ runner.arch }}-

- name: Sync dependencies
shell: bash
run: uv sync --all-groups --frozen

- name: Ingest docs
run: poetry run python backend/ingest.py
shell: bash
run: uv run python backend/ingest.py
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
WEAVIATE_URL: ${{ secrets.WEAVIATE_URL }}
Expand Down
Loading