blob: 30fc689e0b4c77b908410439c555e15fe93279cc [file] [log] [blame]
garciadeblas26ccfbe2025-08-01 18:43:58 +02001#!/bin/bash
2#######################################################################################
3# Copyright ETSI Contributors and Others.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14# implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#######################################################################################
18
garciadeblas77351e52025-10-01 08:50:08 +020019if [ $# -lt 2 ] || [ $# -gt 4 ]; then
20 echo "Usage $0 <BRANCH> <GIT_USER> [<DO_PUSH>] [<GIT_PASSWORD>]"
21 echo "Example: $0 v18.0 garciadeblas false"
22 echo "When <GIT_PASSWORD> is provided, it will be used for git https authentication. Otherwise, ssh authentication will be used."
garciadeblas26ccfbe2025-08-01 18:43:58 +020023 exit 1
24fi
25
26set -e -o pipefail
27
garciadeblas77351e52025-10-01 08:50:08 +020028BRANCH_NAME="$1"
29GIT_USER="$2"
30DO_PUSH="${3:-"true"}"
31GIT_PASSWORD="${4:-}"
garciadeblas26ccfbe2025-08-01 18:43:58 +020032
garciadeblas77351e52025-10-01 08:50:08 +020033declare -A branch_module_map=(
34 ["v14.0"]="common IM LCM MON N2VC NBI NG-SA osmclient RO PLA POL tests"
35 ["v15.0"]="common IM LCM MON N2VC NBI NG-SA osmclient RO PLA POL tests"
36 ["v16.0"]="common IM LCM MON N2VC NBI NG-SA osmclient RO PLA POL tests"
37 ["v17.0"]="common IM LCM MON N2VC NBI NG-SA osmclient RO PLA POL tests"
38 ["v18.0"]="common IM LCM MON NBI NG-SA osmclient RO tests"
39 ["v19.0"]="common IM LCM MON NBI NG-SA osmclient RO tests"
40 ["v20.0"]="common IM LCM MON NBI NG-SA osmclient RO tests"
41 ["v21.0"]="common IM LCM MON NBI NG-SA osmclient RO tests"
42 ["v22.0"]="common IM LCM MON NBI NG-SA osmclient RO tests"
43 ["v23.0"]="common IM LCM MON NBI NG-SA osmclient RO tests"
44 ["master"]="common IM LCM MON NBI NG-SA osmclient RO tests"
45)
46MODULE_LIST="${branch_module_map[$BRANCH_NAME]}"
47if [ -z "$MODULE_LIST" ]; then
48 echo "Unknown branch name: $BRANCH_NAME"
garciadeblas26ccfbe2025-08-01 18:43:58 +020049 exit 1
50fi
51
52# Create a temporary folder
garciadeblas77351e52025-10-01 08:50:08 +020053BASE_FOLDER=$(mktemp -d --tmpdir update-pip-dependencies.XXXXXX)
54pushd ${BASE_FOLDER}
55echo "Using temporary directory: ${BASE_FOLDER}"
56
57if [ -n "$GIT_PASSWORD" ]; then
58 REPO_BASE_URL="https://${GIT_USER}@osm.etsi.org/gerrit/a/osm"
59 # Follow recommendation for user auth with git using a script git-creds.sh
60 cat << "EOF" > "${HOME}/git-creds.sh"
61#!/bin/sh
62if echo "$1" | grep -q '^Password'; then
63 echo "${GIT_PASSWORD}"
64else
65 echo "${GIT_USER}"
66fi
67exit 0
68EOF
69 chmod +x "${HOME}/git-creds.sh"
70else
71 REPO_BASE_URL="ssh://${GIT_USER}@osm.etsi.org:29418/osm"
72fi
garciadeblas26ccfbe2025-08-01 18:43:58 +020073
74echo "Updating pip dependencies"
garciadeblas77351e52025-10-01 08:50:08 +020075for i in ${MODULE_LIST}; do
garciadeblas26ccfbe2025-08-01 18:43:58 +020076 echo "Updating pip dependencies for $i"
garciadeblas77351e52025-10-01 08:50:08 +020077 REPO_DIR="${BASE_FOLDER}/$i"
78 REPO_URL="${REPO_BASE_URL}/${i}"
79 echo "Cloning $i repo"
80 if [ -n "$GIT_PASSWORD" ]; then
81 echo "Using https authentication"
82 GIT_USERNAME="${GIT_USER}" GIT_ASKPASS=~/git-creds.sh git clone "${REPO_URL}"
83 else
84 echo "Using ssh authentication"
85 git clone "${REPO_URL}"
garciadeblas26ccfbe2025-08-01 18:43:58 +020086 fi
87 pushd "$REPO_DIR"
garciadeblas77351e52025-10-01 08:50:08 +020088 git checkout $BRANCH_NAME
garciadeblas26ccfbe2025-08-01 18:43:58 +020089 git pull --rebase
90 tox -e pip-compile
91 git add -u
garciadeblas77351e52025-10-01 08:50:08 +020092 # Only commit if there are staged changes
93 if ! git diff --cached --quiet; then
94 git show HEAD --stat
95 git diff HEAD^ > "${BASE_FOLDER}/$i.diff"
96 echo "===================" | tee -a "${BASE_FOLDER}/all.diff"
97 echo "Showing diff for $i" | tee -a "${BASE_FOLDER}/all.diff"
98 echo "===================" | tee -a "${BASE_FOLDER}/all.diff"
99 git diff HEAD^ | tee -a "${BASE_FOLDER}/all.diff"
100 if [ "$DO_PUSH" == "true" ]; then
101 echo "Pushing changes for $i"
102 if [ -n "$GIT_PASSWORD" ]; then
103 echo "Using https authentication"
104 GIT_USERNAME="${GIT_USER}" GIT_ASKPASS=~/git-creds.sh git push origin $BRANCH_NAME
105 else
106 echo "Using ssh authentication"
107 git push origin $BRANCH_NAME
108 fi
109 fi
110 else
111 echo "No changes to commit for $i"
garciadeblas26ccfbe2025-08-01 18:43:58 +0200112 fi
113 popd
114done
garciadeblas77351e52025-10-01 08:50:08 +0200115
116popd
117
118echo "All diffs saved in ${BASE_FOLDER}/all.diff"
garciadeblas26ccfbe2025-08-01 18:43:58 +0200119
120exit 0