-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathfetch_and_build_rpm
More file actions
executable file
·246 lines (206 loc) · 8.02 KB
/
fetch_and_build_rpm
File metadata and controls
executable file
·246 lines (206 loc) · 8.02 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/bin/bash
# make bash behave
set -euo pipefail
# In one branch we execute commands inside One Branch steps, since One Branch does not allow executing docker inside
# docker. Additionally, Onebranch needs containers not to close so we make it hang for OneBranch to be able to
# execute commands.
if [ "${CONTAINER_BUILD_RUN_ENABLED:-""}" == "" ]; then
echo "INFO: Image working in waiting mode. Not executing build script"
tail -f /dev/null
fi
IFS=$'\n\t'
# constants
stdout=1
stderr=2
success=0
failure=1
badusage=64
noinput=66
nextversion='0.0.0'
builddir=$(pwd)
# outputs usage message on specified device before exiting with provided status
usage() {
cat << 'E_O_USAGE' >&"$1"
usage: fetch_and_build_rpm build_type build_directory
build_type: 'release', 'nightly', or a valid git reference
fetch_and_build_rpm builds Red Hat packages using local build files. The build
type 'release' builds the latest release tag, 'nightly' builds a nightly from
the latest 'master' commit, and any other type is interpreted as a git ref to
facilitate building one-off packages for customers.
E_O_USAGE
exit "${2}";
}
# sets the next version variable used during non-release builds
setnextversion() {
# First line replaces '~' and '_' characters and splits the version by '-' and gets the first
# from the array.
# Second line strips '.citus' suffix
# e.g. input->11.0.0_beta-1.citus; output->11.0.0
baseversion=$(echo "$1" | tr '~' '-' | tr '_' '-' | cut -d- -f1)
baseversion="${baseversion%.citus}"
nextversion=$(echo "$baseversion" | perl -pe 's/^(\d+\.)(\d+)(\.\d+)$/$1.($2+1).".0"/e')
}
if [ "$#" -ne 1 ]; then
usage $stderr $badusage
fi
if [ "${1}" = '-h' ]; then
usage $stdout $success
fi
# populate variables from packaging metadata file
# shellcheck source=/dev/null
source /buildfiles/pkgvars
# set default values for certain packaging variables
declare pkglatest # to make shellcheck happy
pkgname="${rpm_pkgname:-${pkgname}}"
hubproj="${hubproj:-${pkgname}}"
nightlyref="${nightlyref:-master}"
releasepg="${releasepg:-11,12,13}"
nightlypg="${nightlypg:-${releasepg}}"
versioning="${versioning:-simple}"
if [[ "${pkglatest}" == *"beta"* ]]; then
release_type="beta"
else
release_type="stable"
fi
if [ -z "${pkglatest}" ]; then
echo "$0: pkgvars file must specify a value for pkglatest" >&2
exit $noinput
fi
echo "header=\"Authorization: token ${GITHUB_TOKEN}\"" > ~/.curlrc
git config --global url."https://x-access-token:${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/"
name=$(determine_name)
email=$(determine_email)
export RPM_PACKAGER="${name} <${email}>"
cp "/buildfiles/${pkgname}.spec" /buildfiles/rpmlintrc "${builddir}"
repopath="citusdata/${hubproj}"
case "${1}" in
release)
packageversion=${pkglatest%-*}
releasetag="v${packageversion%.citus}"
# Since the only part of the release version after '-' character is fancy version, package release
# will alwayse be empty string. So the releasetag is always equal to packageversion
packagerelease=$(echo "${pkglatest#*-}" | sed -E 's/^[0-9.]+//')
if [ -n "${packagerelease}" ]; then
releasetag="v${packageversion}-${packagerelease}"
fi
conf_extra_version="%{nil}"
gitsha=$(curl -s "https://api.github.com/repos/${repopath}/git/refs/tags/${releasetag}" | \
jq -r '.object.sha')
if [ "${gitsha}" == 'null' ]; then
echo "$0: could not determine commit for git tag ${releasetag}" >&2
exit $failure
fi
verified=$(curl -sH 'Accept:application/vnd.github.cryptographer-preview+sha' \
"https://api.github.com/repos/${repopath}/git/tags/${gitsha}" | \
jq -r '.verification.verified')
if [ "${verified}" != 'true' ]; then
echo "$0: could not verify signature for git tag ${releasetag}" >&2
exit $failure
fi
;;
*)
if [ "${1}" == 'nightly' ]; then
ref=${nightlyref}
infix='git'
else
ref=${1}
infix='pre'
fi
setnextversion "${pkglatest}"
set +e
gitsha=$(curl -sfH 'Accept:application/vnd.github.v3.sha' \
"https://api.github.com/repos/${repopath}/commits/${ref}")
if [ "${?}" -ne 0 ]; then
echo "$0: could not determine commit for git ref ${ref}" >&2
exit $failure
fi
set -e
packageversion="${nextversion}.citus"
timestamp=$(date +'%Y%m%d')
packagesuffix="${infix}.${timestamp}.${gitsha:0:7}"
packagerelease="0.0.${packagesuffix}"
conf_extra_version="+${packagesuffix}"
sed -i -E -e "/^Version:/s/[^ \\t]*$/${packageversion}/" \
-e "/^Release:/s/[^ \\t]*$/${packagerelease}%{dist}/" \
"${builddir}/${pkgname}.spec"
;;
esac
# this should all take place in a package-build directory
rpmbuilddir="${builddir}/citus-rpm-build"
mkdir -p "${rpmbuilddir}"
pkgsrcdir="${builddir}/${pkgname}-${packageversion}"
mkdir "${pkgsrcdir}"
download=$(mktemp)
tarballurl="https://api.github.com/repos/${repopath}/tarball/${gitsha}"
curl -sL "${tarballurl}" -o "${download}"
tarballpath="${rpmbuilddir}/${gitsha}"
tar xf "${download}" -C "${pkgsrcdir}" --strip-components 1
# git metadata needs to be setup to initialize submodules
# in repos which rely on git submodules
if [[ -f "${pkgsrcdir}/.gitmodules" ]]; then
setup_submodules "${pkgsrcdir}"
fi
tar czf "${tarballpath}" "${pkgsrcdir}"
# force our URL and expanded folder names into spec
sed -i -E -e "\\|^Source0:|s|https:.*|${tarballurl}|" \
-e "/^%global pgmajorversion/s/[0-9]+$/${PGVERSION//'.'/}/" \
-e "/^%global pgpackageversion/s/[0-9.]+$/${PGVERSION}/" \
"${builddir}/${pkgname}.spec"
os_name=$(awk '{print $1}' /etc/system-release)
if [ "${os_name}" == 'AlmaLinux' ]; then
os_release=$(awk '{print $3}' /etc/system-release)
else
os_release=$(awk '{print $4}' /etc/system-release)
fi
if [ "${os_name}" == 'Oracle' ]; then
locale='C'
elif [ "${os_name}" == 'Fedora' ] || [[ ( "${os_name}" == 'CentOS' || "${os_name}" == 'AlmaLinux' ) && "${os_release}" == 8* ]]; then
locale='C.utf8'
else
locale='en_US.utf8'
fi
# add minor/major version to package name if using fancy versioning
if [ "${versioning}" == 'fancy' ]; then
infix=$(echo "${packageversion}" | grep -oE '^[0-9]+\.[0-9]+' | tr -d '.')
if [ "${release_type}" == "stable" ]; then
package_prefix="${infix}"
else
package_prefix="${infix}_${release_type}"
fi
sed -i -E "1i %global pkginfix ${package_prefix}" "${builddir}/${pkgname}.spec"
fi
# add a changelog entry into nightly build
case "${1}" in
release)
# Changelogs for release builds are being added by packaging scripts and could not be autogenerated
# Therefore there is nothing to do for release builds
;;
nightly)
msg="Nightly package. Built from ${nightlyref} "
msg+=$(date +'on %l:%M %p (%Z) on %A, %B %Y' | tr -s ' ')
LC_ALL=${locale} rpmdev-bumpspec -c "${msg}" "${builddir}/${pkgname}.spec"
sed -i -E 's/0.1.git/0.0.git/' "${builddir}/${pkgname}.spec"
sed -i -E "1i %global pkginfix ${package_prefix}" "${builddir}/${pkgname}.spec"
;;
*)
msg="Custom package. Built from ${gitsha:0:7} "
msg+=$(date +'on %l:%M %p (%Z) on %A, %B %Y' | tr -s ' ')
LC_ALL=${locale} rpmdev-bumpspec -c "${msg}" "${builddir}/${pkgname}.spec"
sed -i -E 's/0.1.pre/0.0.pre/' "${builddir}/${pkgname}.spec"
;;
esac
# Enable gcc8 on distros that have it
if [ -f /opt/rh/devtoolset-8/enable ]; then
set +u
# shellcheck source=/dev/null
source /opt/rh/devtoolset-8/enable
set -u
fi
rpmbuild --define "_sourcedir ${rpmbuilddir}" \
--define "_specdir ${rpmbuilddir}" \
--define "_builddir ${rpmbuilddir}" \
--define "_srcrpmdir ${rpmbuilddir}" \
--define "_rpmdir ${rpmbuilddir}" \
--define "conf_extra_version ${conf_extra_version}" \
-bb "${builddir}/${pkgname}.spec"
cp /citus-rpm-build/x86_64/*.rpm /packages