Skip to content

Commit

Permalink
Merge pull request #17 from kiwix/backend-tests-qa
Browse files Browse the repository at this point in the history
set up CI/CD workflow for backend tests
  • Loading branch information
elfkuzco authored Jun 12, 2024
2 parents 661c4bb + 2954ee0 commit 0181ad1
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/backend-Tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Backend Tests

on:
pull_request:
push:
paths:
- 'backend/**'
branches:
- main

jobs:
run-tests:
runs-on: ubuntu-22.04

services:
postgresdb:
image: postgres:16.3-bookworm
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version-file: backend/pyproject.toml
architecture: x64

- name: Install dependencies (and project)
working-directory: backend
run: |
pip install -U pip
pip install -e .[test,scripts]
- name: Create extensions on the PostgreSQL database
run: >-
psql -c 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp";'
"host=localhost port=5432 dbname=postgres user=postgres password=postgres"
- name: Run the tests
working-directory: backend
env:
POSTGRES_URI: postgresql+psycopg://postgres:postgres@localhost:5432/postgres
run: inv coverage --args "-vvv"

- name: Upload coverage report to codecov
uses: codecov/codecov-action@v4
with:
directory: backend
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions backend/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def report_cov(ctx: Context, *, html: bool = False):
"""report coverage"""
ctx.run("coverage combine", warn=True, pty=use_pty)
ctx.run("coverage report --show-missing", pty=use_pty)
ctx.run("coverage xml", pty=use_pty)
if html:
ctx.run("coverage html", pty=use_pty)

Expand Down
1 change: 1 addition & 0 deletions worker/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def report_cov(ctx: Context, *, html: bool = False):
"""report coverage"""
ctx.run("coverage combine", warn=True, pty=use_pty)
ctx.run("coverage report --show-missing", pty=use_pty)
ctx.run("coverage xml", pty=use_pty)
if html:
ctx.run("coverage html", pty=use_pty)

Expand Down

0 comments on commit 0181ad1

Please sign in to comment.