Unit Tests #29
This file contains hidden or 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: Unit Tests | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| schedule: | |
| # Nightly drift check at 05:00 UTC — 1h after upstream-sync.yml rebases | |
| # the forks at 04:00 UTC, so this run exercises whatever landed on | |
| # maintenance/gramps60 overnight. Surfaces upstream regressions in a | |
| # scheduled failure instead of the next contributor's PR. | |
| - cron: '0 5 * * *' | |
| workflow_dispatch: | |
| inputs: | |
| gramps_repo: | |
| description: 'gramps repo (owner/name); empty = same-owner fork' | |
| default: '' | |
| gramps_ref: | |
| description: 'gramps branch/tag/sha; empty = matrix defaults' | |
| default: '' | |
| # See interface-tests.yml for rationale — dorny/test-reporter needs | |
| # checks: write + pull-requests: write, and the repo's default token | |
| # permissions are restrictive. | |
| permissions: | |
| contents: read | |
| checks: write | |
| pull-requests: write | |
| jobs: | |
| unit-tests: | |
| runs-on: ubuntu-24.04 | |
| timeout-minutes: 20 | |
| # Advisory gate. This job runs gramps' own *_test.py suite against an | |
| # upstream gramps checkout — failures here almost always reflect | |
| # upstream regressions or transient flakiness, not testbed bugs. | |
| # continue-on-error lets testbed PRs merge on upstream-caused red; | |
| # the blocking gate for the testbed is the interface smoke suite in | |
| # interface-tests.yml. Re-evaluate if the upstream suite stabilises. | |
| continue-on-error: true | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| # Supported Gramps minors. Add new maintenance branches here when | |
| # they exist upstream (e.g. - maintenance/gramps61) — each entry | |
| # produces a parallel job. | |
| gramps_ref: | |
| - maintenance/gramps60 | |
| steps: | |
| - name: Checkout testbed | |
| uses: actions/checkout@v4 | |
| with: | |
| path: gramps-testbed | |
| # Repo resolution (in order): workflow input → repository variable | |
| # → same-owner fork. Ref resolution: workflow input → matrix cell. | |
| # Matches interface-tests.yml so forking this testbed alone is | |
| # enough configuration. | |
| - name: Checkout gramps fork | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ github.event.inputs.gramps_repo || vars.GRAMPS_REPO || format('{0}/gramps', github.repository_owner) }} | |
| ref: ${{ github.event.inputs.gramps_ref || matrix.gramps_ref }} | |
| path: gramps | |
| - name: Install system dependencies | |
| # No xvfb/dbus/at-spi — unit tests do not launch the GUI. GTK | |
| # introspection bindings are still required because gramps.gen | |
| # imports gi at module load time. | |
| # | |
| # python3-venv / python3-pip are installed here so the next step | |
| # can build a venv that inherits python3-gi from the system | |
| # interpreter. | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y --no-install-recommends \ | |
| python3 python3-venv python3-pip \ | |
| python3-gi python3-gi-cairo python3-cairo python3-icu \ | |
| gir1.2-gtk-3.0 gir1.2-osmgpsmap-1.0 gir1.2-goocanvas-2.0 gir1.2-gexiv2-0.10 \ | |
| libgirepository1.0-dev \ | |
| gettext intltool \ | |
| librsvg2-common | |
| - name: Set up Python venv (inherits python3-gi from apt) | |
| # Ubuntu 24.04's apt python3-gi installs PyGObject into the system | |
| # Python's dist-packages only; a fresh interpreter from | |
| # setup-python@v5 can't see those bindings, and gramps.gen imports | |
| # gi on module load — so every gramps-touching command dies with | |
| # ModuleNotFoundError. --system-site-packages keeps pip installs | |
| # in the venv but inherits apt-provided bindings (gi, cairo, icu). | |
| # Replaces actions/setup-python@v5; pip cache is restored below | |
| # via actions/cache. | |
| run: | | |
| python3 -m venv --system-site-packages .venv | |
| echo "$GITHUB_WORKSPACE/.venv/bin" >> "$GITHUB_PATH" | |
| .venv/bin/python -m pip install --upgrade pip | |
| - name: Restore pip cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pip | |
| key: pip-${{ runner.os }}-${{ hashFiles('gramps-testbed/requirements-test.txt') }} | |
| restore-keys: | | |
| pip-${{ runner.os }}- | |
| - name: Install Python dependencies | |
| run: | | |
| pip install -r gramps-testbed/requirements-test.txt | |
| # [testing] extras pulls in jsonschema/mock/lxml from gramps setup.py, | |
| # which some of gramps' own *_test.py files import. | |
| pip install -e 'gramps[testing]' | |
| - name: Compile Gramps translations | |
| # Keeps gramps.gen imports quiet during test collection. Matches | |
| # the same step in interface-tests.yml. | |
| working-directory: gramps | |
| run: | | |
| for po in po/*.po; do | |
| lang=$(basename "$po" .po) | |
| dest="build/mo/$lang/LC_MESSAGES" | |
| mkdir -p "$dest" | |
| msgfmt "$po" -o "$dest/gramps.mo" | |
| done | |
| - name: Run unit tests | |
| # Mirrors the canonical command from ../gramps/AGENTS.md: | |
| # GRAMPS_RESOURCES=. python3 -m unittest discover -p "*_test.py" | |
| # xmlrunner is a drop-in replacement for unittest that also writes | |
| # JUnit XML. GRAMPS_RESOURCES=. is load-bearing — without it, | |
| # several plugin tests fail to locate resource files. | |
| working-directory: gramps | |
| env: | |
| GRAMPS_RESOURCES: . | |
| run: | | |
| mkdir -p "$GITHUB_WORKSPACE/gramps-testbed/test-results" | |
| python -m xmlrunner discover \ | |
| -p '*_test.py' \ | |
| -o "$GITHUB_WORKSPACE/gramps-testbed/test-results/" \ | |
| -v | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| # Matrix-scoped artifact name so parallel cells don't collide. | |
| name: unit-test-results-${{ strategy.job-index }} | |
| path: gramps-testbed/test-results/ | |
| - name: Publish test report | |
| if: always() | |
| uses: dorny/test-reporter@v1 | |
| with: | |
| # See interface-tests.yml for the working-directory rationale — | |
| # checkouts use `path:` subdirs so the workflow root isn't a | |
| # git repo; anchor on the testbed checkout. | |
| working-directory: gramps-testbed | |
| name: Unit Tests (${{ matrix.gramps_ref }}) | |
| path: test-results/*.xml | |
| reporter: java-junit |