-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbuild_new_nightly
executable file
·99 lines (83 loc) · 2.89 KB
/
build_new_nightly
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
#!/bin/bash
# make bash behave
set -euo pipefail
IFS=$'\n\t'
# constants
stderr=2
badusage=64
latestpg="10"
if [ "${TARGET_PLATFORM:-}" = "" ]; then
echo TARGET_PLATFORM must be set
exit $badusage
fi
PLATFORM_TYPE="$(echo "$TARGET_PLATFORM" | cut -d "/" -f1)"
PLATFORM_VERSION="$(echo "$TARGET_PLATFORM" | cut -d "/" -f2)"
pkgauth="${PACKAGECLOUD_API_TOKEN}:"
hubauth="Authorization: token ${GITHUB_TOKEN}"
# populate variables from packaging metadata file
# shellcheck source=/dev/null
source pkgvars
# set default values for certain packaging variables
nightlyref="${nightlyref:-master}"
releasepg="${releasepg:-9.6,10}"
nightlypg="${nightlypg:-${releasepg}}"
latestpg=$(echo "${nightlypg}" | tr ',' '\n' | sort -t. -k1,1n -k2,2n | tail -n1)
if [[ "$PLATFORM_TYPE" == "debian" ]] && [[ "$PLATFORM_VERSION" == "jessie" ]]; then
# Debian Jessie doesn't have pg13 packages yet, override latestpg
latestpg=12
fi
if { [[ "$PLATFORM_TYPE" == "el" ]] || [[ "$PLATFORM_TYPE" == "ol" ]]; } && [[ "$PLATFORM_VERSION" == "6" ]]; then
# CentOS & OracleLinux 6 don't have pg13 packages yet, override latestpg
latestpg=12
fi
case "${PLATFORM_TYPE}" in
debian|ubuntu)
pkgflavor='deb'
pkgname="${deb_pkgname:-${pkgname}}"
pkgfull="postgresql-${latestpg}-${pkgname}"
pkgarch="amd64"
;;
el|ol)
pkgflavor='rpm'
pkgname="${rpm_pkgname:-${pkgname}}"
pkgfull="${pkgname}_${latestpg//./}"
pkgarch="x86_64"
;;
*)
echo "$0: unknown package flavor -- ${pkgflavor}" >&2
usage $stderr $badusage
;;
esac
hubproj="${hubproj:-${pkgname}}"
pkgapiurl="https://packagecloud.io/api/v1/repos/citusdata/${PKG_REPOTYPE}-nightlies"
pkgapiurl+="/package/${pkgflavor}/${TARGET_PLATFORM}/${pkgfull}/${pkgarch}/versions.json"
response=$(curl -w '\n%{http_code}\n' -s -u "${pkgauth}" "${pkgapiurl}?per_page=1000")
httpcode=$(echo "${response}" | tail -n1)
case "${httpcode}" in
404)
httpbody='[]'
;;
200)
httpbody=$(echo "${response}" | sed '$d')
;;
*)
echo "$0: bad response code from packagecloud -- ${httpcode}" >&2
exit $noservice
;;
esac
epochstr='"1970-01-01T00:00:00.000Z"'
lastnightly=$(echo "${httpbody}" | jq -r "map(.created_at) | sort | last // ${epochstr}")
hubapiurl="https://api.github.com/repos/citusdata/${hubproj}/commits?"
hubapiurl+="sha=${nightlyref}&since=${lastnightly}&per_page=1"
newcommitcount=$(curl -sf -H "${hubauth}" "${hubapiurl}" | jq -r 'length')
if [ "${newcommitcount}" -gt 0 ]; then
citus_package -p "${TARGET_PLATFORM}" 'local' nightly 2>&1 > citus_package.log
echo "Warnings generated by nightly docker build :"
grep -Ei '(warning|\bi|\be|\bw):' citus_package.log || true
mkdir -p pkgs/nightlies
shopt -s nullglob
mv ./*/*.rpm ./*/*.deb pkgs/nightlies
git clean -df -e pkgs
else
echo 'nightly up to date'
fi