-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup_versioning.sh
112 lines (91 loc) · 3.41 KB
/
setup_versioning.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/sh -x
# MIT License
#
# (C) Copyright [2020-2022] Hewlett Packard Enterprise Development LP
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
set -ex
# Automated versioning changes are done here.
# Do not change versions in any other place
CHANGE_LOG=changelog$$
CURRENT_BRANCH=$GIT_BRANCH
# RELEASE_BRANCH is used to checkout the correct slingshot-version!
# Update RELEASE_BRANCH when a new release branch is created.
# For example:
# RELEASE_BRANCH=release/shs-11.0
RELEASE_BRANCH=main
if [ -d hpc-shs-version ]; then
rm -rf hpc-shs-version
fi
if [ ! -z "$HPE_GITHUB_TOKEN_USR" -a ! -z "$HPE_GITHUB_TOKEN_PSW" ]; then
git clone https://${HPE_GITHUB_TOKEN_USR}:${HPE_GITHUB_TOKEN_PSW}@github.hpe.com/hpe/hpc-shs-version.git -b $RELEASE_BRANCH
else
git clone https://github.hpe.com/hpe/hpc-shs-version.git -b $RELEASE_BRANCH
fi
cd hpc-shs-version
if ! git checkout $CURRENT_BRANCH > /dev/null ; then
echo "INFO: Branch ${CURRENT_BRANCH} is not an official SHS branch, using version string from ${RELEASE_BRANCH}" >&2
fi
cd - > /dev/null
PRODUCT_VERSION=$(cat hpc-shs-version/shs-version)
date=`date '+%a %b %d %Y'`
git_hash=`git rev-parse HEAD`
if [ -z "${BUILD_NUMBER}" ]; then
RELEASE="LocalBuild"
else
RELEASE=${BUILD_NUMBER}
fi
echo "${PRODUCT_VERSION}-${RELEASE}" > hpc-shs-version/shs-build-version
create_changelog() {
# Usage:
# create_changelog <output file name> <release_version>
outfile=$1
package_version=$2
rm -f $1
echo '* '`date '+%a %b %d %Y'`" $USER <[email protected]> $package_version" >> $1
echo "- Built from git hash ${git_hash}" >> $1
}
if [ "-d" = "${1}" ]; then
cat << EOF
# Copyright and version
© 2024 Hewlett Packard Enterprise Development LP
SHS:
${PRODUCT_VERSION}-${RELEASE}
Doc git hash:
${git_hash}
Generated:
${date}
EOF
fi
if [ ! -z "${BUILD_NUMBER}" ]; then
if [ -z "${PRODUCT_VERSION}" ]; then
echo "Version: ${PRODUCT_VERSION} is Empty"
exit 1
fi
create_changelog $CHANGE_LOG ${PRODUCT_VERSION}
# Modify .version files
sed -i s/0.0.0/${PRODUCT_VERSION}-${BUILD_NUMBER}/g .version
sed -i s/0.0.0/${PRODUCT_VERSION}/g .version_rpm
# Modify rpm spec
cat docs/portal/developer-portal/shs-docs.spec.template | sed \
-e "s/0.0.0/$PRODUCT_VERSION/g" \
-e "/__CHANGELOG_SECTION__/r $CHANGE_LOG" \
-e "/__CHANGELOG_SECTION__/d" > docs/portal/developer-portal/shs-docs.spec
fi
rm -f ${CHANGE_LOG}