forked from dotnet/corefxlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·123 lines (104 loc) · 3.13 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
#!/usr/bin/env bash
# adding dotnet to the path. it is needed to run toolset csc.
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
dotnet_path=$parent_path/dotnetcli
export PATH=$PATH:$dotnet_path
usage()
{
echo "build.sh [ Debug(default) | Release ]"
}
if [ "$1" == "-?" ] || [ "$1" == "-h" ]; then
usage
exit
fi
if [ $# -eq 0 ]
then
Configuration="Debug"
else
Configuration=$1
fi
BuildVersion="preview2-$(date '+%y%m%d')-1"
Version="<default>"
Restore="true"
echo "Configuration=$Configuration."
echo "Restore=$Restore."
echo "Version=$Version."
echo "BuildVersion=$BuildVersion."
dotnetExePath="dotnetcli/dotnet"
if [ "$Version" = "<default>" ]; then
Version=$(head -n 1 "DotnetCLIVersion.txt")
fi
if [ ! -d "dotnetcli" ]; then
echo "dotnet.exe not installed, downloading and installing."
./scripts/install-dotnet.sh -Channel master -Version "$Version" -InstallDir "dotnetcli"
ret=$?
if [ $ret -ne 0 ]; then
echo "Failed to install latest dotnet.exe, exit code $ret, aborting build."
exit -1
fi
./scripts/install-dotnet.sh -Version 2.0.0 -InstallDir "dotnetcli"
ret=$?
if [ $ret -ne 0 ]; then
echo "Failed to install framework version 2.0.0, exit code $ret, aborting build."
exit -1
fi
else
echo "dotnet.exe is installed, checking for latest."
cliVersion=$(./$dotnetExePath --version)
if [ $cliVersion != $Version ]; then
echo "Newest version of dotnet cli not installed, downloading and installing."
./scripts/install-dotnet.sh -Channel master -Version "$Version" -InstallDir "dotnetcli"
ret=$?
if [ $ret -ne 0 ]; then
echo "Failed to install latest dotnet.exe, exit code $ret, aborting build."
exit -1
fi
else
echo "Newest version of dotnet cli is already installed."
fi
fi
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_MULTILEVEL_LOOKUP=0
myFile="corefxlab.sln"
if [ "$Restore" = "true" ]; then
echo "Restoring all packages"
./$dotnetExePath restore $myFile /p:VersionSuffix="$BuildVersion"
ret=$?
if [ $ret -ne 0 ]; then
echo "Failed to restore packages."
exit -1
fi
fi
echo "Building solution $myFile..."
./$dotnetExePath build $myFile -c "$Configuration" /p:VersionSuffix="$BuildVersion" --no-restore /nologo
ret=$?
if [ $ret -ne 0 ]; then
echo "Failed to build solution $myFile"
exit -1
fi
errorsEncountered=0
declare -a projectsFailed
while read -r testFile;
do
echo "Building and running tests for project $testFile..."
./$dotnetExePath test "$testFile" -c "$Configuration" --no-build -- -notrait category=performance -notrait category=outerloop
ret=$?
if [ $ret -ne 0 ]; then
echo "Some tests failed in project $testFile"
projectsFailed[${#projectsFailed[@]}]="$testFile"
((errorsEncountered=errorsEncountered+1))
fi
done < <(find tests -name "*Tests*.csproj")
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
if [ $errorsEncountered -ne 0 ]; then
echo -e "${RED}** Build failed. $errorsEncountered projects failed to build or test. **${NC}"
for i in "${projectsFailed[@]}"
do
echo -e "${RED} $i${NC}"
done
else
echo -e "${GREEN}** Build succeeded. **${NC}"
fi
exit $errorsEncountered