From b7ec20d9aefac03ead8b422a5811681d79d67cf2 Mon Sep 17 00:00:00 2001
From: Dimitrios Giannopoulos <dimit.giannopoulos@upnet.gr>
Date: Tue, 23 Jan 2024 15:18:31 +0000
Subject: [PATCH] Fix/multi version

---
 .gitlab-ci.yml | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index fedf490d..20f28f1d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,11 +1,31 @@
 pages:
   stage: deploy
   image: python:3.9.18-slim-bullseye
+  variables:
+    PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
+    PAGES_BRANCH: gl-pages
+    HTTPS_REMOTE: https://gitlab-ci-token:${ACCESS_TOKEN}@${CI_SERVER_HOST}/rep/${CI_PROJECT_PATH}.git
+  before_script:
+    - pip install -q mkdocs-material mike
+    - apt-get update -qq && apt-get -qq install -y git > /dev/null
+    - git config --global --replace-all user.name $GITLAB_USER_NAME
+    - git config --global --replace-all user.email $GITLAB_USER_EMAIL
+    - git fetch origin $PAGES_BRANCH && git checkout $PAGES_BRANCH || git checkout -b $PAGES_BRANCH origin/$PAGES_BRANCH || echo "Pages branch not deployed yet."
+    - git checkout $CI_COMMIT_SHA
   script:
-    - pip install mkdocs-material
-    - mkdocs build --site-dir public
+    - |
+      if [ -n "$CI_COMMIT_TAG" ]; then
+        mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH -u $CI_COMMIT_TAG latest
+        mike set-default --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH latest
+      elif [ "$CI_COMMIT_REF_NAME" == "develop" ]; then
+        mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH -u $CI_COMMIT_BRANCH
+      fi
+    - git checkout $PAGES_BRANCH -- public/
   artifacts:
     paths:
-      - public
+      - public/
   rules:
-    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
+    - if: '$CI_COMMIT_TAG'
+    - if: '$CI_COMMIT_REF_NAME == "develop"'
+      when: always
+    - when: never
\ No newline at end of file
-- 
GitLab