From 72fdbe784d22579e0b3669f4b7588171a21335fc Mon Sep 17 00:00:00 2001
From: Raphael Defosseux <raphael.defosseux@eurecom.fr>
Date: Wed, 23 Sep 2020 14:54:11 +0200
Subject: [PATCH] CI: adding cn5g components as submodules

Signed-off-by: Raphael Defosseux <raphael.defosseux@eurecom.fr>
---
 .gitmodules                  |   9 +++
 component/oai-amf            |   1 +
 component/oai-smf            |   1 +
 component/oai-upf-equivalent |   1 +
 scripts/syncComponents.sh    | 127 +++++++++++++++++++++++++++++++++++
 5 files changed, 139 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 component/oai-amf
 create mode 160000 component/oai-smf
 create mode 160000 component/oai-upf-equivalent
 create mode 100755 scripts/syncComponents.sh

diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 00000000..ca905887
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,9 @@
+[submodule "component/oai-amf"]
+	path = component/oai-amf
+	url = https://gitlab.eurecom.fr/oai/cn5g/oai-cn5g-amf.git
+[submodule "component/oai-smf"]
+	path = component/oai-smf
+	url = https://gitlab.eurecom.fr/oai/cn5g/oai-cn5g-smf.git
+[submodule "component/oai-upf-equivalent"]
+	path = component/oai-upf-equivalent
+	url = https://github.com/OPENAIRINTERFACE/openair-spgwu-tiny.git
diff --git a/component/oai-amf b/component/oai-amf
new file mode 160000
index 00000000..8341c820
--- /dev/null
+++ b/component/oai-amf
@@ -0,0 +1 @@
+Subproject commit 8341c82073923601091f59803fe6c066cd8a68d8
diff --git a/component/oai-smf b/component/oai-smf
new file mode 160000
index 00000000..e43b4429
--- /dev/null
+++ b/component/oai-smf
@@ -0,0 +1 @@
+Subproject commit e43b4429ce0eb8e754dd2bfbaa2c620cfa36ac49
diff --git a/component/oai-upf-equivalent b/component/oai-upf-equivalent
new file mode 160000
index 00000000..e812920b
--- /dev/null
+++ b/component/oai-upf-equivalent
@@ -0,0 +1 @@
+Subproject commit e812920bc48dcedb0e8f3811f3dbbe2ebebeb899
diff --git a/scripts/syncComponents.sh b/scripts/syncComponents.sh
new file mode 100755
index 00000000..8b004583
--- /dev/null
+++ b/scripts/syncComponents.sh
@@ -0,0 +1,127 @@
+#!/bin/bash
+#/*
+# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+# * contributor license agreements.  See the NOTICE file distributed with
+# * this work for additional information regarding copyright ownership.
+# * The OpenAirInterface Software Alliance licenses this file to You under
+# * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+# * except in compliance with the License.
+# * You may obtain a copy of the License at
+# *
+# *      http://www.openairinterface.org/?page_id=698
+# *
+# * Unless required by applicable law or agreed to in writing, software
+# * distributed under the License is distributed on an "AS IS" BASIS,
+# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# * See the License for the specific language governing permissions and
+# * limitations under the License.
+# *-------------------------------------------------------------------------------
+# * For more information about the OpenAirInterface (OAI) Software Alliance:
+# *      contact@openairinterface.org
+# */
+
+function usage {
+    echo "Openair-CN components synchronization"
+    echo "   Original Author: Raphael Defosseux"
+    echo ""
+    echo "   Requirement: git shall be installed"
+    echo ""
+    echo "   By default (no options) all components will be synchronized to"
+    echo "     the 'develop' branch."
+    echo "   Each component can be synchronized a dedicated branch."
+    echo ""
+    echo "Usage:"
+    echo "------"
+    echo "    syncComponents.sh [OPTIONS]"
+    echo ""
+    echo "Options:"
+    echo "--------"
+    echo "    --amf-branch ####"
+    echo "    Specify the source branch for the OAI-AMF component"
+    echo ""
+    echo "    --smf-branch ####"
+    echo "    Specify the source branch for the OAI-SMF component"
+    echo ""
+    echo "    --spgwu-tiny-branch ####"
+    echo "    Specify the source branch for the OAI-SPGW-U-TINY component"
+    echo ""
+    echo "    --help OR -h"
+    echo "    Print this help message."
+    echo ""
+}
+
+AMF_BRANCH='develop'
+SMF_BRANCH='develop'
+SPGWU_BRANCH='develop'
+
+doDefault=1
+
+while [[ $# -gt 0 ]]
+do
+key="$1"
+
+case $key in
+    -h|--help)
+    shift
+    usage
+    exit 0
+    ;;
+    --amf-branch)
+    AMF_BRANCH="$2"
+    doDefault=0
+    shift
+    shift
+    ;;
+    --smf-branch)
+    SMF_BRANCH="$2"
+    doDefault=0
+    shift
+    shift
+    ;;
+    --spgwc-branch)
+    SPGWC_BRANCH="$2"
+    doDefault=0
+    shift
+    shift
+    ;;
+    --spgwu-tiny-branch)
+    SPGWU_BRANCH="$2"
+    doDefault=0
+    shift
+    shift
+    ;;
+    *)
+    echo "Syntax Error: unknown option: $key"
+    echo ""
+    usage
+    exit 1
+esac
+
+done
+
+echo "---------------------------------------------------------"
+echo "OAI-AMF    component branch : ${AMF_BRANCH}"
+echo "OAI-SMF    component branch : ${SMF_BRANCH}"
+echo "OAI-SPGW-U component branch : ${SPGWU_BRANCH}"
+echo "---------------------------------------------------------"
+
+# First do a clean-up
+git submodule deinit --all --force
+
+git submodule init
+git submodule update
+
+if [ $doDefault -eq 1 ]
+then
+    git submodule foreach 'git fetch --prune && git checkout develop && git pull origin develop'
+else
+    pushd component/oai-amf
+    git fetch --prune && git checkout $AMF_BRANCH && git pull origin $AMF_BRANCH
+    popd
+    pushd component/oai-smf
+    git fetch --prune && git checkout $SMF_BRANCH && git pull origin $SMF_BRANCH
+    popd
+    pushd component/oai-upf-equivalent
+    git fetch --prune && git checkout $SPGWU_BRANCH && git pull origin $SPGWU_BRANCH
+    popd
+fi
-- 
GitLab