From c8479290bfe5eddaff51a0d76a8d5e69367d7389 Mon Sep 17 00:00:00 2001 From: elaynelemos Date: Tue, 23 Jun 2020 13:46:54 -0300 Subject: [PATCH 1/2] Updates gitlab ci process --- {{ cookiecutter.repo_name }}/.gitlab-ci.yml | 97 +++++++++++++++++---- {{ cookiecutter.repo_name }}/tox.ini | 8 +- 2 files changed, 80 insertions(+), 25 deletions(-) diff --git a/{{ cookiecutter.repo_name }}/.gitlab-ci.yml b/{{ cookiecutter.repo_name }}/.gitlab-ci.yml index c38f1c220..6fe105e97 100644 --- a/{{ cookiecutter.repo_name }}/.gitlab-ci.yml +++ b/{{ cookiecutter.repo_name }}/.gitlab-ci.yml @@ -1,27 +1,88 @@ image: python:3.8-slim-buster variables: - PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache" + PIP_CACHE_DIR: $CI_PROJECT_DIR/.cache + ARANGO_ROOT_PASSWORD: admin + TOX_CACHE_DIR: .tox/py38 + PYTEST_CACHE: pytest -cache: - paths: - - .cache/pip - - venv/ +stages: + - Clean_Up + - Tests -before_script: - - python -V - - pip install virtualenv - - virtualenv venv - - source venv/bin/activate - -test: - allow_failure: true +.tests-template: + stage: Tests script: - - pip install -U tox - - tox + - python -V only: - - master - - develop - - merge_requests + changes: + - {{ cookiecutter.repo_name }}/**/*.py + - tests/**/*.py + - .gitlab-ci.yml + refs: + - develop + - merge_request artifacts: expire_in: 1 week + +flake8: + extends: .tests-template + allow_failure: true + before_script: + - python -V + - pip install flake8 + script: + - flake8 {{ cookiecutter.repo_name }} tests --ignore=F401 + except: + refs: + - schedules + cache: {} + +pytest: + extends: .tests-template + image: image: python:3.8-buster + before_script: + - python -V + - cp env.example.py env.py + - pip install -U tox + script: + - tox + only: + changes: + - {{ cookiecutter.repo_name }}/**/* + - tests/**/* + - .gitlab-ci.yml + - requirements_dev.txt + - tox.ini + - "*.py" + refs: + - develop + - schedules + cache: + key: $PYTEST_CACHE + paths: + - $TOX_CACHE_DIR + +pytest:mr: + extends: pytest + only: + refs: + - merge_requests + except: + refs: + - schedules + cache: + policy: pull + +clean:on-schedule: + stage: Clean_Up + script: + - echo "Cleaning up cache!" + only: + refs: + - schedules + cache: + key: "$CACHE_KEY" + policy: push + paths: + - $CACHE_AT diff --git a/{{ cookiecutter.repo_name }}/tox.ini b/{{ cookiecutter.repo_name }}/tox.ini index 9edd3ae5e..5220b653c 100644 --- a/{{ cookiecutter.repo_name }}/tox.ini +++ b/{{ cookiecutter.repo_name }}/tox.ini @@ -1,10 +1,5 @@ [tox] -envlist = py38, flake8 - -[testenv:flake8] -deps = flake8 -; igores 'imported but unused' traceback -commands = flake8 --ignore=F401 +envlist = py38 [testenv] setenv = @@ -12,7 +7,6 @@ setenv = {% if cookiecutter.use_pytest == 'y' -%} deps = -r{toxinidir}/requirements_dev.txt - -r{toxinidir}/requirements.txt ; If you want to make tox run the tests with the same versions, create a ; requirements.txt with the pinned versions and uncomment the following line: ; -r{toxinidir}/requirements.txt From f97b4bc4ff36c3ebb8036beff2359e8724a07bd0 Mon Sep 17 00:00:00 2001 From: elaynelemos Date: Tue, 23 Jun 2020 13:47:27 -0300 Subject: [PATCH 2/2] Fixes conditional pytest --- {{ cookiecutter.repo_name }}/requirements_dev.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/{{ cookiecutter.repo_name }}/requirements_dev.txt b/{{ cookiecutter.repo_name }}/requirements_dev.txt index 0b81634c8..9cc2da440 100644 --- a/{{ cookiecutter.repo_name }}/requirements_dev.txt +++ b/{{ cookiecutter.repo_name }}/requirements_dev.txt @@ -1,5 +1,5 @@ coverage flake8 +{% if cookiecutter.use_pytest == 'y' -%} pytest -pytest-cov -pylint +pytest-cov{%- endif %}