forked from EventStore/EventStore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·177 lines (143 loc) · 4.56 KB
/
build.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
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
#!/usr/bin/env bash
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PRODUCTNAME="Event Store Open Source"
COMPANYNAME="Event Store Ltd"
COPYRIGHT="Copyright 2021 Event Store Ltd. All rights reserved."
# ------------ End of configuration -------------
CONFIGURATION="Release"
BUILD_UI="no"
NET_FRAMEWORK="net6.0"
function usage() {
cat <<EOF
Usage:
$0 [<version=0.0.0.0>] [<configuration=Debug|Release>] [<build_ui=yes|no>]
version: EventStore build version. Versions must be complete four part identifiers valid for use on a .NET assembly.
configuration: Build configuration. Valid configurations are: Debug, Release
build_ui: Whether or not to build the EventStore UI. Building the UI requires an installation of Node.js (v8.11.4+)
EOF
exit 1
}
function detectOS(){
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) os=Linux;;
Darwin*) os=MacOS;;
*) os="${unameOut}"
esac
if [[ "$os" != "Linux" && $os != "MacOS" ]] ; then
echo "Unsupported operating system: $os. Only Linux and MacOS are supported."
exit 1
fi
OS=$os
}
function checkParams() {
if [[ "$1" == "-help" || "$1" == "--help" ]] ; then
usage
fi
version=$1
configuration=$2
build_ui=$3
[[ $# -gt 3 ]] && usage
if [[ "$version" == "" ]] ; then
VERSIONSTRING="0.0.0.0"
echo "Version defaulted to: 0.0.0.0"
else
VERSIONSTRING=$version
echo "Version set to: $VERSIONSTRING"
fi
if [[ "$configuration" == "" ]]; then
CONFIGURATION="Release"
echo "Configuration defaulted to: $CONFIGURATION"
else
if [[ "$configuration" == "Release" || "$configuration" == "Debug" ]]; then
CONFIGURATION=$configuration
echo "Configuration set to: $CONFIGURATION"
else
echo "Invalid configuration: $configuration"
usage
fi
fi
if [[ "$build_ui" == "" ]]; then
BUILD_UI="no"
echo "Build UI defaulted to: $BUILD_UI"
else
if [[ "$build_ui" == "yes" || "$build_ui" == "no" ]]; then
BUILD_UI=$build_ui
echo "Build UI set to: $BUILD_UI"
else
echo "Invalid Build UI value: $build_ui"
usage
fi
fi
}
function revertVersionInfo() {
files=$( find . -name "VersionInfo.cs" )
for file in $files
do
git checkout "$file"
echo "Reverted $file"
done
}
function err() {
revertVersionInfo
echo "FAILED. See earlier messages"
exit 1
}
function patchVersionInfo {
branchName=$(git rev-parse --abbrev-ref HEAD)
commitHash=$(git log -n1 --pretty=format:"%H" HEAD)
commitTimestamp=$(git log -n1 --pretty=format:"%aD" HEAD)
newVersion="public static readonly string Version = \"$VERSIONSTRING\";"
newBranch="public static readonly string Branch = \"$branchName\";"
newCommitHash="public static readonly string Hashtag = \"$commitHash\";"
newTimestamp="public static readonly string Timestamp = \"$commitTimestamp\";"
versionPattern="public static readonly string Version .*$"
branchPattern="public static readonly string Branch .*$"
commitHashPattern="public static readonly string Hashtag .*$"
timestampPattern="public static readonly string Timestamp .*$"
files=$( find . -name "VersionInfo.cs" )
for file in $files
do
tempfile="$file.tmp"
sed -e "s/$versionPattern/$newVersion/" \
-e "s/$branchPattern/$newBranch/" \
-e "s/$commitHashPattern/$newCommitHash/" \
-e "s/$timestampPattern/$newTimestamp/" \
"$file" > "$tempfile"
mv "$tempfile" "$file"
echo "Patched $file with version information"
done
}
function buildUI {
if [[ "$BUILD_UI" != "yes" ]] ; then
echo "Skipping UI Build"
return
fi
rm -rf src/EventStore.ClusterNode.Web/clusternode-web/
pushd src/EventStore.UI
if [ ! -f ./package.json ]; then
git submodule update --init ./
fi
npm install bower@~1.8.14 -g
bower install --allow-root
npm install gulp-cli -g
npm install
gulp dist
mv es-dist ../EventStore.ClusterNode.Web/clusternode-web/
popd
}
function buildEventStore {
patchVersionInfo
rm -rf bin/
dotnet build -c $CONFIGURATION /p:Platform=x64 /p:Version=$VERSIONSTRING --framework=$NET_FRAMEWORK src/EventStore.sln || err
revertVersionInfo
}
function exitWithError {
echo "$1"
exit 1
}
detectOS
checkParams "$1" "$2" "$3"
echo "Running from base directory: $BASE_DIR"
buildUI
buildEventStore