| garciadeblas | 26ccfbe | 2025-08-01 18:43:58 +0200 | [diff] [blame] | 1 | #!/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 | |
| garciadeblas | 77351e5 | 2025-10-01 08:50:08 +0200 | [diff] [blame] | 19 | if [ $# -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." |
| garciadeblas | 26ccfbe | 2025-08-01 18:43:58 +0200 | [diff] [blame] | 23 | exit 1 |
| 24 | fi |
| 25 | |
| 26 | set -e -o pipefail |
| 27 | |
| garciadeblas | 77351e5 | 2025-10-01 08:50:08 +0200 | [diff] [blame] | 28 | BRANCH_NAME="$1" |
| 29 | GIT_USER="$2" |
| 30 | DO_PUSH="${3:-"true"}" |
| 31 | GIT_PASSWORD="${4:-}" |
| garciadeblas | 26ccfbe | 2025-08-01 18:43:58 +0200 | [diff] [blame] | 32 | |
| garciadeblas | 77351e5 | 2025-10-01 08:50:08 +0200 | [diff] [blame] | 33 | declare -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 | ) |
| 46 | MODULE_LIST="${branch_module_map[$BRANCH_NAME]}" |
| 47 | if [ -z "$MODULE_LIST" ]; then |
| 48 | echo "Unknown branch name: $BRANCH_NAME" |
| garciadeblas | 26ccfbe | 2025-08-01 18:43:58 +0200 | [diff] [blame] | 49 | exit 1 |
| 50 | fi |
| 51 | |
| 52 | # Create a temporary folder |
| garciadeblas | 77351e5 | 2025-10-01 08:50:08 +0200 | [diff] [blame] | 53 | BASE_FOLDER=$(mktemp -d --tmpdir update-pip-dependencies.XXXXXX) |
| 54 | pushd ${BASE_FOLDER} |
| 55 | echo "Using temporary directory: ${BASE_FOLDER}" |
| 56 | |
| 57 | if [ -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 |
| 62 | if echo "$1" | grep -q '^Password'; then |
| 63 | echo "${GIT_PASSWORD}" |
| 64 | else |
| 65 | echo "${GIT_USER}" |
| 66 | fi |
| 67 | exit 0 |
| 68 | EOF |
| 69 | chmod +x "${HOME}/git-creds.sh" |
| 70 | else |
| 71 | REPO_BASE_URL="ssh://${GIT_USER}@osm.etsi.org:29418/osm" |
| 72 | fi |
| garciadeblas | 26ccfbe | 2025-08-01 18:43:58 +0200 | [diff] [blame] | 73 | |
| 74 | echo "Updating pip dependencies" |
| garciadeblas | 77351e5 | 2025-10-01 08:50:08 +0200 | [diff] [blame] | 75 | for i in ${MODULE_LIST}; do |
| garciadeblas | 26ccfbe | 2025-08-01 18:43:58 +0200 | [diff] [blame] | 76 | echo "Updating pip dependencies for $i" |
| garciadeblas | 77351e5 | 2025-10-01 08:50:08 +0200 | [diff] [blame] | 77 | 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}" |
| garciadeblas | 26ccfbe | 2025-08-01 18:43:58 +0200 | [diff] [blame] | 86 | fi |
| 87 | pushd "$REPO_DIR" |
| garciadeblas | 77351e5 | 2025-10-01 08:50:08 +0200 | [diff] [blame] | 88 | git checkout $BRANCH_NAME |
| garciadeblas | 26ccfbe | 2025-08-01 18:43:58 +0200 | [diff] [blame] | 89 | git pull --rebase |
| 90 | tox -e pip-compile |
| 91 | git add -u |
| garciadeblas | 77351e5 | 2025-10-01 08:50:08 +0200 | [diff] [blame] | 92 | # 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" |
| garciadeblas | 26ccfbe | 2025-08-01 18:43:58 +0200 | [diff] [blame] | 112 | fi |
| 113 | popd |
| 114 | done |
| garciadeblas | 77351e5 | 2025-10-01 08:50:08 +0200 | [diff] [blame] | 115 | |
| 116 | popd |
| 117 | |
| 118 | echo "All diffs saved in ${BASE_FOLDER}/all.diff" |
| garciadeblas | 26ccfbe | 2025-08-01 18:43:58 +0200 | [diff] [blame] | 119 | |
| 120 | exit 0 |