From e3c280155ad75f41276a86ee05f03823a21a0094 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joan=20Vallv=C3=A9=20Navarro?= <jvallve@iri.upc.edu>
Date: Tue, 5 Dec 2023 16:37:06 +0100
Subject: [PATCH] Upload New File

---
 .ci_templates/.yaml_schema_cpp.yml | 78 ++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)
 create mode 100644 .ci_templates/.yaml_schema_cpp.yml

diff --git a/.ci_templates/.yaml_schema_cpp.yml b/.ci_templates/.yaml_schema_cpp.yml
new file mode 100644
index 000000000..fb7056750
--- /dev/null
+++ b/.ci_templates/.yaml_schema_cpp.yml
@@ -0,0 +1,78 @@
+.install_yamlschemacpp_script:
+  - cd ${CI_PROJECT_DIR}
+
+  # create 'ci_deps' folder (if not exists)
+  - mkdir -pv ci_deps
+  - cd ${CI_PROJECT_DIR}/ci_deps
+
+  # clone or pull
+  - if [ -d yaml-schema-cpp ]; then
+  -   echo "directory yaml-schema-cpp exists"
+  -   cd yaml-schema-cpp
+  -   git checkout main
+  -   git pull 
+  - else
+  -   git clone -b main ssh://git@gitlab.iri.upc.edu:2202/labrobotica/algorithms/yaml-schema-cpp.git
+  -   cd yaml-schema-cpp
+  - fi
+
+  # build and install
+  - mkdir -pv build
+  - cd build
+  - cmake -DCMAKE_BUILD_TYPE=release -DBUILD_TESTS=OFF ..
+  - make -j$(nproc)
+  - make install
+  - ldconfig
+
+.generate_yaml_templates_script:
+  - cd ${CI_PROJECT_DIR}
+
+  # create ci_deps if not created yet
+  - mkdir -pv ci_deps
+
+  # configure git
+  - git remote set-url origin "ssh://git@gitlab.iri.upc.edu:2202/${CI_PROJECT_PATH}.git"
+  - git pull origin ${CI_COMMIT_REF_NAME}
+  - git config --global user.email "${CI_EMAIL}"
+  - git config --global user.name "${CI_USERNAME}"
+
+  # create temporary branch
+  - if [ `git rev-parse --verify ci_yamlschemacpp 2>/dev/null` ]; then
+  -   git branch --delete ci_yamlschemacpp
+  - fi
+  - export CI_NEW_BRANCH_YAML=ci_yamlschemacpp
+  - echo creating new temporary branch... $CI_NEW_BRANCH_YAML
+  - git checkout -b $CI_NEW_BRANCH_YAML
+
+  # remove all existing yaml templates
+  - cd ${CI_PROJECT_DIR}
+  - rm -rf yaml_templates
+
+  # go to schema folder
+  - cd ${CI_PROJECT_DIR}/schema
+
+  # list all schema files
+  - find . -iname "*.schema" > schemas.txt
+
+  # generate yaml template for each schema file in yaml_templates folder
+  - while read p; do
+  -   echo "Generating template for schema $p"
+  -   folder=${p%/*}
+  -   folder_length=${#folder}
+  -   tmp=${p%.*}
+  -   name=${tmp:$folder_length+1}
+  -   mkdir -p ${CI_PROJECT_DIR}/yaml_templates/$folder
+  -   yaml_template_generator $name "[${CI_PROJECT_DIR}/schema ${CI_PROJECT_DIR}/ci_deps]" ${CI_PROJECT_DIR}/yaml_templates/$folder/$name.yaml
+  - done <schemas.txt
+
+  # remove list of all schema files
+  - rm schemas.txt
+
+  # push changes (if any)
+  - git add ../yaml_templates
+  - if git commit -a -m "[skip ci] yaml templates added or modified" ; then
+  -   git push origin $CI_NEW_BRANCH_YAML:${CI_COMMIT_REF_NAME}
+  - else
+  -   echo "No changes, nothing to commit!"
+  - fi
+
-- 
GitLab