diff --git a/.github/workflows/startproject.yml b/.github/workflows/startproject.yml index 72b5e60..2eadaed 100644 --- a/.github/workflows/startproject.yml +++ b/.github/workflows/startproject.yml @@ -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: | @@ -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: | diff --git a/template/.github/workflows/ci.yml b/template/.github/workflows/ci.yml index 560004f..9808760 100644 --- a/template/.github/workflows/ci.yml +++ b/template/.github/workflows/ci.yml @@ -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: | @@ -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 @@ -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 @@ -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 diff --git a/template/tasks.py b/template/tasks.py index c09e2a4..b5be320 100644 --- a/template/tasks.py +++ b/template/tasks.py @@ -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 @@ -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: @@ -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 # ###########