-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.sh
executable file
·206 lines (178 loc) · 5.71 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
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
#!/usr/bin/env bash
set -ue
# Everything in this script is relative to the directory containing this script.
# This works most of the time but is not perfect. It will fail if the script is sourced or if the script is
# executed from a symlink.
cd "$(dirname "${BASH_SOURCE[0]}")"
# Read version from icerpc.version.props
version=$(cat build/IceRpc.Version.props | grep "<Version" | sed -E "s/<Version .*>(.*)<\/Version>/\1/g" | sed -e 's/^[[:space:]]*//')
usage()
{
echo "Usage: ./build.sh [actions] [arguments]"
echo ""
echo "Actions (defaults to --build):"
echo " --build Build the IceRPC assemblies and the slicec-cs compiler."
echo " --publish Creates and publishes the IceRPC NuGet packages to the local global-packages source."
echo " --clean Clean all build artifacts."
echo " --coverage Generate code coverage report from the tests runs."
echo " Requires reportgenerator command from https://github.com/danielpalme/ReportGenerator"
echo " --doc Generate the C# API documentation"
echo " Requires docfx from https://github.com/dotnet/docfx"
echo ""
echo "Arguments:"
echo " --config Build configuration: debug or release, the default is debug."
echo " --version The version override for the IceRPC NuGet packages. The default version is the version"
echo " specified in the build/IceRpc.Version.props file."
echo " --help Print help and exit."
}
build()
{
arguments=("build")
if [ "$config" == "release" ]; then
arguments+=("--release")
fi
pushd tools/slicec-cs
run_command cargo "${arguments[@]}"
popd
pushd tools
run_command dotnet "build" "-nr:false"$version_property "-c" "$dotnet_config"
popd
run_command dotnet "build" "-nr:false"$version_property "-c" "$dotnet_config"
}
clean()
{
pushd tools/slicec-cs
run_command cargo clean
popd
pushd tools
run_command dotnet "clean" "-nr:false"$version_property "-c" "$dotnet_config"
popd
run_command dotnet "clean" "-nr:false"$version_property
pushd src/IceRpc.Templates
run_command dotnet "clean"$version_property "-nr:false"
popd
}
doc()
{
pushd docfx
run_command docfx "metadata" "--property" "Configuration=$dotnet_config"
run_command docfx "build"
popd
}
publish()
{
build
pushd tools
run_command dotnet "pack" "-nr:false"$version_property "-c" "$dotnet_config"
popd
run_command dotnet "pack" "-nr:false"$version_property "-c" "$dotnet_config"
pushd src/IceRpc.Templates
run_command dotnet "pack" "-nr:false"$version_property "-c" "$dotnet_config"
popd
global_packages=$(dotnet nuget locals -l global-packages)
global_packages=${global_packages/global-packages: /""}
run_command rm "-rf" "$global_packages/zeroc.slice/$version" "$global_packages/icerpc/$version" "$global_packages"/icerpc.*/"$version"
run_command dotnet "nuget" "push" "tools/**/$dotnet_config/*.$version.nupkg" "--source" "$global_packages"
run_command dotnet "nuget" "push" "src/**/$dotnet_config/*.$version.nupkg" "--source" "$global_packages"
}
code_coverage()
{
runsettings=${PWD}/build/Coverlet.runsettings
arguments=("test" "-c" "$dotnet_config" "-p:RunSettingsFilePath=$runsettings" "--collect:\"XPlat Code Coverage\"")
run_command dotnet "${arguments[@]}"
arguments=("-reports:tests/*/TestResults/*/coverage.cobertura.xml" "-targetdir:tests/CodeCoverageReport")
if [ -n "${REPORTGENERATOR_LICENSE:-}" ]; then
arguments+=("-license:${REPORTGENERATOR_LICENSE}")
fi
run_command reportgenerator "${arguments[@]}"
# Remove code coverage results after the report has been generated.
find "tests" -type d -name "TestResults" -prune -exec rm -rf {} \;
}
run_command()
{
echo "$@"
"$@"
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Error $exit_code"
exit $exit_code
fi
}
config=""
version_property=""
passedInActions=()
actions=("--build" "--clean" "--doc" "--coverage" "--publish")
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-h|--help)
usage
exit 0
;;
-c|--config)
config=$2
shift
shift
;;
--version)
version=$2
version_property=" -p:Version=$version"
shift
shift
;;
*)
found=0
for action in "${actions[@]}"; do
if [ "$action" == "$1" ]; then
passedInActions+=("$action")
found=1
break
fi
done
if [ $found -eq 0 ]; then
echo "Unknown argument: " "$1"
echo ""
usage
exit 1
fi
shift
;;
esac
done
if [ -z "$config" ]; then
config="debug"
fi
configs=("debug" "release")
if [[ ! " ${configs[*]} " == *" ${config} "* ]]; then
echo "Invalid config: '" $config "', config must 'debug' or 'release'"
echo ""
usage
exit 1
fi
if [ "$config" == "release" ]; then
dotnet_config="Release"
else
dotnet_config="Debug"
fi
if [ "${#passedInActions[@]}" -eq 0 ]; then
passedInActions=("--build")
fi
for action in "${passedInActions[@]}"; do
case $action in
"--build")
build
;;
"--publish")
publish
;;
"--clean")
clean
;;
"--coverage")
code_coverage
;;
"--doc")
doc
;;
esac
done