Skip to content

Commit

Permalink
Various improvements in tests/CI (#1271)
Browse files Browse the repository at this point in the history
* Run unit tests with all supported Python versions.
* Caching of Python deps in CI.
   Special care taken of python-poetry/poetry#2117
* Local action for DRY Python/Poetry install with caching.
  • Loading branch information
dokterbob committed Sep 2, 2024
1 parent 86798bc commit 48502a5
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 32 deletions.
46 changes: 46 additions & 0 deletions .github/actions/poetry-python-install/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: 'Install Python, poetry and dependencies.'
description: 'Install Python, Poetry and poetry dependencies using cache'

inputs:
python-version:
description: 'Python version'
required: true
poetry-version:
description: 'Poetry version'
required: true
poetry-working-directory:
description: 'Working directory for poetry command.'
required: false
default: '.'
poetry-install-args:
description: 'Extra arguments for poetry install, e.g. --with tests.'
required: false

defaults:
run:
shell: bash

runs:
using: 'composite'
steps:
- name: Cache poetry install
uses: actions/cache@v2
with:
path: ~/.local
key: poetry-${{ runner.os }}-${{ inputs.poetry-version }}-0
- name: Install Poetry
run: pipx install 'poetry==${{ inputs.poetry-version }}'
shell: bash
- name: Set up Python ${{ inputs.python-version }}
id: setup_python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
cache: poetry
cache-dependency-path: ${{ inputs.poetry-working-directory }}/poetry.lock
- name: Set Poetry environment
run: poetry -C '${{ inputs.poetry-working-directory }}' env use '${{ steps.setup_python.outputs.python-path }}'
shell: bash
- name: Install Python dependencies
run: poetry -C '${{ inputs.poetry-working-directory }}' install ${{ inputs.poetry-install-args }}
shell: bash
18 changes: 9 additions & 9 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
env:
BACKEND_DIR: ./backend
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8.6.9
- uses: ./.github/actions/poetry-python-install
name: Install Python, poetry and Python dependencies
with:
python-version: 3.9
poetry-version: 1.8.3
poetry-working-directory: ${{ env.BACKEND_DIR }}
poetry-install-args: --with tests
- name: Use Node.js 16.15.0
uses: actions/setup-node@v3
with:
node-version: '16.15.0'
cache: 'pnpm'
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip'
- name: Install Poetry
run: pip install poetry
- name: Install JS dependencies
run: pnpm install --no-frozen-lockfile
- name: Build UI
run: pnpm run buildUi
- name: Lint UI
run: pnpm run lintUi
- name: Install Python dependencies
run: poetry install -C ./backend --with tests
- name: Run tests
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
Expand Down
20 changes: 9 additions & 11 deletions .github/workflows/mypy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ on: [workflow_call]
jobs:
mypy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend
env:
BACKEND_DIR: ./backend
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
- uses: ./.github/actions/poetry-python-install
name: Install Python, poetry and Python dependencies
with:
python-version: '3.9'
cache: 'pip'
- name: Install Poetry
run: pip install poetry
- name: Install dependencies
run: poetry install --with tests --with mypy --with custom-data
python-version: 3.9
poetry-version: 1.8.3
poetry-install-args: --with tests --with mypy --with custom-data
poetry-working-directory: ${{ env.BACKEND_DIR }}
- name: Run Mypy
run: poetry run mypy chainlit/
working-directory: ${{ env.BACKEND_DIR }}
25 changes: 13 additions & 12 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ name: Pytest
on: [workflow_call]

jobs:
mypy:
pytest:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
env:
BACKEND_DIR: ./backend
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
- uses: ./.github/actions/poetry-python-install
name: Install Python, poetry and Python dependencies
with:
python-version: '3.9'
cache: 'pip'
- name: Install Poetry
run: pip install poetry
- name: Install dependencies
run: poetry install --with tests --with mypy --with custom-data
python-version: ${{ matrix.python-version }}
poetry-version: 1.8.3
poetry-install-args: --with tests --with mypy --with custom-data
poetry-working-directory: ${{ env.BACKEND_DIR }}
- name: Run Pytest
run: poetry run pytest --cov=chainlit/
working-directory: ${{ env.BACKEND_DIR }}

0 comments on commit 48502a5

Please sign in to comment.