diff --git a/.env b/.env new file mode 100644 index 0000000..43303f6 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +# env file for docker-compose +ENVFILE=static-docker-env diff --git a/.laminar b/.laminar index 9c767ab..d484957 100755 --- a/.laminar +++ b/.laminar @@ -29,11 +29,6 @@ then #green "Dump of docker-env:" #cat ../docker-env - - - # TODO: fix later - exit 0 - cd ci #green "Dump docker-compose config:" diff --git a/ci/.env b/ci/.env new file mode 120000 index 0000000..4a82335 --- /dev/null +++ b/ci/.env @@ -0,0 +1 @@ +../.env \ No newline at end of file diff --git a/ci/docker-compose.yml b/ci/docker-compose.yml new file mode 100644 index 0000000..5a83596 --- /dev/null +++ b/ci/docker-compose.yml @@ -0,0 +1,30 @@ +version: '3' + +services: + sut: + build: + context: docker + dockerfile: Dockerfile + args: + PYTHON_TAG: ${PYTHON:-3}-bullseye + volumes: + # Project data + - type: bind + source: ../ + target: /app + read_only: false + # pip cache + - type: volume + source: pip-cache + target: /root/.cache/pip + volume: + nocopy: true + + # environment file to passthrough environment from laminar - generated by laminar init template + # automatically-generated docker-env is situated in parent of repo dir (two levels up) + env_file: ${ENVFILE:-../../docker-env} + # make it faster + tmpfs: /tmp + +volumes: + pip-cache: # cache for pip diff --git a/ci/docker/Dockerfile b/ci/docker/Dockerfile new file mode 100644 index 0000000..c927c4d --- /dev/null +++ b/ci/docker/Dockerfile @@ -0,0 +1,47 @@ +ARG PYTHON_TAG=3 +FROM python:${PYTHON_TAG} + +RUN set -xeu ; \ + apt update ; \ + apt -yy full-upgrade ; \ + apt -yy install ca-certificates \ + libfontconfig1 \ + libfreetype6 \ + libx11-6 \ + libx11-xcb1 \ + libxext6 \ + libxfixes3 \ + libxi6 \ + libxrender1 \ + libxcb1 \ + libxcb-util1 \ + libxcb-glx0 \ + libxcb-keysyms1 \ + libxcb-image0 \ + libxcb-shm0 \ + libxcb-icccm4 \ + libxcb-sync1 \ + libxcb-xfixes0 \ + libxcb-shape0 \ + libxcb-randr0 \ + libxcb-render-util0 \ + libxcb-xinerama0 \ + libxkbcommon0 \ + libxkbcommon-x11-0 \ + libdbus-1-3 \ + xvfb xclip xsel xdotool; \ + python -m venv /venv ;\ + /venv/bin/pip install --upgrade pip ; \ + apt clean ; \ + rm -Rf /var/lib/apt/lists/* ; \ + mkdir /app + + + +ADD run-tests /usr/local/bin +ADD clilib /usr/local + +VOLUME /app +WORKDIR /app +CMD ["/usr/local/bin/run-tests"] + diff --git a/ci/docker/clilib b/ci/docker/clilib new file mode 100644 index 0000000..d50ea3a --- /dev/null +++ b/ci/docker/clilib @@ -0,0 +1,55 @@ +#!/bin/bash + +reset='\e[0m' +bold='\e[1m' +green='\e[92m' +red='\e[91m' +yellow='\e[93m' +cyan='\e[96m' + +status(){ + echo -e "$yellow$@$reset" +} + +ok() { + echo -e " [ $green${bold}OK$reset ]" +} + +error(){ + echo -e "$red - $@$reset" +} + +failure(){ + echo -e "$red - $@$reset" + exit +} + +info(){ + echo -e "$cyan$@$reset" +} + +infon(){ + echo -ne "$cyan$@$reset" +} + + +drawexit(){ + [ $1 -eq 0 ] && ok || error "Failed!" +} + +filelen(){ + wc -c $1 | cut -d' ' -f1 +} + +wraperr(){ + $@ && rc=0 || rc=$? + if [ $rc -eq 0 ] + then + ok 2>&1 + else + error "Command failed: \"$@\"" 2>&1 + error "Return code: $rc" 2>&1 + exit $rc + fi +} + diff --git a/ci/docker/run-tests b/ci/docker/run-tests new file mode 100755 index 0000000..450f603 --- /dev/null +++ b/ci/docker/run-tests @@ -0,0 +1,50 @@ +#!/bin/bash +set -euo pipefail +IFS=$'\n\t' + +# source cli lib +source /usr/local/clilib + +status "Preparing XDG_RUNTIME_DIR" +export XDG_RUNTIME_DIR=/tmp/xdg-runtime-dir +mkdir -p $XDG_RUNTIME_DIR + +# setup exit trap +function finish { + status "Changing ownership of /app directory" + perms=$(stat -c '%u:%g' /app) + wraperr chown -R $perms /app +} +trap finish EXIT + +status "Loading venv" +source /venv/bin/activate +echo $VIRTUAL_ENV + +status "Changing directory to /app" +wraperr cd /app + +status "Installing pip depenencies" +wraperr pip install -r requirements.txt + +status "Installing dev dependencies" +wraperr pip install -r requirements.dev. + +# TODO: fix later +exit 0 + +status "Preparing data trees for tests..." +wraperr bash -c "cd tests/_support_data; ./gen-data.sh" + +status "Running tests itself" +wraperr python3 -m pytest .\ + -v \ + -n auto \ + --ignore=tests/_support_data \ + --color=yes \ + --cov . \ + --cov-config .coveragerc \ + --cov-report term-missing \ + --cov-report html +exit 0 + diff --git a/ci/static-docker-env b/ci/static-docker-env new file mode 100644 index 0000000..768f92b --- /dev/null +++ b/ci/static-docker-env @@ -0,0 +1,3 @@ +# This is just dummy file which would be replaced by one generated in CI pipeline +PYTHON=3 + diff --git a/requirements.dev.txt b/requirements.dev.txt new file mode 100644 index 0000000..3b6f831 --- /dev/null +++ b/requirements.dev.txt @@ -0,0 +1,5 @@ +-r requirements.txt +pytest==6.2.5 +pyinstaller==4.5.1 +pytest-xdist==2.3.0 +pytest-cov==2.12.1 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..eebb98a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +gitdb==4.0.9 +GitPython==3.1.27 +smmap==5.0.0 diff --git a/test.py b/test.py new file mode 100755 index 0000000..d2b5087 --- /dev/null +++ b/test.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 + +from git import Repo + +r = Repo("/home/vasek/dev/repo-cloner") +print(r.bare)