From 6647f4c7447129767509f310404810fda60478e4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Benjamin=20H=C3=A4ttasch?=
 <benjamin.haettasch@fachschaft.informatik.tu-darmstadt.de>
Date: Fri, 9 Jun 2023 21:50:57 +0200
Subject: [PATCH] Add linting to CI pipeline

---
 .gitlab-ci.yml | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 741d4f59..398dc6d4 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -20,6 +20,10 @@ before_script:
   - apt-get -qq install -y python3-virtualenv python3 python3-dev python3-pip gettext default-mysql-client default-libmysqlclient-dev
   - export DJANGO_SETTINGS_MODULE=AKPlanning.settings_ci
   - ./Utils/setup.sh --prod
+  - mkdir -p public/badges public/lint
+  - echo undefined > public/badges/$CI_JOB_NAME.score
+  - source venv/bin/activate
+  - pip install pylint-gitlab
   - mysql --version
 
 check:
@@ -48,3 +52,32 @@ test:
         coverage_format: cobertura
         path: coverage.xml
       junit: unit.xml
+
+lint:
+  stage: test
+  script:
+    - pylint --exit-zero --output-format=text $(find -type f -name "*.py" ! -path "**/venv/**") | tee /tmp/pylint.txt
+    - sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' /tmp/pylint.txt > public/badges/$CI_JOB_NAME.score
+    - pylint --exit-zero --output-format=pylint_gitlab.GitlabCodeClimateReporter $(find -type f -name "*.py" ! -path "**/venv/**") > codeclimate.json
+    - pylint --exit-zero --output-format=pylint_gitlab.GitlabPagesHtmlReporter $(find -type f -name "*.py" ! -path "**/venv/**") > public/lint/index.html
+  after_script:
+   - |
+      echo "Linting score: $(cat public/badges/$CI_JOB_NAME.score)"
+  artifacts:
+    paths:
+      - public
+    reports:
+      codequality: codeclimate.json
+    when: always
+
+pages:
+  stage: deploy
+  image: alpine:latest
+  script:
+    - echo
+  artifacts:
+    paths:
+      - public
+  only:
+    refs:
+      - main
-- 
GitLab