diff --git a/.ci_templates/.clang_format.yml b/.ci_templates/.clang_format.yml new file mode 100644 index 0000000000000000000000000000000000000000..dc263197d73bc5bf68967dfd390ae2933bde2a31 --- /dev/null +++ b/.ci_templates/.clang_format.yml @@ -0,0 +1,29 @@ +.clang_format_script: + + - apt install -y clang-format-12 # available in ubuntu 20.04 or newer + - cd $CI_PROJECT_DIR + + # 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_clangformat 2>/dev/null` ]; then + - git branch --delete ci_clangformat + - fi + - export CI_NEW_BRANCH_CLANG=ci_clangformat + - echo creating new temporary branch... $CI_NEW_BRANCH_CLANG + - git checkout -b $CI_NEW_BRANCH_CLANG + + # apply clang format to all code files + - cd ${CI_PROJECT_DIR} + - find . -iname *.h -o -iname *.cpp -o -iname *.hpp | xargs clang-format-12 --style=file -i + + # push changes (if any) + - if git commit -a -m "[skip ci] applied clang format" ; then + - git push origin $CI_NEW_BRANCH_CLANG:${CI_COMMIT_REF_NAME} + - else + - echo "No changes, nothing to commit!" + - fi \ No newline at end of file