From a209e00aa6daafed8ab565951ab88ff79120eeca Mon Sep 17 00:00:00 2001
From: Miguel Angel Reina Ortega <miguelangel.reinaortega@etsi.org>
Date: Wed, 10 Apr 2024 17:32:18 +0200
Subject: [PATCH] Moving baselines to public/baselines

---
 generateChangemarks/.gitlab-ci.yml |  4 ++--
 publish_on_pages.sh                | 29 ++++++++++++++++++++++-------
 updateIndex.py                     | 16 ++++++----------
 3 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/generateChangemarks/.gitlab-ci.yml b/generateChangemarks/.gitlab-ci.yml
index b5cd556..d632f64 100644
--- a/generateChangemarks/.gitlab-ci.yml
+++ b/generateChangemarks/.gitlab-ci.yml
@@ -91,10 +91,10 @@ pages:
         TAG_NAME: "upgrade"
   before_script:
     - |
-     curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/publish_on_pages%2Esh/raw?ref=master" >> publish_on_pages.sh
+     curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/publish_on_pages%2Esh/raw?ref=addDiffCR" >> publish_on_pages.sh
     - chmod +x publish_on_pages.sh
     - |
-     curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/updateIndex%2Epy/raw?ref=master" >> updateIndex.py
+     curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/updateIndex%2Epy/raw?ref=addDiffCR" >> updateIndex.py
     - |
      curl "${CI_API_V4_URL}/projects/$TOOLS_SCRIPTS_PROJECT_ID/repository/files/index%2Ehtml/raw?ref=master" >> index.html
     - |
diff --git a/publish_on_pages.sh b/publish_on_pages.sh
index 751a21b..11755a5 100644
--- a/publish_on_pages.sh
+++ b/publish_on_pages.sh
@@ -23,26 +23,41 @@ fi
 set -e
 
 echo "------ Get the previous GitLab Pages content --------"
+# Move all folders except the "baselines" folder if baselines folder exists
+if [ -d "public/baselines" ]; then
+    echo "Baselines already moved to baselines/";
+else
+    mkdir -p "public/baselines"
+    for folder in public/*; do
+        if [ -d "$folder" ] && [ "$(basename "$folder")" != "baselines" ]; then
+            mv "$folder" "public/baselines/"
+            echo "Moved $(basename "$folder") to public/baselines"
+        fi
+    done
+    # Move index.html with new location
+    mv "public/index.html" "public/baselines/"
+
+fi
 
 echo "------ Add/update content --------"
 if [ $4 == 'upgrade' ]; then
     echo 'Upgrading index.html...'
     docker run --rm -v $(pwd):/tmp -w /tmp "$DOCKER_IMAGE" python3 $1 -u "$7_$4" "$4/$7_$4.docx" "$5"
 elif [ $6 == 'true' ]; then
-    echo 'Removing all web pages content...'
-	rm -r public/*;
-	mkdir -p "public/$4"
+    echo 'Removing all baselines ...'
+	rm -r public/baselines/*;
+	mkdir -p "public/baselines/$4"
     ls public/
-	cp -r -f "$7_$4.docx" public/$4
+	cp -r -f "$7_$4.docx" public/baselines/$4
     docker run --rm -v $(pwd):/tmp -w /tmp "$DOCKER_IMAGE" python3 $1 "$7_$4" "$4/$7_$4.docx" "$5"
 elif [ $6 == 'false' ]; then
-	mkdir -p "public/$4"
+	mkdir -p "public/baselines/$4"
     ls public/
-	cp -r -f "$7_$4.docx" public/$4
+	cp -r -f "$7_$4.docx" public/baselines/$4
     docker run --rm -v $(pwd):/tmp -w /tmp "$DOCKER_IMAGE" python3 $1 "$7_$4" "$4/$7_$4.docx" "$5"
 else
     echo 'Removing entry for ' $6
-    rm -r -f public/$6
+    rm -r -f public/baselines/$6
     docker run --rm -v $(pwd):/tmp -w /tmp "$DOCKER_IMAGE" python3 $1 -re "$7_$4" "$4/$7_$4.docx" "$5"
 fi
 
diff --git a/updateIndex.py b/updateIndex.py
index 74c513a..a03521c 100644
--- a/updateIndex.py
+++ b/updateIndex.py
@@ -12,12 +12,12 @@ import argparse, os
 
 def upgradeIndex(args: argparse.Namespace) -> None:
     # Check if index.htm exists
-    if not os.path.exists('public/index.html'):
+    if not os.path.exists('public/baselines/index.html'):
         print("'index.html' does not exist yet, Upgrade is not needed")
         exit()
     else:
         # Read the source HTML file
-        with open('public/index.html', 'r', encoding='utf-8') as source_file:
+        with open('public/baselines/index.html', 'r', encoding='utf-8') as source_file:
             source_html = source_file.read()
 
         # Read the destination HTML file
@@ -46,26 +46,22 @@ def upgradeIndex(args: argparse.Namespace) -> None:
             exit(1)
 
         # Save the updated destination HTML
-        with open('public/index.html', 'w', encoding='utf-8') as dest_updated_file:
+        with open('public/baselines/index.html', 'w', encoding='utf-8') as dest_updated_file:
             dest_updated_file.write(str(dest_soup))
 
-
-        # Read index HTML
-        with open('public/index.html', 'r', encoding='utf-8') as file:
-            html_content = file.read()
         print("Index.html upgraded")
 
 
 def updateIndex(args:argparse.Namespace) -> None:
     
     # Check if index.htm exists
-    if not os.path.exists('public/index.html'):
+    if not os.path.exists('public/baselines/index.html'):
         print("'index.html' does not exist yet, using template")
         with open(args.indexTemplate, 'r', encoding='utf-8') as file:
             html_content = file.read()
     else:
         # Read index HTML
-        with open('public/index.html', 'r', encoding='utf-8') as file:
+        with open('public/baselines/index.html', 'r', encoding='utf-8') as file:
             html_content = file.read()
 
     # Analyze index content with BeautifulSoup
@@ -97,7 +93,7 @@ def updateIndex(args:argparse.Namespace) -> None:
             document_list.append(li)
 
     # Save the updated index.html file
-    with open('public/index.html', 'w', encoding='utf-8') as file:
+    with open('public/baselines/index.html', 'w', encoding='utf-8') as file:
         file.write(str(soup))
 
     print("Index.html updated")
-- 
GitLab