forked from ikkentim/SampSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·232 lines (203 loc) · 5.92 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·232 lines (203 loc) · 5.92 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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/bin/bash
# Root build dispatcher for SampSharp plugins
# Usage: build.sh <target> [action] [options]
# Targets: legacy-plugin, legacy-libraries, component, libraries
# Actions: (empty), test, publish
# Options: --no-build, --version=<version>
set -euo pipefail
show_usage() {
echo ""
echo "Usage:"
echo " build.sh legacy-plugin - Build legacy x86 plugin"
echo " build.sh legacy-plugin publish - Build and publish legacy x86 plugin"
echo " build.sh legacy-libraries - Build legacy C# libraries"
echo " build.sh legacy-libraries publish - Build and pack legacy C# libraries"
echo " build.sh component - Build open.mp component"
echo " build.sh component publish - Build and publish open.mp component"
echo " build.sh libraries - Build C# libraries"
echo " build.sh libraries test - Test C# libraries"
echo " build.sh libraries publish - Build and pack C# libraries"
echo " build.sh clean - Delete build directory contents"
echo ""
echo "Options:"
echo " --no-build - Skip the build step for tests"
echo " --version=<version> - Set the CI package version"
}
build_component_libraries() {
local SCRIPTDIR="$1"
cd "$SCRIPTDIR"
echo ""
echo "Building C# libraries..."
if [ -n "$VERSION" ]; then
dotnet build SampSharp.slnx -c Release "/p:CiVersion=$VERSION"
else
dotnet build SampSharp.slnx -c Release
fi
}
test_component_libraries() {
local SCRIPTDIR="$1"
local RESULTSDIR="$SCRIPTDIR/build/test-results/libraries"
cd "$SCRIPTDIR"
mkdir -p "$RESULTSDIR"
echo ""
echo "Testing C# libraries..."
local command=(dotnet test SampSharp.slnx -c Release --results-directory "$RESULTSDIR" --logger "trx;LogFilePrefix=libraries")
if [ "$NO_BUILD" = true ]; then
command+=(--no-build)
fi
if [ -n "$VERSION" ]; then
command+=("/p:CiVersion=$VERSION")
fi
"${command[@]}"
}
pack_component_libraries() {
local SCRIPTDIR="$1"
cd "$SCRIPTDIR"
echo ""
echo "Packing C# libraries..."
if [ -n "$VERSION" ]; then
dotnet pack SampSharp.slnx -c Release "/p:CiVersion=$VERSION"
else
dotnet pack SampSharp.slnx -c Release
fi
echo ""
echo "NuGet packages created in: $SCRIPTDIR/build/artifacts/packages"
}
build_legacy_libraries() {
local SCRIPTDIR="$1"
cd "$SCRIPTDIR/src/legacy"
echo ""
echo "Building C# libraries..."
if [ -n "$VERSION" ]; then
dotnet build SampSharp.Legacy.slnx -c Release "/p:CiVersion=$VERSION"
else
dotnet build SampSharp.Legacy.slnx -c Release
fi
}
pack_legacy_libraries() {
local SCRIPTDIR="$1"
cd "$SCRIPTDIR/src/legacy"
echo ""
echo "Packing C# libraries..."
if [ -n "$VERSION" ]; then
dotnet pack SampSharp.Legacy.slnx -c Release "/p:CiVersion=$VERSION"
else
dotnet pack SampSharp.Legacy.slnx -c Release
fi
echo ""
echo "NuGet packages created in: $SCRIPTDIR/build/artifacts/packages"
}
TARGET="${1:-}"
SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -z "$TARGET" ]; then
show_usage
exit 1
fi
shift
ACTION=""
if [ $# -gt 0 ]; then
case "$1" in
test|publish)
ACTION="$1"
shift
;;
esac
fi
VERSION=""
NO_BUILD=false
while [ $# -gt 0 ]; do
case "$1" in
--no-build)
NO_BUILD=true
;;
--version=*)
VERSION="${1#--version=}"
if [ -z "$VERSION" ]; then
echo "Missing value for --version"
exit 1
fi
;;
--version)
shift
if [ $# -eq 0 ]; then
echo "Missing value for --version"
exit 1
fi
VERSION="$1"
;;
*)
echo "Invalid option: $1"
show_usage
exit 1
;;
esac
shift
done
case "$TARGET" in
component-libraries)
TARGET="libraries"
;;
esac
case "$TARGET" in
legacy-plugin)
if [ -z "$ACTION" ]; then
echo "Building legacy plugin (x86)..."
"$SCRIPTDIR/src/legacy/SampSharp/build.sh"
elif [ "$ACTION" = "publish" ]; then
echo "Building and publishing legacy plugin (x86)..."
"$SCRIPTDIR/src/legacy/SampSharp/build.sh"
"$SCRIPTDIR/src/legacy/SampSharp/publish.sh"
else
show_usage
exit 1
fi
;;
legacy-libraries)
if [ -z "$ACTION" ]; then
build_legacy_libraries "$SCRIPTDIR"
elif [ "$ACTION" = "publish" ]; then
pack_legacy_libraries "$SCRIPTDIR"
else
show_usage
exit 1
fi
;;
component)
if [ -z "$ACTION" ]; then
echo "Building open.mp component..."
"$SCRIPTDIR/src/sampsharp-component/build.sh"
elif [ "$ACTION" = "publish" ]; then
echo "Building and publishing open.mp component..."
"$SCRIPTDIR/src/sampsharp-component/build.sh"
"$SCRIPTDIR/src/sampsharp-component/publish.sh"
else
show_usage
exit 1
fi
;;
libraries)
if [ -z "$ACTION" ]; then
build_component_libraries "$SCRIPTDIR"
elif [ "$ACTION" = "test" ]; then
test_component_libraries "$SCRIPTDIR"
elif [ "$ACTION" = "publish" ]; then
pack_component_libraries "$SCRIPTDIR"
else
show_usage
exit 1
fi
;;
clean)
echo "Cleaning build directory..."
rm -rf "$SCRIPTDIR/build"
mkdir -p "$SCRIPTDIR/build"
echo "Build directory cleaned."
;;
*)
echo "Invalid target: $TARGET"
show_usage
exit 1
;;
esac
echo "Build complete."
exit 0