create venv in tests

This commit is contained in:
Arthur Vuillard 2023-07-07 12:28:17 +02:00
parent fb84d11e54
commit a7ab585599

View file

@ -1,23 +1,8 @@
stages:
- build
- test
- docker
- deploy
before_script:
- export CACHE_PATH="/venvs/${CI_PROJECT_NAME}/$(date +week-%V-%Y)"
- if [[ "$CI_COMMIT_BRANCH" == *"--no-cache"* ]] ; then export CACHE_PATH="/venvs/$CI_COMMIT_SHORT_SHA"; fi
venv:
stage: build
image: registry.gitlab.com/hashbangfr/docker_archlinux:python
script:
- echo "Creating virtual env..."
- if [ ! -d $CACHE_PATH/venv ] ; then virtualenv --python=python3.9 $CACHE_PATH/venv ; fi
- $CACHE_PATH/venv/bin/pip install --upgrade pip
- echo "Virtual env created."
tests:
stage: test
image: registry.gitlab.com/hashbangfr/docker_archlinux:python
@ -34,13 +19,19 @@ tests:
dependencies:
- venv
script:
- export CACHE_PATH="/venvs/${CI_PROJECT_NAME}/$(date +week-%V-%Y)"
- if [[ "$CI_COMMIT_BRANCH" == *"--no-cache"* ]] ; then export CACHE_PATH="/venvs/$CI_COMMIT_SHORT_SHA"; fi
- echo "Creating virtual env..."
- if [ ! -d $CACHE_PATH/venv ] ; then virtualenv --python=python3.11 $CACHE_PATH/venv ; fi
- $CACHE_PATH/venv/bin/pip install --upgrade pip
- echo "Virtual env created."
- echo "Running tests..."
- source $CACHE_PATH/venv/bin/activate
- pip install -U -r requirements.txt
- pip install -U -r dev-requirements.txt
- pytest --create-db --cov --cov-report=xml
- if [ "$CI_COMMIT_REF_NAME" = 'main' ] ; then exit 0 ; fi
- if [ "$CI_COMMIT_REF_NAME" = 'develop' ] ; git fetch origin main ; then diff-cover coverage.xml --fail-under=90 && exit 0 ; fi
- if [ "$CI_COMMIT_REF_NAME" = 'develop' ] ; then git fetch origin main ; diff-cover coverage.xml --fail-under=90 --compare-branch origin/main && exit 0 ; fi
- git fetch origin develop ; diff-cover coverage.xml --fail-under=90 --compare-branch origin/develop
- echo "Tests done."