From b870ce55bc51bcc93bc17c1ef699fadafb724181 Mon Sep 17 00:00:00 2001
From: Yassine Doghri <yassine@doghri.fr>
Date: Thu, 14 Apr 2022 12:09:40 +0000
Subject: [PATCH] ci(gitlabci): filter out docs src languages not declared in
 .i18n-filter file before build

---
 docs/.gitlab-ci.yml         |  2 ++
 docs/scripts/i18n-filter.sh | 29 +++++++++++++++++++++++++++++
 docs/src/.i18n-filter       |  4 ++++
 3 files changed, 35 insertions(+)
 create mode 100755 docs/scripts/i18n-filter.sh
 create mode 100644 docs/src/.i18n-filter

diff --git a/docs/.gitlab-ci.yml b/docs/.gitlab-ci.yml
index 965f468bf9..1b25164acd 100644
--- a/docs/.gitlab-ci.yml
+++ b/docs/.gitlab-ci.yml
@@ -7,6 +7,8 @@ stages:
 .documentation-setup:
   before_script:
     - cd docs
+    - chmod +x ./scripts/i18n-filter.sh
+    - ./scripts/i18n-filter.sh
     - npm ci
 
 cache:
diff --git a/docs/scripts/i18n-filter.sh b/docs/scripts/i18n-filter.sh
new file mode 100755
index 0000000000..51b506e8ca
--- /dev/null
+++ b/docs/scripts/i18n-filter.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+# This script deletes language files not declared in the .i18n-filter file
+
+set -e
+
+# Exit if the directory isn't found
+if [ ! -d $1 ]
+then
+    echo "$1 directory does not exist."
+    exit
+fi
+
+cd $1
+
+# Exit if the .i18n-filter isn't found
+if [[ -f .i18n-filter ]]
+then
+    # delete all languages not present in .i18n-filter
+    for i in *; do
+        if ! grep -qxFe "$i" .i18n-filter; then
+            echo "Deleting: $i"
+
+            rm -rf "$i"
+        fi
+    done
+else
+    echo "$1/.i18n-filter file not found!"
+    exit
+fi
diff --git a/docs/src/.i18n-filter b/docs/src/.i18n-filter
new file mode 100644
index 0000000000..25512c2929
--- /dev/null
+++ b/docs/src/.i18n-filter
@@ -0,0 +1,4 @@
+public
+contributing
+getting-started
+index.md
-- 
GitLab