blob: 78ea8834a4e6b55f81038f37c66170d2a52c8aa7 [file] [log] [blame]
vegall427cdb22024-06-13 15:59:43 +00001#!/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
garciadeblasbba76a52025-09-26 10:11:36 +020016if [ "$#" -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"
garciadeblas59816e82025-09-29 13:16:01 +020020 echo "When <GIT_PASSWORD> is provided, it will be used for git https authentication. Otherwise, ssh authentication will be used."
vegall427cdb22024-06-13 15:59:43 +000021 exit 1
22fi
23
24NEW_VERSION="$1"
garciadeblasbba76a52025-09-26 10:11:36 +020025GIT_USER="$2"
26GIT_PASSWORD="${3:-}"
27
garciadeblas90480ca2025-03-12 11:16:36 +010028BRANCH_NAME="v$(echo $NEW_VERSION | grep -oE '[0-9]+\.[0-9]+')"
vegall427cdb22024-06-13 15:59:43 +000029
garciadeblas59816e82025-09-29 13:16:01 +020030BASE_FOLDER=$(mktemp -d --tmpdir change-chart-version.XXXXXX)
garciadeblasbba76a52025-09-26 10:11:36 +020031pushd $BASE_FOLDER
32
33if [ -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
38if echo "$1" | grep -q '^Password'; then
39 echo "${GIT_PASSWORD}"
40else
41 echo "${GIT_USER}"
42fi
43exit 0
44EOF
45 chmod +x "${HOME}/git-creds.sh"
46else
47 REPO_URL="ssh://${GIT_USER}@osm.etsi.org:29418/osm/devops"
48fi
49
50echo "Cloning devops repo"
51if [ -n "$GIT_PASSWORD" ]; then
52 echo "Using https authentication"
53 GIT_USERNAME="${GIT_USER}" GIT_ASKPASS=~/git-creds.sh git clone "${REPO_URL}"
54else
55 echo "Using ssh authentication"
56 git clone "${REPO_URL}"
57fi
58cd "devops"
59curl https://osm.etsi.org/gerrit/tools/hooks/commit-msg > .git/hooks/commit-msg
60chmod +x .git/hooks/commit-msg
vegall427cdb22024-06-13 15:59:43 +000061
62git checkout $BRANCH_NAME
garciadeblas90480ca2025-03-12 11:16:36 +010063sed -i -E "0,/^version: .*/s//version: \"$NEW_VERSION\"/" installers/helm/osm/Chart.yaml
vegall427cdb22024-06-13 15:59:43 +000064sed -i -E "0,/^appVersion: .*/s//appVersion: \"$NEW_VERSION\"/" installers/helm/osm/Chart.yaml
65
66git add installers/helm/osm/Chart.yaml
garciadeblas90480ca2025-03-12 11:16:36 +010067git commit -s -m "Update chart version version to $NEW_VERSION"
garciadeblasbba76a52025-09-26 10:11:36 +020068
69echo "Pushing changes to devops repo"
70if [ -n "$GIT_PASSWORD" ]; then
71 echo "Using https authentication"
72 GIT_USERNAME="${GIT_USER}" GIT_ASKPASS=~/git-creds.sh git push origin $BRANCH_NAME
73else
74 echo "Using ssh authentication"
75 git push origin $BRANCH_NAME
76fi
vegall427cdb22024-06-13 15:59:43 +000077
78commit=$(git show --summary | grep commit | awk '{print $2}')
garciadeblasa9cab1f2025-01-13 12:04:42 +010079echo "The commit is $commit"
garciadeblasbba76a52025-09-26 10:11:36 +020080cd ..
garciadeblas90480ca2025-03-12 11:16:36 +010081rm -rf devops
82
garciadeblasbba76a52025-09-26 10:11:36 +020083popd