-
Notifications
You must be signed in to change notification settings - Fork 11
/
SCYLLA-VERSION-GEN
executable file
·110 lines (94 loc) · 3.14 KB
/
SCYLLA-VERSION-GEN
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
#!/bin/bash -e
USAGE="$(cat <<-END
Usage: $(basename "$0") [-h|--help] [-o|--output-dir PATH] [--date-stamp DATE] -- generate Scylla version and build information files.
Options:
-h|--help show this help message.
-o|--output-dir PATH specify destination path at which the version files are to be created.
-d|--date-stamp DATE manually set date for release parameter
-v|--verbose also print out the version number
By default, the script will attempt to parse 'version' file
in the current directory, which should contain a string of
'\$version-\$release' form.
Otherwise, it will call 'git log' on the source tree (the
directory, which contains the script) to obtain current
commit hash and use it for building the version and release
strings.
The script assumes that it's called from the Scylla source
tree.
The files created are:
SCYLLA-VERSION-FILE
SCYLLA-RELEASE-FILE
By default, these files are created in the 'build'
subdirectory under the directory containing the script.
The destination directory can be overridden by
using '-o PATH' option.
END
)"
DATE=""
PRINT_VERSION=0
while [[ $# -gt 0 ]]; do
opt="$1"
case "${opt}" in
-h|--help)
echo "${USAGE}"
exit 0
;;
-o|--output-dir)
OUTPUT_DIR="$2"
shift 2
;;
--date-stamp)
DATE="$2"
shift 2
;;
-v|--verbose)
PRINT_VERSION=1
shift 1
;;
*)
echo "Unexpected argument found: $1"
echo
echo "${USAGE}"
exit 1
;;
esac
done
SCRIPT_DIR="$(dirname "$0")"
if [[ -z "${OUTPUT_DIR}" ]]; then
OUTPUT_DIR="${SCRIPT_DIR}/build"
fi
if [[ -z "${DATE}" ]]; then
DATE="$(date --utc +%Y%m%d)"
fi
# Default scylla version tags
VERSION="$(sed -n -e 's/^version = \"\(.*\)\"$/\1/p' scylla-rust-wrapper/Cargo.toml)"
if [[ -f version ]]; then
SCYLLA_VERSION="$(cat version | awk -F'-' '{print $1}')"
SCYLLA_RELEASE="$(cat version | awk -F'-' '{print $2}')"
else
SCYLLA_VERSION="${VERSION}"
if [[ -z "${SCYLLA_RELEASE}" ]]; then
GIT_COMMIT="$(git -C "${SCRIPT_DIR}" log --pretty=format:'%h' -n 1 --abbrev=12)"
# For custom package builds, replace "0" with "counter.your_name",
# where counter starts at 1 and increments for successive versions.
# This ensures that the package manager will select your custom
# package over the standard release.
SCYLLA_BUILD=0
SCYLLA_RELEASE="${SCYLLA_BUILD}.${DATE}.${GIT_COMMIT}"
elif [[ -f "${OUTPUT_DIR}/SCYLLA-RELEASE-FILE" ]]; then
echo "setting SCYLLA_RELEASE only makes sense in clean builds" 1>&2
exit 1
fi
fi
if [[ -f "${OUTPUT_DIR}/SCYLLA-RELEASE-FILE" ]]; then
GIT_COMMIT_FILE=$(cat "${OUTPUT_DIR}/SCYLLA-RELEASE-FILE" |cut -d . -f 3)
if [[ "${GIT_COMMIT}" = "${GIT_COMMIT_FILE}" ]]; then
exit 0
fi
fi
if [[ ${PRINT_VERSION} -eq 1 ]]; then
echo "${SCYLLA_VERSION}-${SCYLLA_RELEASE}"
fi
mkdir -p "${OUTPUT_DIR}"
echo "${SCYLLA_VERSION}" > "${OUTPUT_DIR}/SCYLLA-VERSION-FILE"
echo "${SCYLLA_RELEASE}" > "${OUTPUT_DIR}/SCYLLA-RELEASE-FILE"