Skip to content

Commit

Permalink
Add CI configs for running tests (#46)
Browse files Browse the repository at this point in the history
This PR adds run-test job to the CI pipeline. It also introduces a new invoke task to install dependencies to make the setup operations clean and minimal.

Issue: #12
  • Loading branch information
zahraaalizadeh authored Apr 15, 2024
2 parents 7159cfa + de97e35 commit 9eaccff
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 27 deletions.
22 changes: 2 additions & 20 deletions .github/workflows/startproject.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,8 @@ jobs:
libffi-dev \
libpq-dev
# Playwright System Dependencies
sudo apt-get install -y \
libnss3\
libnspr4\
libatk1.0-0\
libatk-bridge2.0-0\
libcups2\
libdrm2\
libxkbcommon0\
libatspi2.0-0\
libxcomposite1\
libxdamage1\
libxfixes3\
libxrandr2\
libgbm1\
libasound2
# Base Python tooling
pip install poetry django
pip install invoke poetry django
- name: Create test project
run: |
Expand All @@ -80,8 +63,7 @@ jobs:
- name: Install test project
run: |
cd test_project
poetry install
poetry run playwright install
poetry run invoke install
- name: Check test project is valid
run: |
Expand Down
104 changes: 101 additions & 3 deletions template/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Install dependencies
run: |
pip install invoke poetry
poetry install
invoke install --skip-install-playwright
- name: Run linting and formatting
run: |
Expand All @@ -40,7 +40,7 @@ jobs:
- name: Install dependencies
run: |
pip install invoke poetry
poetry install
invoke install --skip-install-playwright
cp example.env .env
- name: Run type-checking
Expand All @@ -61,7 +61,7 @@ jobs:
- name: Install dependencies
run: |
pip install invoke poetry
poetry install
invoke install --skip-install-playwright
- name: Build the documentation
# When running the ci locally using act, MkDocs build fails at "make html" with
Expand All @@ -72,3 +72,101 @@ jobs:
# NOTE: it runs fine when pushing to Github, but unfortunately not in act.
# link to issue on act repository: https://github.com/nektos/act/issues/1853
run: TZ=UTC poetry run invoke build-docs

run-system-tests:
name: Run System Test Suite
runs-on: ubuntu-latest

services:
postgres:
image: postgres:14
env:
POSTGRES_USER: dev
POSTGRES_PASSWORD: dev_password
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Allows us to use the same env config used locally by mapping to port to
# the test runner container.
- 5432:5432

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install dependencies
run: |
sudo apt-get update
# Project System Dependencies
sudo apt-get install -y \
build-essential \
libffi-dev \
libpq-dev
pip install invoke poetry
invoke install --skip-install-playwright
cp example.env .env
- name: Run the system test suite
run: poetry run invoke test --suite=system

run-functional-tests:
name: Run Functional Test Suite
runs-on: ubuntu-latest

services:
postgres:
image: postgres:14
env:
POSTGRES_USER: dev
POSTGRES_PASSWORD: dev_password
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Allows us to use the same env config used locally by mapping to port to
# the test runner container.
- 5433:5432

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install dependencies
run: |
sudo apt-get update
# Project System Dependencies
sudo apt-get install -y \
build-essential \
libffi-dev \
libpq-dev
pip install invoke poetry
invoke install
cp example.env .env
# Since there are separate jobs for running system and functional tests independently,
# and we use different ports to access the database, the following configuration sets up
# the environment variable to point to the correct database URL.
- name: Set DATABASE_URL for functional tests
run: echo "DATABASE_URL=postgres://dev:dev_password@localhost:5433/dev" >> $GITHUB_ENV

- name: Run the functional test suite
run: poetry run invoke test --suite=functional
21 changes: 17 additions & 4 deletions template/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def help(ctx):


@invoke.task
def format(ctx, check:bool = False) -> None:
def format(ctx, check: bool = False) -> None:
"""
Apply automatic code formatting tools
Expand Down Expand Up @@ -138,9 +138,6 @@ def test(ctx, name="", verbose=False, suite=None):
"""
Runs the test suite
"""

ctx.run("poetry run playwright install") # ensure we have a playwright browser

title_suffix = "S"
args = ["poetry run pytest"]
if verbose:
Expand Down Expand Up @@ -227,6 +224,22 @@ def run_docs(ctx):
ctx.run("poetry run mkdocs serve")


@invoke.task
def install(ctx, skip_install_playwright: bool = False):
"""
Install system dependencies necessary for the {{ project_name }} project.
This task optionally skips the installation of Playwright dependencies,
which is useful for CI pipelines where Playwright is not needed,
thereby improving the build performance.
"""
_title("Installing Dependencies")
ctx.run("poetry install")

if not skip_install_playwright:
_title("Installing Playwright Dependencies")
ctx.run("poetry run playwright install --with-deps")

###########
# HELPERS #
###########
Expand Down

0 comments on commit 9eaccff

Please sign in to comment.