Skip to content

Commit

Permalink
ci: run tests after linting
Browse files Browse the repository at this point in the history
  • Loading branch information
xenophonf committed Nov 30, 2023
1 parent 3d920d5 commit de62e92
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 12 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Test

# Trigger this workflow manually or after linting.
on:
workflow_dispatch:
workflow_run:
workflows:
- Lint
types:
- completed

jobs:
test-matrix:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- '3.10'
- '3.11'
- '3.12'
steps:
- uses: actions/cache/restore@v3
with:
key: workdir-${{ github.sha }}
path: .
# Computer science has only 3 hard problems: naming things,
# cache invaconcurrency, lidation, and off-by-one errors.
- id: hash-sources
run: |
echo "hash=$(find src tests -type f -exec cat '{}' \; | sha512sum | awk '{print $1}')" >> $GITHUB_OUTPUT
shell: bash
- id: cache-pytest
uses: actions/cache@v3
with:
key: pytest-${{ matrix.python-version }}-${{ steps.hash-sources.outputs.hash }}
lookup-only: true
path: pytest.out
- if: steps.cache-pytest.outputs.cache-hit != 'true'
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
- if: steps.cache-pytest.outputs.cache-hit != 'true'
name: Install test infrastructure
run: |
sudo make build-deps
pip install .[psycopg2cffi,test]
USER_SITE=`python -m site --user-site`
mkdir -p "${USER_SITE}"
echo "from psycopg2cffi import compat" > "${USER_SITE}/psycopg2.py"
echo "compat.register()" >> "${USER_SITE}/psycopg2.py"
- if: steps.cache-pytest.outputs.cache-hit != 'true'
uses: pavelzw/pytest-action@v2
with:
custom-arguments: --cov=stuart --report-log=pytest.out
91 changes: 79 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,95 @@
# License along with this program. If not, see
# <https://www.gnu.org/licenses/>.

stuart.egg-info: .venv
. .venv/bin/activate; pip install -e .[dev,test]
# Install Stuart in a virtual environment. (See also the build-deps target.)

PYV = $(shell python3 -c "import sys;print('{}.{}'.format(*sys.version_info[:2]))")

dev-infra: .venv/lib/python$(PYV)/site-packages/psycopg2.py

.venv/lib/python$(PYV)/site-packages/psycopg2.py: stuart.egg-info
echo "from psycopg2cffi import compat\ncompat.register()" > $@

stuart.egg-info: .venv pyproject.toml src/*.py
. .venv/bin/activate; pip install -U pip setuptools
. .venv/bin/activate; pip install -e .[psycopg2cffi,dev,test]

venv: .venv

.venv:
python3 -m venv --system-site-packages $@
python3 -m venv $@

debug: stuart.egg-info
debug run: stuart.egg-info
. .venv/bin/activate; python3 -m flask --debug --app stuart.app run

run: debug
smoke: dev-infra
. .venv/bin/activate; pytest -m "smoke and not slow"

test: stuart.egg-info
test tests: dev-infra
. .venv/bin/activate; pytest

coverage: stuart.egg-info
coverage: dev-infra
. .venv/bin/activate; pytest --cov=stuart

clean:
rm -rf .coverage stuart.egg-info .pytest_cache .venv*
find . -type d -name __pycache__ -print | xargs rm -rf
dist: dev-infra
. .venv/bin/activate; python -m build

distcheck: dist
. .venv/bin/activate; twine check dist/*

distclean:
rm -rf dist

# Install, run, or update pre-commit hooks.

pre-commit: .git/hooks/pre-commit

container:
.git/hooks/pre-commit: .pre-commit-config.yaml dev-infra
. .venv/bin/activate; pre-commit install --install-hooks

check checks lint: pre-commit
. .venv/bin/activate; pre-commit validate-config
. .venv/bin/activate; pre-commit validate-manifest
. .venv/bin/activate; pre-commit run --show-diff-on-failure --all-files

# Install Stuart in a container image.
builder tester:
docker build -t stuart:$@ --target $@ .

container docker:
docker build -t stuart .

docker: container
prune:
docker system prune --all --volumes --force

# Install (or remove) build dependencies on Debian/Ubuntu. Note that
# these targets must be invoked by root. Also note that the
# purge-deps target can remove packages other that the ones listed
# here, so keep the confirmation prompts to avoid footguns.

DEBIAN_BUILD_DEPS = build-essential devscripts equivs postgresql
DEBIAN_INSTALL_TOOL = apt-get -o Debug::pkgProblemResolver=yes -y --no-install-recommends

build-deps: /etc/debian_version
ifneq ($(shell id -u), 0)
@echo You must be root to perform this action.
@exit 1
endif
sed -i '/deb-src/s/^# //' /etc/apt/sources.list
apt-get update
$(DEBIAN_INSTALL_TOOL) install $(DEBIAN_BUILD_DEPS)
mk-build-deps -i -r -t "$(DEBIAN_INSTALL_TOOL)" python3-psycopg2
mk-build-deps -i -r -t "$(DEBIAN_INSTALL_TOOL)" python3-psycopg2cffi
rm -f *.buildinfo *.changes

clean-deps: /etc/debian_version
ifneq ($(shell id -u), 0)
@echo You must be root to perform this action.
@exit 1
endif
apt-mark auto $(DEBIAN_BUILD_DEPS) psycopg2-build-deps python-psycopg2cffi-build-deps
apt-get autoremove

clean:
rm -rf build .coverage dist lethbridge.egg-info .pytest_cache .venv*
find . -type d -name __pycache__ -print | xargs rm -rf
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ psycopg2cffi = [
test = [
"pytest",
"pytest-cov",
"pytest-emoji",
"pytest-md",
"pytest-order",
"pytest-reportlog",
]
Expand Down
File renamed without changes.

0 comments on commit de62e92

Please sign in to comment.