From 27e80b06aa3b14b53f913818a85cf7b94e56ec38 Mon Sep 17 00:00:00 2001 From: Freezed <2160318-free_zed@users.noreply.gitlab.com> Date: Tue, 25 Oct 2022 00:28:11 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Add=20CI=20for=20GitLab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 23 +++++++++++++++++++++++ Makefile | 5 ++++- main.py | 4 +++- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..86de785 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,23 @@ +variables: + PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" + +cache: + paths: + - .cache/pip + - /var/venv/ + +lint: + image: python:3.8-slim + stage: test + except: + - /^wip-.*$/ + - /^old-.*$/ + - pitchme + script: + - python -V + - apt-get update -qq && apt-get -qq -y install make python3-venv + - python3 -m venv /var/venv/ + - source /var/venv/bin/activate + - pip install -r requirements-dev.txt + - make --no-print-directory --quiet lint + - make --no-print-directory --quiet test diff --git a/Makefile b/Makefile index a051a75..88b68fa 100644 --- a/Makefile +++ b/Makefile @@ -26,8 +26,11 @@ lint: # Lint code open_all: # Open all projects files ${EDITOR} ${VBIN}/activate - ${EDITOR} main.py Makefile pyproject.toml README.md requirements-dev.txt requirements.txt + ${EDITOR} .gitlab-ci.yml main.py Makefile pyproject.toml README.md requirements-dev.txt requirements.txt ${EDITOR} .git/hooks/p*-commit pre_commit: # Run the pre-commit hook bash .git/hooks/pre-commit + +test: # Run the code tests + ./main.py -h 1> /dev/null && echo ✅ || echo 🚨 diff --git a/main.py b/main.py index 1e51466..0b7b426 100755 --- a/main.py +++ b/main.py @@ -12,6 +12,7 @@ This file is part of [``]() """ import argparse +from os import environ import sys from pprint import pprint as pp @@ -123,5 +124,6 @@ def main(): if __name__ == "__main__": import doctest - doctest.testmod() + # When running on GitLab CI, a doctest error raised an error + doctest.testmod(raise_on_error=environ.get("CI", False)) sys.exit(main())