From f20d9fdba4c37a9fedaa0a7bb566e6bcf7385aa1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joan=20Vallv=C3=A9=20Navarro?= <jvallve@iri.upc.edu>
Date: Fri, 3 Mar 2023 13:26:10 +0100
Subject: [PATCH] Upload .license_template_ci

---
 .license_template_ci.yml | 47 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 .license_template_ci.yml

diff --git a/.license_template_ci.yml b/.license_template_ci.yml
new file mode 100644
index 000000000..3d827c739
--- /dev/null
+++ b/.license_template_ci.yml
@@ -0,0 +1,47 @@
+.license_header_script:
+  - cd $CI_PROJECT_DIR
+
+  # create 'ci_deps' folder (if not exists)
+  - mkdir -pv ci_deps
+
+  # configure git
+  - export CI_NEW_BRANCH=ci_processing$RANDOM
+  - echo creating new temporary branch... $CI_NEW_BRANCH
+  - git config --global user.email "${CI_EMAIL}"
+  - git config --global user.name "${CI_USERNAME}"
+  - git checkout -b $CI_NEW_BRANCH # temporary branch
+
+  # download license script
+  - if [ -f /ci_deps/license_manager.sh ]; then
+  -   echo "File license_manager.sh already exists."
+  - else
+  -   echo "Downloading file license_manager.sh..."
+  -   wget -P /ci_deps  https://gitlab.iri.upc.edu/mobile_robotics/wolf_projects/wolf_lib/wolf/-/raw/$WOLF_CORE_BRANCH/wolf_scripts/license_manager.sh
+  - fi
+
+  # license headers
+  - export CURRENT_YEAR=$( date +'%Y' )
+  - echo "current year:" ${CURRENT_YEAR}
+  - if [ -f license_header_${CURRENT_YEAR}.txt ]; then
+      # add license headers to new files
+  -   echo "File license_header_${CURRENT_YEAR}.txt already exists. License headers are assumed to be updated. Adding headers to new files..."
+  -   source /ci_deps/license_manager.sh --add --path=. --config-path=. --exclude=ci_deps
+  - else
+      # remove license headers of all files
+  -   source /ci_deps/license_manager.sh --remove --path=. --config-path=. --exclude=ci_deps
+      # update license header
+  -   export PREV_YEAR=$(( CURRENT_YEAR-1 ))
+  -   echo "Creating new file license_header_${CURRENT_YEAR}.txt..."
+  -   git mv license_header_${PREV_YEAR}.txt license_header_${CURRENT_YEAR}.txt
+  -   sed -i "s/${PREV_YEAR}/${PREV_YEAR},${CURRENT_YEAR}/g" license_header_${CURRENT_YEAR}.txt
+      # add new license headers to all files
+  -   source /ci_deps/license_manager.sh --add --path=. --config-path=. --exclude=ci_deps
+  - fi
+
+  # push changes (if any)
+  - if git commit -a -m "[skip ci] license headers added or modified" ; then
+  -   git remote set-url --push origin "ssh://git@gitlab.iri.upc.edu:2202/${CI_PROJECT_PATH}.git"
+  -   git push origin $CI_NEW_BRANCH:${CI_COMMIT_REF_NAME}
+  - else
+  -   echo "No changes, nothing to commit!"
+  - fi
\ No newline at end of file
-- 
GitLab