-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper.sh
executable file
·127 lines (106 loc) · 3.64 KB
/
helper.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
KITDIR="$(dirname "${BASH_SOURCE}")"
ROOT="${ROOT:-${KITDIR}/..}"
OUTPUT="${OUTPUT:-${ROOT}/output}"
PATCHESDIR="${PATCHESDIR:-${ROOT}/patches}"
REPOSDIR="${REPOSDIR:-${ROOT}/repos}"
TMPDIR="${TMP_DIR:-./tmp}"
CONFIG="${CONFIG:-${ROOT}/releases.yml}"
KITDIR=$(realpath -m ${KITDIR})
ROOT=$(realpath -m ${ROOT})
OUTPUT=$(realpath -m ${OUTPUT})
PATCHESDIR=$(realpath -m ${PATCHESDIR})
REPOSDIR=$(realpath -m ${REPOSDIR})
TMPDIR=$(realpath -m ${TMPDIR})
CONFIG=$(realpath -m ${CONFIG})
mkdir -p "${TMPDIR}"
function helper::download() {
local patch="$1"
if ! [[ "${patch}" =~ ^https?:// ]]; then
echo "$(realpath -m ${ROOT}/${patch})"
return
fi
local tmp_patch="${TMPDIR}/$(basename ${patch})"
if ! [[ -f "${tmp_patch}" ]]; then
echo "+++ Downloading patch to ${tmp_patch} from ${patch}" 1>&2
curl -o "${tmp_patch}" -sSL "${patch}"
fi
echo ${tmp_patch}
}
function helper::workdir::version() {
local version=$(cd "${WORKDIR}" && git describe --tags)
echo "${version}"
}
function helper::config::get_base_repository() {
cat "${CONFIG}" | yq ".base" | tr -d '"'
}
readonly REPO=$(helper::config::get_base_repository)
function helper::config::get_base_release() {
cat "${CONFIG}" | yq ".releases | .[] | select( .name == \"$1\" ) | .base_release" | tr -d '"'
}
function helper::config::get_patches() {
cat "${CONFIG}" | yq ".releases | .[] | select( .name == \"$1\" ) | .patches | .[]?" | tr -d '"'
}
function helper::config::get_patches_all() {
base_chain=$(helper::config::base_chain $1)
for base in ${base_chain}; do
cat "${CONFIG}" | yq ".releases | .[] | select( .name == \"${base}\" ) | .patches | .[]?" | tr -d '"'
done
}
function helper::config::get_test_failures_tolerated() {
base_chain=$(helper::config::base_chain $1)
for base in ${base_chain}; do
cat "${CONFIG}" | yq ".releases | .[] | select( .name == \"${base}\" ) | .test_failures_tolerated | .[]?" | tr -d '"'
done
}
function helper::config::get_test_integration_failures_tolerated() {
base_chain=$(helper::config::base_chain $1)
for base in ${base_chain}; do
cat "${CONFIG}" | yq ".releases | .[] | select( .name == \"${base}\" ) | .test_integration_failures_tolerated | .[]?" | tr -d '"'
done
}
function helper::config::base_chain() {
base="$1"
while [[ "${base}" != "" ]]; do
echo "${base}"
base=$(helper::config::get_base_release "${base}")
done
}
function helper::config::get_patch() {
local list=""
for patch in $@; do
patches=$(cat "${CONFIG}" | yq ".patches | .[] | select( .name == \"${patch}\" ) | .patch | .[]?" | tr -d '"')
for item in ${patches}; do
list+=" $(helper::download ${item})"
done
done
echo "${list}"
}
function helper::config::list_releases() {
cat "${CONFIG}" | yq ".releases | .[] | select( .must == true ) | .name" | tr -d '"'
}
function helper::repos::get_base_repository() {
cd "${ROOT}" && git remote get-url origin | sed -E 's#git@(.+):(.+)#https://\1/\2#g'
}
function helper::repos::branch() {
echo repos
}
WORKDIR="${WORKDIR:-${ROOT}/src/${REPO##*//}}"
WORKDIR=$(realpath -m ${WORKDIR})
function helper::show() {
echo "KITDIR: ${KITDIR}"
echo "ROOT: ${ROOT}"
echo "OUTPUT: ${OUTPUT}"
echo "PATCHESDIR: ${PATCHESDIR}"
echo "REPOSDIR: ${REPOSDIR}"
echo "TMPDIR: ${TMPDIR}"
echo "CONFIG: ${CONFIG}"
echo "REPO: ${REPO}"
echo "WORKDIR: ${WORKDIR}"
}
if [[ "$(git config --global user.name)" == "" ]]; then
git config --global user.name "bot"
fi