Skip to content

Instantly share code, notes, and snippets.

@Tirael
Forked from skushnerchuk/build.yml
Created May 31, 2022 11:21
Show Gist options
  • Save Tirael/ddce04648cee14e1d505664b328054b6 to your computer and use it in GitHub Desktop.
Save Tirael/ddce04648cee14e1d505664b328054b6 to your computer and use it in GitHub Desktop.
replace external submodules in gitlab pipeline
include:
- project: 'devops/ci'
ref: master
file: '/gitlab/scripts.yml'
before_script:
- !reference [.scripts, replace_external_submodules]
replace_external_submodules: |
exists_in_list () {
list=$1
delimiter=$2
value=$3
list_whitespaces=`echo $list | tr "$delimiter" " "`
for x in $list_whitespaces; do
if [ "$x" = "$value" ]; then
return 0
fi
done
return 1
}
if [ ! -f ".gitmodules" ]; then
echo "INFO: .gitmodules not exist";
else
echo "INFO: .gitmodules exist";
external_submodules="benchmark.git,abseil.git,googletest.git,tlx.git,trompeloeil.git"
git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
while read path_key path
do
url_key=$(echo $path_key | sed 's/\.path/.url/')
url=$(git config -f .gitmodules --get "$url_key")
repo="${url##*/}"
repo=${repo%.*}.git
echo $repo
if exists_in_list "$external_submodules" "," $repo ; then
repo="../external_submodules/${repo}"
echo "Add submodule ${repo}"
git submodule add $repo $path
fi
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment