Skip to content

Tests

Tests #2727

Workflow file for this run

# If you change this name also do it in tests_skipper.yml and ci_metrics.yml
name: Tests
on:
# Activate this workflow manually
workflow_dispatch:
# Run tests nightly against Haystack's main branch
schedule:
- cron: "0 0 * * *"
push:
branches:
- main
pull_request:
types:
- opened
- reopened
- synchronize
paths:
- "haystack_experimental/**/*.py"
- "test/**/*.py"
- "pyproject.toml"
- ".github/workflows/tests.yml"
permissions:
id-token: write
contents: read
env:
PYTHON_VERSION: "3.10"
HATCH_VERSION: "1.14.2"
PYTHONUNBUFFERED: "1"
FORCE_COLOR: "1"
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
MEM0_API_KEY: ${{ secrets.MEM0_API_KEY }}
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
AWS_REGION: "us-east-1"
jobs:
linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Get changed files
id: files
uses: tj-actions/changed-files@v47
with:
files_yaml: |
python:
- '**/*.py'
- '!test/**'
pyproject:
- 'pyproject.toml'
- uses: actions/setup-python@v6
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Install Hatch
run: pip install hatch==${{ env.HATCH_VERSION }}
- name: Ruff - check format and linting
run: hatch run fmt-check
- name: Pylint
# Running pylint on pyproject.toml causes errors, so we only run it on python files.
if: steps.files.outputs.python_any_changed == 'true'
run: |
hatch run test:lint ${{ steps.files.outputs.python_all_changed_files }}
- name: Typing
if: steps.files.outputs.python_any_changed == 'true' || steps.files.outputs.pyproject_any_changed == 'true'
run: |
mkdir .mypy_cache
hatch run test:types
unit-tests:
name: Unit / ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v6
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Install Hatch
run: pip install hatch==${{ env.HATCH_VERSION }}
- name: Run
run: hatch run test:unit
- name: Coveralls
# We upload only coverage for ubuntu as handling both os
# complicates the workflow too much for little to no gain
if: matrix.os == 'ubuntu-latest'
uses: coverallsapp/github-action@v2
with:
path-to-lcov: coverage.xml
- name: Nightly - run unit tests with Haystack main branch
if: github.event_name == 'schedule'
id: nightly-haystack-main
run: |
hatch env prune
hatch -e test env run -- uv pip install git+https://github.com/deepset-ai/haystack.git@main
hatch run test:unit
integration-tests:
name: Integration / ${{ matrix.os }}
needs: linting
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v6
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Install Hatch
run: pip install hatch==${{ env.HATCH_VERSION }}
# Do not authenticate on PRs from forks and on PRs created by dependabot
- name: AWS authentication
id: aws-auth
if: github.event_name == 'schedule' || (github.event.pull_request.head.repo.full_name == github.repository && !startsWith(github.event.pull_request.head.ref, 'dependabot/'))
uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ secrets.AWS_CI_ROLE_ARN }}
- name: Run
if: success() && steps.aws-auth.outcome == 'success'
run: hatch run test:integration-retry