| vegall | 427cdb2 | 2024-06-13 15:59:43 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | # |
| 15 | |
| garciadeblas | 2f34fb1 | 2025-09-26 10:11:36 +0200 | [diff] [blame^] | 16 | if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then |
| 17 | echo "Usage: $0 <NEW_VERSION> <GIT_USER> [<GIT_PASSWORD>]" |
| 18 | echo " Example: $0 16.0.0 garciadeblas" |
| 19 | echo " Example: $0 15.0.7 vegall" |
| 20 | echo "When <PASSWORD> is provided, it will be used for git https authentication. Otherwise, ssh authentication will be used." |
| vegall | 427cdb2 | 2024-06-13 15:59:43 +0000 | [diff] [blame] | 21 | exit 1 |
| 22 | fi |
| 23 | |
| 24 | NEW_VERSION="$1" |
| garciadeblas | 2f34fb1 | 2025-09-26 10:11:36 +0200 | [diff] [blame^] | 25 | GIT_USER="$2" |
| 26 | GIT_PASSWORD="${3:-}" |
| 27 | |
| garciadeblas | 8d4c249 | 2025-03-12 11:16:36 +0100 | [diff] [blame] | 28 | BRANCH_NAME="v$(echo $NEW_VERSION | grep -oE '[0-9]+\.[0-9]+')" |
| vegall | 427cdb2 | 2024-06-13 15:59:43 +0000 | [diff] [blame] | 29 | |
| garciadeblas | 2f34fb1 | 2025-09-26 10:11:36 +0200 | [diff] [blame^] | 30 | BASE_FOLDER=$(mktemp -d change-chart-version.XXXXXX) |
| 31 | pushd $BASE_FOLDER |
| 32 | |
| 33 | if [ -n "$GIT_PASSWORD" ]; then |
| 34 | REPO_URL="https://${GIT_USER}@osm.etsi.org/gerrit/a/osm/devops" |
| 35 | # Follow recommendation for user auth with git using a script git-creds.sh |
| 36 | cat << "EOF" > "${HOME}/git-creds.sh" |
| 37 | #!/bin/sh |
| 38 | if echo "$1" | grep -q '^Password'; then |
| 39 | echo "${GIT_PASSWORD}" |
| 40 | else |
| 41 | echo "${GIT_USER}" |
| 42 | fi |
| 43 | exit 0 |
| 44 | EOF |
| 45 | chmod +x "${HOME}/git-creds.sh" |
| 46 | else |
| 47 | REPO_URL="ssh://${GIT_USER}@osm.etsi.org:29418/osm/devops" |
| 48 | fi |
| 49 | |
| 50 | echo "Cloning devops repo" |
| 51 | if [ -n "$GIT_PASSWORD" ]; then |
| 52 | echo "Using https authentication" |
| 53 | GIT_USERNAME="${GIT_USER}" GIT_ASKPASS=~/git-creds.sh git clone "${REPO_URL}" |
| 54 | else |
| 55 | echo "Using ssh authentication" |
| 56 | git clone "${REPO_URL}" |
| 57 | fi |
| 58 | cd "devops" |
| 59 | curl https://osm.etsi.org/gerrit/tools/hooks/commit-msg > .git/hooks/commit-msg |
| 60 | chmod +x .git/hooks/commit-msg |
| vegall | 427cdb2 | 2024-06-13 15:59:43 +0000 | [diff] [blame] | 61 | |
| 62 | git checkout $BRANCH_NAME |
| garciadeblas | 8d4c249 | 2025-03-12 11:16:36 +0100 | [diff] [blame] | 63 | sed -i -E "0,/^version: .*/s//version: \"$NEW_VERSION\"/" installers/helm/osm/Chart.yaml |
| vegall | 427cdb2 | 2024-06-13 15:59:43 +0000 | [diff] [blame] | 64 | sed -i -E "0,/^appVersion: .*/s//appVersion: \"$NEW_VERSION\"/" installers/helm/osm/Chart.yaml |
| 65 | |
| 66 | git add installers/helm/osm/Chart.yaml |
| garciadeblas | 8d4c249 | 2025-03-12 11:16:36 +0100 | [diff] [blame] | 67 | git commit -s -m "Update chart version version to $NEW_VERSION" |
| garciadeblas | 2f34fb1 | 2025-09-26 10:11:36 +0200 | [diff] [blame^] | 68 | |
| 69 | echo "Pushing changes to devops repo" |
| 70 | if [ -n "$GIT_PASSWORD" ]; then |
| 71 | echo "Using https authentication" |
| 72 | GIT_USERNAME="${GIT_USER}" GIT_ASKPASS=~/git-creds.sh git push origin $BRANCH_NAME |
| 73 | else |
| 74 | echo "Using ssh authentication" |
| 75 | git push origin $BRANCH_NAME |
| 76 | fi |
| vegall | 427cdb2 | 2024-06-13 15:59:43 +0000 | [diff] [blame] | 77 | |
| 78 | commit=$(git show --summary | grep commit | awk '{print $2}') |
| garciadeblas | 8d4c249 | 2025-03-12 11:16:36 +0100 | [diff] [blame] | 79 | echo "The commit is $commit" |
| garciadeblas | 2f34fb1 | 2025-09-26 10:11:36 +0200 | [diff] [blame^] | 80 | cd .. |
| garciadeblas | 8d4c249 | 2025-03-12 11:16:36 +0100 | [diff] [blame] | 81 | rm -rf devops |
| 82 | |
| garciadeblas | 2f34fb1 | 2025-09-26 10:11:36 +0200 | [diff] [blame^] | 83 | popd |