[DOP-11675] - add tests to github workflow #12
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tests | |
on: | |
push: | |
branches-ignore: | |
- dependabot/** | |
- pre-commit-ci-update-config | |
pull_request: | |
branches-ignore: | |
- master | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
tests: | |
name: Run ${{ matrix.mark}} tests (${{ matrix.python-version }} on ${{ matrix.os }}) | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: ['3.7', '3.12'] | |
os: [ubuntu-latest] | |
mark: [all] | |
services: | |
db: | |
image: postgres:15-alpine | |
env: | |
# Init Postgres database | |
POSTGRES_DB: horizon | |
POSTGRES_USER: horizon | |
POSTGRES_PASSWORD: Aeviphai6juo3ooY7iecaivieX5OoMai | |
# See Backend -> Configuration documentation | |
HORIZON__DATABASE__URL: postgresql+asyncpg://horizon:Aeviphai6juo3ooY7iecaivieX5OoMai@db:5432/horizon | |
HORIZON__AUTH__ACCESS_TOKEN__SECRET_KEY: bae1thahr8Iyaisai0kohvoh1aeg5quu | |
HORIZON__AUTH__PROVIDER: horizon.backend.providers.auth.dummy.DummyAuthProvider | |
HORIZON__SERVER__LOGGING__PRESET: colored | |
HORIZON__SERVER__DEBUG: false | |
ports: | |
- 5432:5432 | |
ldap: | |
image: thoteam/slapd-server-mock | |
ports: | |
- 389:389 | |
- 636:636 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Build Backend Container | |
run: docker build -t backend:${{ github.sha }} -f docker/Dockerfile.backend . | |
- name: Start Backend Container | |
run: | | |
docker run -d --name backend --restart unless-stopped --network host --env-file .env.docker -p 8000:8000 -v $(pwd):/app backend:${{ github.sha }} | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install system dependencies | |
# this step is needed for successful installation of "bonsai" library in python dependencies | |
run: sudo apt-get update && sudo apt-get install -y libldap2-dev libsasl2-dev | |
- name: Install poetry | |
uses: snok/install-poetry@v1 | |
with: | |
virtualenvs-create: true | |
virtualenvs-in-project: true | |
- name: Cache poetry | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cache/pypoetry | |
key: ${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-codeql-${{ hashFiles('**/poetry.lock') }} | |
restore-keys: | | |
${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-codeql-${{ hashFiles('**/poetry.lock') }} | |
${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-codeql- | |
${{ runner.os }}-python | |
${{ runner.os }}- | |
- name: Install dependencies | |
run: | | |
poetry install --no-root --all-extras --with dev,test,docs | |
- name: Run Tests | |
run: | | |
source .env.local | |
mkdir -p reports/ | |
poetry run python -m horizon.backend.db.migrations upgrade head | |
poetry run coverage run -m pytest | |
poetry run coverage xml -o reports/coverage-${{ matrix.python-version }}.xml -i | |
- name: Upload Coverage Results | |
uses: actions/upload-artifact@v4 | |
with: | |
name: code-coverage-${{ matrix.python-version }} | |
path: reports/coverage-${{ matrix.python-version }}.xml | |
all_done: | |
name: Tests done | |
runs-on: ubuntu-latest | |
needs: [tests] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Download all coverage reports | |
uses: actions/download-artifact@v4 | |
with: | |
path: reports | |
- name: Move coverage reports to the root folder | |
run: find reports -type f -exec mv '{}' reports \; | |
- name: Check coverage | |
uses: codecov/codecov-action@v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
directory: ./reports | |
fail_ci_if_error: true | |
- name: All done | |
run: echo 1 |