forked from Azure/device-simulation-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·124 lines (104 loc) · 3.11 KB
/
build
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
#!/usr/bin/env bash -e
# Usage:
# Build the project in the local environment: ./scripts/build
# Build the project inside a Docker container: ./scripts/build -s
# Build the project inside a Docker container: ./scripts/build --in-sandbox
# Debug|Release
CONFIGURATION=Release
APP_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )/"
source "$APP_HOME/scripts/.functions.sh"
# Folder where PCS sandboxes cache data. Reuse the same folder to speed up the
# sandbox and to save disk space.
# Use PCS_CACHE="$APP_HOME/.cache" to cache inside the project folder
PCS_CACHE="/tmp/azure/iotpcs/.cache"
compile() {
check_dependency_dotnet
cd $APP_HOME
./scripts/env-vars-check
header "Downloading dependencies..."
dotnet restore
header "Compiling code..."
dotnet build --configuration $CONFIGURATION
}
run_tests() {
check_dependency_dotnet
cd $APP_HOME
header "Running tests..."
PROJECTS=$(dotnet sln list | grep 'csproj$' | grep '\.Test')
for PROJ in $PROJECTS; do
echo "-- $PROJ"
dotnet test --configuration $CONFIGURATION $PROJ
done
}
json_lint() {
cd $APP_HOME
set +e
TEST=$(which jsonlint)
set -e
if [[ ! -z "$TEST" ]]; then
for foo in Services/data/devicemodels/*.json; do
set +e
TEST=$(cat $foo | jsonlint -s 2> /dev/null)
if [[ -z "$TEST" ]]; then
error "$foo:"
cat $foo | jsonlint -s
exit 1
fi
set -e
done
fi
}
js_lint() {
cd $APP_HOME
set +e
TEST=$(which jslint4java)
set -e
if [[ ! -z "$TEST" ]]; then
for foo in Services/data/devicemodels/scripts/*.js; do
jslint4java $foo
done
fi
}
setup_sandbox_cache() {
mkdir -p $PCS_CACHE/sandbox/.config
mkdir -p $PCS_CACHE/sandbox/.dotnet
mkdir -p $PCS_CACHE/sandbox/.nuget
echo "Note: caching build files in $PCS_CACHE"
}
build_in_sandbox() {
setup_sandbox_cache
cd $APP_HOME
# In Windows this script should use docker.exe, in which case
# the parameters syntax is different, e.g. volumes path
# (i.e. C:\path\path\... vs /c/path/path/...).
#
# Note that this script is also used for the git precommit hook.
set +e
IS_WINDOWS=$(which cmd.exe)
set -e
if [[ -z "$IS_WINDOWS" ]]; then
check_dependency_docker
docker run -it \
-e PCS_IOTHUB_CONNSTRING \
-v "$PCS_CACHE/sandbox/.config:/root/.config" \
-v "$PCS_CACHE/sandbox/.dotnet:/root/.dotnet" \
-v "$PCS_CACHE/sandbox/.nuget:/root/.nuget" \
-v "$APP_HOME:/opt/code" \
azureiotpcs/code-builder-dotnet:1.0-dotnetcore /opt/code/scripts/build
else
# Note 'winpty' is required to provide a TTY to Docker
echo "Launching cmd.exe /c winpty ..."
cmd.exe /c "winpty .\scripts\build.cmd --in-sandbox"
fi
}
if [[ "$1" == "--in-sandbox" || "$1" == "-s" ]]; then
build_in_sandbox
else
# workaround for https://github.com/dotnet/cli/issues/3995
unset home
json_lint
js_lint
compile
run_tests
fi
set +e