forked from kurrent-io/KurrentDB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·137 lines (109 loc) · 3.56 KB
/
build.sh
File metadata and controls
executable file
·137 lines (109 loc) · 3.56 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
#!/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"
NET_FRAMEWORK="net8.0"
function usage() {
cat <<EOF
Usage:
$0 [<version=0.0.0.0>] [<configuration=Debug|Release>]
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
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
[[ $# -gt 2 ]] && 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
}
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 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"
echo "Running from base directory: $BASE_DIR"
buildEventStore