From dfeb3d6f9407c0e92b9fc5fd3fccf8bcbd5e1d07 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 8 Dec 2025 19:57:47 +0900 Subject: [PATCH] .gitea/workflows: init test pipeline --- .gitea/workflows/test.yaml | 81 ++++++++++++++++++++++++++++++++++++++ .gitignore | 2 + README.md | 4 ++ nix/shell.nix | 1 + pyproject.toml | 4 +- uv.lock | 19 +++++---- 6 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 .gitea/workflows/test.yaml diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml new file mode 100644 index 0000000..ed75702 --- /dev/null +++ b/.gitea/workflows/test.yaml @@ -0,0 +1,81 @@ +name: Run tests +on: + pull_request: + push: + workflow_dispatch: + inputs: + debug_sql: + description: "Print SQL statements executed by SQLAlchemy during tests" + type: boolean + default: True + +env: + DEBUG_SQL: ${{ inputs.debug_sql || true }} + +jobs: + run-tests: + runs-on: debian-latest + steps: + - uses: actions/checkout@v6 + + - name: Install uv + uses: astral-sh/setup-uv@v7 + + - name: Install dependencies + run: uv sync --locked --group test + + - name: Run tests + continue-on-error: true + run: | + set -euo pipefail + set -x + + PYTEST_ARGS=( + -vv + + --cov=dibbler.lib + --cov=dibbler.models + --cov=dibbler.queries + --cov-report=html + --cov-branch + + --self-contained-html + --html=./test-report/index.html + ) + + if [ "$DEBUG_SQL" == "true" ]; then + PYTEST_ARGS+=( + --debug-sql + ) + fi + + uv run -- pytest "${PYTEST_ARGS[@]}" + + - name: Generate badge + run: uv run -- coverage-badge -o htmlcov/badge.svg + + - name: Upload test report + uses: https://git.pvv.ntnu.no/Projects/rsync-action@v1 + with: + source: ./test-report/ + target: ${{ gitea.ref_name }}/test-report/ + username: gitea-web + ssh-key: ${{ secrets.WEB_SYNC_SSH_KEY }} + host: pages.pvv.ntnu.no + known-hosts: "pages.pvv.ntnu.no ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIH2QjfFB+city1SYqltkVqWACfo1j37k+oQQfj13mtgg" + + - name: Upload coverage report + uses: https://git.pvv.ntnu.no/Projects/rsync-action@v1 + with: + source: ./htmlcov/ + target: ${{ gitea.ref_name }}/coverage/ + username: gitea-web + ssh-key: ${{ secrets.WEB_SYNC_SSH_KEY }} + host: pages.pvv.ntnu.no + known-hosts: "pages.pvv.ntnu.no ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIH2QjfFB+city1SYqltkVqWACfo1j37k+oQQfj13mtgg" + + - name: Check failure + if: failure() + run: | + echo "Tests failed" + exit 1 diff --git a/.gitignore b/.gitignore index 10d5554..2aaeea2 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ test.db .ruff_cache .coverage +htmlcov +test-report diff --git a/README.md b/README.md index 55f7063..4bdd8b7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +[![Coverage](https://pages.pvv.ntnu.no/Projects/dibbler/event-sourcing/coverage/badge.svg)](https://pages.pvv.ntnu.no/Projects/dibbler/event-sourcing/coverage) +[![Test report](https://img.shields.io/badge/status-grab_the_latest_test_report-blue)](https://pages.pvv.ntnu.no/Projects/dibbler/event-sourcing/test-report) + # Dibbler EDB-system for PVVVV @@ -41,6 +44,7 @@ Du kan også endre hvilken config-fil som blir brukt direkte i pakken eller i mo Se eksempelet for hvordan skrot er satt opp i `flake.nix` og `nix/skrott.nix` ### Bygge image for skrot + Skrot har et image definert i flake.nix: 1. endre `example-config.ini` diff --git a/nix/shell.nix b/nix/shell.nix index e4463d1..adb6302 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -19,6 +19,7 @@ mkShell { pytest pytest-cov + pytest-html ])) ]; } diff --git a/pyproject.toml b/pyproject.toml index 11f0a5b..89b2db5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,8 +20,8 @@ dependencies = [ ] dynamic = ["version"] -[project.optional-dependencies] -dev = [ +[dependency-groups] +test = [ "pytest", "pytest-cov", "coverage-badge>=1.1.2", diff --git a/uv.lock b/uv.lock index 327af49..ca56931 100644 --- a/uv.lock +++ b/uv.lock @@ -256,8 +256,8 @@ dependencies = [ { name = "sqlalchemy" }, ] -[package.optional-dependencies] -dev = [ +[package.dev-dependencies] +test = [ { name = "coverage-badge" }, { name = "pytest" }, { name = "pytest-cov" }, @@ -268,17 +268,20 @@ dev = [ [package.metadata] requires-dist = [ { name = "brother-ql" }, - { name = "coverage-badge", marker = "extra == 'dev'", specifier = ">=1.1.2" }, { name = "matplotlib" }, { name = "psycopg2-binary", specifier = ">=2.8,<2.10" }, - { name = "pytest", marker = "extra == 'dev'" }, - { name = "pytest-cov", marker = "extra == 'dev'" }, - { name = "pytest-html", marker = "extra == 'dev'", specifier = ">=4.1.1" }, { name = "python-barcode" }, { name = "sqlalchemy", specifier = ">=2.0,<2.1" }, - { name = "sqlparse", marker = "extra == 'dev'", specifier = ">=0.5.4" }, ] -provides-extras = ["dev"] + +[package.metadata.requires-dev] +test = [ + { name = "coverage-badge", specifier = ">=1.1.2" }, + { name = "pytest" }, + { name = "pytest-cov" }, + { name = "pytest-html", specifier = ">=4.1.1" }, + { name = "sqlparse", specifier = ">=0.5.4" }, +] [[package]] name = "fonttools"