forked from googleapis/google-cloud-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·201 lines (180 loc) · 5.1 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
#!/bin/bash
set -e
cd $(dirname $0)
source toolversions.sh
# Disable automatic test reporting to AppVeyor.
# See https://github.com/googleapis/google-cloud-dotnet/issues/1232
unset APPVEYOR_API_URL
# Make it easier to handle globbing that doesn't
# match anything, e.g. when looking for tests.
shopt -s nullglob
# Command line arguments are the APIs to build. Each argument
# should be the name of a directory, either relative to the location
# of this script, or under apis.
# Additional arguments:
# --notests: Just build, don't run the tests
# --diff: Detect which APIs to build based on a diff to the master branch
# --regex regex: Only build APIs that match the given regex
# --nobuild: Just list which APIs would be built; don't run the build
# --coverage: Run tests with coverage enabled
apis=()
runtests=true
runcoverage=false
apiregex=
nobuild=false
diff=false
while (( "$#" )); do
if [[ "$1" == "--notests" ]]
then
runtests=false
elif [[ "$1" == "--diff" ]]
then
apis+=($(git diff master --name-only | grep -e 'apis/.*/' | cut -d/ -f 2 | uniq))
diff=true
elif [[ "$1" == "--regex" ]]
then
shift
apiregex=$1
elif [[ "$1" == "--nobuild" ]]
then
nobuild=true
elif [[ "$1" == "--coverage" ]]
then
runcoverage=true
install_dotcover
mkdir -p coverage
else
apis+=($1)
fi
shift
done
# Build and test the tools, but only on Windows
[[ "$OS" == "Windows_NT" ]] && tools="tools" || tools=""
# If no APIs were specified explicitly, build all of them (and tools on Windows)
if [[ ${#apis[@]} -eq 0 && $diff == false ]]
then
apis=(${tools} $($PYTHON3 tools/listapis.py apis/apis.json))
fi
# If we were given an API filter regex, apply it now.
if [[ "$apiregex" != "" ]]
then
filteredapis=()
# This is a hack to allow ! to negate the regex.
# Bash regular expressions don't allow for lookahead, so this is the
# simplest way of doing it.
if [[ $apiregex == !* ]]
then
apiregex=$(echo $apiregex | sed s/^!//g)
for api in ${apis[*]}
do
if [[ ! "$api" =~ $apiregex ]]
then
if [[ -d "apis/$api" ]]
then
filteredapis+=($api)
else
echo "Skipping missing API $api; recently deleted?"
fi
fi
done
else
for api in ${apis[*]}
do
if [[ "$api" =~ $apiregex ]]
then
if [[ -d "apis/$api" ]]
then
filteredapis+=($api)
else
echo "Skipping missing API $api; recently deleted?"
fi
fi
done
fi
unset apis
apis=("${filteredapis[@]}")
if [[ ${#apis[@]} -eq 0 ]]
then
echo "After regular expression filter, no projects left to build. Exiting."
exit 0
fi
fi
# If we are building Google.Cloud.Diagnostics.AspNetCore we also need to build
# Google.Cloud.Diagnostics.AspNetCore3 since they share code files.
hasCore=false
hasCore3=false
for api in ${apis[*]}
do
if [[ "$api" == "Google.Cloud.Diagnostics.AspNetCore" ]]
then
hasCore=true
elif [[ "$api" == "Google.Cloud.Diagnostics.AspNetCore3" ]]
then
hasCore3=true
fi
done
if [[ "$hasCore" == "true" ]] && [[ "$hasCore3" == "false" ]]
then
apis+=("Google.Cloud.Diagnostics.AspNetCore3")
fi
if [[ "$nobuild" == "true" ]]
then
echo "APIs that would be built:"
for api in ${apis[*]}
do
echo "$api"
done
exit 0
fi
# First build the analyzers, for use in everything else.
log_build_action "(Start) build.sh"
log_build_action "Building analyzers"
dotnet publish -nologo -clp:NoSummary -v quiet -c Release -f netstandard1.3 tools/Google.Cloud.Tools.Analyzers
# Then build the requested APIs, working out the test projects as we go.
> AllTests.txt
for api in ${apis[*]}
do
[[ -d "$api" ]] && apidir=$api || apidir=apis/$api
# ServiceDirectory is in apis/ for the sake of autosynth, but doesn't really build.
if [[ "$api" == "ServiceDirectory" ]]
then
continue
fi
log_build_action "Building $apidir"
dotnet build -nologo -clp:NoSummary -v quiet -c Release $apidir
# On Linux, we don't have desktop .NET, so any projects which only
# support desktop .NET are going to be broken. Just don't add them.
for testproject in $apidir/*.Tests/*.csproj
do
if [[ "$OS" == "Windows_NT" ]] || ! grep -q -E '>net[0-9]+<' $testproject
then
echo "$testproject" >> AllTests.txt
fi
done
# If we're not going to test the desktop .NET builds, let's remove them
# entirely. This saves a huge amount of disk space, as the desktop framework
# builds include copies of gRPC.
if [[ ! "$OS" == "Windows_NT" ]]
then
rm -rf $apidir/*/bin/Release/net[0-9]*
fi
done
if [[ "$runtests" = true ]]
then
log_build_action "(Start) Unit tests"
# Could use xargs, but this is more flexible
while read testproject
do
testdir=$(dirname $testproject)
log_build_action "Testing $testdir"
if [[ "$runcoverage" = true && -f "$testdir/coverage.xml" ]]
then
echo "(Running with coverage)"
(cd "$testdir"; $DOTCOVER cover "coverage.xml" --ReturnTargetExitCode)
else
dotnet test -nologo -c Release --no-build $testproject
fi
done < AllTests.txt
log_build_action "(End) Unit tests"
fi
log_build_action "(End) build.sh"