From 55876b86b76d132b26ed656ca6eed0b3e1127272 Mon Sep 17 00:00:00 2001
From: Michele Nottoli <michele.nottoli@mathematik.uni-stuttgart.de>
Date: Tue, 24 Oct 2023 11:36:07 +0200
Subject: [PATCH] Added CI

---
 .gitlab-ci.yml | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++
 README.md      |  7 +++++++
 setup.py       |  2 +-
 3 files changed, 64 insertions(+), 1 deletion(-)
 create mode 100644 .gitlab-ci.yml
 create mode 100644 README.md

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..c4985f5
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,56 @@
+stages:
+  - test
+  - lint
+  - coverage
+
+variables:
+  PYLINT_CMD: >
+    (pylint grext --exit-zero > pylint.out) || true
+  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
+
+default:
+  image: python:latest
+  cache:
+    paths:
+      - .cache/pip
+  before_script:
+    - python -V
+    - pip install virtualenv
+    - virtualenv venv
+    - source venv/bin/activate
+    - pip install .
+    - pip install pylint anybadge coverage
+  tags:
+    - Maths
+
+test:
+  stage: test
+  script:
+    - coverage run -m pytest
+  artifacts:
+    paths:
+      - .coverage
+
+lint:
+  stage: lint
+  script:
+    - mkdir -p ./public
+    - pylint grext --exit-zero | tee pylint.out
+    - score=$(sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' pylint.out)
+    - echo "Pylint score was $score"
+    - anybadge --value=$score --file=public/pylint_badge.svg pylint
+    - echo $score | awk '{if( $1 > 8.0 ) exit 0; exit 1;}'
+  artifacts:
+    paths:
+      - public/pylint_badge.svg
+
+coverage:
+  stage: coverage
+  script:
+    - mkdir -p ./public
+    - coverage report | tee report.out
+    - covperc=`cat report.out | grep 'TOTAL' | sed -e 's/%//g' | awk '{print $4}'`
+    - anybadge --value=$covperc --file=public/coverage.svg coverage
+  artifacts:
+    paths:
+      - public/coverage.svg
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..bd9bab5
--- /dev/null
+++ b/README.md
@@ -0,0 +1,7 @@
+![CI_Badge](https://gitlab.mathematik.uni-stuttgart.de/nottolme/grext/badges/main/pipeline.svg)
+![Pylint Badge](https://gitlab.mathematik.uni-stuttgart.de/nottolme/grext/-/jobs/artifacts/main/raw/public/pylint_badge.svg?job=lint)
+![Coverage Badge](https://gitlab.mathematik.uni-stuttgart.de/nottolme/grext/-/jobs/artifacts/main/raw/public/coverage.svg?job=coverage.svg)
+
+# grext: Grassmann Extrapolation Library
+
+
diff --git a/setup.py b/setup.py
index 9b63992..bb17fa0 100644
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,7 @@ setup(
     name="grext",
     version="0.2.0",
     packages=find_packages(),
-    install_requires=["numpy", "scipy"],
+    install_requires=["numpy", "scipy", "pytest"],
     author="Michele Nottoli",
     description="Tools for generating new guesses for SCF calculations.",
     classifiers=[
-- 
GitLab