while getopts s: flag
do
    case "${flag}" in
        s) SCHEME=${OPTARG};;
    esac
done

submodule_branch_name=$(grep branch .gitmodules | sed 's/\tbranch = //')
echo "Submodule branch name: $submodule_branch_name"

if [ "$CI_PIPELINE_SOURCE" == "pipeline" ] && [ "$UPSTREAM_BRANCH" != "" ]; then
    sed -i "" "s/branch = [^\n]*/branch = $UPSTREAM_BRANCH/" .gitmodules
    echo "Changed branch name of submodules to $UPSTREAM_BRANCH"
fi

echo "build SCHEME: ${SCHEME}";
echo "prepare dependencies"
xcodebuild clean -workspace RutubeTv.xcworkspace -scheme "${SCHEME}" -list
xcodebuild -resolvePackageDependencies
pod install --repo-update
echo "end prepare dependencies"

