From 7bae5fda369ecda07167a861d3da7e01b9e172f4 Mon Sep 17 00:00:00 2001
From: Martin Weise <martin.weise@tuwien.ac.at>
Date: Mon, 25 Mar 2024 10:46:03 +0100
Subject: [PATCH] Build all in one script

---
 Makefile                                | 13 ++-----------
 .docs/build-website.sh => build-docs.sh | 22 ++++++++++++++++++++--
 lib/python/build-website.sh             |  8 --------
 3 files changed, 22 insertions(+), 21 deletions(-)
 rename .docs/build-website.sh => build-docs.sh (72%)
 delete mode 100755 lib/python/build-website.sh

diff --git a/Makefile b/Makefile
index e74bc4bd19..8ad6b93fe3 100644
--- a/Makefile
+++ b/Makefile
@@ -231,14 +231,5 @@ teardown:
 build-api:
 	bash .docs/.swagger/swagger-generate.sh
 
-build-mkdocs:
-	bash .docs/build-website.sh
-
-build-sphinx:
-	pwd
-	ls -la .
-	ls la -la lib
-	ls la -la lib/python
-	bash ./lib/python/build-website.sh
-
-docs: build-mkdocs build-sphinx
+docs:
+	bash ./build-docs.sh
diff --git a/.docs/build-website.sh b/build-docs.sh
similarity index 72%
rename from .docs/build-website.sh
rename to build-docs.sh
index 6e2fb29e79..ffc17120b0 100644
--- a/.docs/build-website.sh
+++ b/build-docs.sh
@@ -4,8 +4,25 @@ OVERRIDES_MAIN_HTML=""
 SCRIPTS_EXTRA_JS=""
 
 function clean_cache {
-  echo "Removing cache from directory ./site"
-  rm -rf ./site
+  echo "Removing cache from directory ./site ./lib/python/docs/build"
+  rm -rf ./site ./lib/python/docs/build
+}
+
+function generate_sphinx {
+  BRANCH="release-$1"
+  echo "==================================================="
+  echo "Building LIB for version $1 on branch $BRANCH"
+  echo "==================================================="
+  git reset --hard && git checkout "$BRANCH"
+  pip install -r ./requirements.txt > /dev/null
+  mkdir -p ./final
+  if [ "$1" = "latest" ]; then
+    sed -i -e "s/__APPVERSION__/${APP_VERSION}/g" ./lib/python/setup.py ./lib/python/pyproject.toml ./lib/python/docs/conf.py ./lib/python/docs/index.rst ./lib/python/docs/index.rst
+  fi
+  sphinx-apidoc -o ./lib/python/docs/source ./lib/python/dbrepo
+  sphinx-build -M html ./lib/python/docs/ ./lib/python/docs/build/
+  cp -r ./lib/python/docs/build/html "./final/$1/sphinx"
+  clean_cache
 }
 
 function generate_docs {
@@ -66,6 +83,7 @@ git fetch
 
 generate_api "latest"
 generate_docs "latest"
+generate_sphinx "latest"
 
 # versions
 for i in "${!versions[@]}"; do
diff --git a/lib/python/build-website.sh b/lib/python/build-website.sh
deleted file mode 100755
index 1178d90892..0000000000
--- a/lib/python/build-website.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-python3 -m venv ./lib/python/venv
-source ./lib/python/venv/bin/activate
-PIPENV_PIPFILE=./lib/python/Pipfile pipenv install --dev
-sed -i -e "s/__APPVERSION__/${APP_VERSION}/g" ./lib/python/pyproject.toml ./lib/python/setup.py ./lib/python/README.md ./lib/python/docs/conf.py ./lib/python/docs/index.rst
-sphinx-apidoc -o ./lib/python/docs/source ./lib/python/dbrepo
-sphinx-build -M html ./lib/python/docs/ ./lib/python/docs/build/
-cp -r ./lib/python/docs/build/html ./site/sphinx
\ No newline at end of file
-- 
GitLab