forked from Azure-Samples/azure-iot-samples-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
161 lines (125 loc) · 5.3 KB
/
build.ps1
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
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
<#
.SYNOPSIS
Microsoft Azure IoT SDK .NET Samples build script.
.DESCRIPTION
Builds Azure IoT SDK samples.
Parameters:
-clean: Runs dotnet clean. Use `git clean -xdf` if this is not sufficient.
-build: Builds the project.
-run: Runs the sample. The required environmental variables need to be set beforehand.
-configuration {Debug|Release}
-verbosity: Sets the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].
.EXAMPLE
.\build
Builds a Debug version of the SDK.
.EXAMPLE
.\build -config Release
Builds a Release version of the SDK.
.EXAMPLE
.\build -clean
.LINK
https://github.com/Azure-Samples/azure-iot-samples-csharp
https://github.com/azure/azure-iot-sdk-csharp
#>
Param(
[switch] $clean,
[switch] $build,
[switch] $run,
[string] $configuration = "Debug",
[string] $verbosity = "q"
)
Function IsWindowsDevelopmentBox()
{
return ([Environment]::OSVersion.Platform -eq [System.PlatformID]::Win32NT)
}
Function BuildProject($path, $message) {
$label = "BUILD: --- $message $configuration ---"
Write-Host
Write-Host -ForegroundColor Cyan $label
cd (Join-Path $rootDir $path)
if ($clean) {
& dotnet clean --verbosity $verbosity --configuration $configuration
if ($LASTEXITCODE -ne 0) {
throw "Clean failed: $label"
}
}
& dotnet build --verbosity $verbosity --configuration $configuration
if ($LASTEXITCODE -ne 0) {
throw "Build failed: $label"
}
}
Function RunApp($path, $message, $args) {
$label = "RUN: --- $message $configuration ($args)---"
Write-Host
Write-Host -ForegroundColor Cyan $label
cd (Join-Path $rootDir $path)
& dotnet run $args
if ($LASTEXITCODE -ne 0) {
throw "Tests failed: $label"
}
}
$rootDir = (Get-Item -Path ".\" -Verbose).FullName
$startTime = Get-Date
$buildFailed = $true
$errorMessage = ""
try {
if ($build)
{
BuildProject iot-hub\Samples\device "IoTHub Device Samples"
BuildProject iot-hub\Samples\module "IoTHub Module Samples"
BuildProject iot-hub\Samples\service "IoTHub Service Samples"
BuildProject iot-hub\Quickstarts "IoTHub Device Quickstarts"
BuildProject iot-hub\Tutorials\Routing "IoTHub Tutorials - Routing"
BuildProject provisioning\Samples\device "Provisioning Device Samples"
BuildProject provisioning\Samples\service "Provisioning Service Samples"
BuildProject security\Samples "Security Samples"
}
if ($run)
{
# Run cleanup first so the samples don't get overloaded with old device instances
RunApp provisioning\Samples\service\CleanupEnrollmentsSample "Provisioning\Service\CleanupEnrollmentsSample"
RunApp iot-hub\Samples\service\CleanUpDevicesSample "IoTHub\Service\CleanUpDevicesSample"
RunApp iot-hub\Samples\device\FileUploadSample "IoTHub\Device\FileUploadSample"
RunApp iot-hub\Samples\device\KeysRolloverSample "IoTHub\Device\KeysRolloverSample"
RunApp iot-hub\Samples\device\MessageSample "IoTHub\Device\MessageSample"
RunApp iot-hub\Samples\device\MethodSample "IoTHub\Device\MethodSample"
RunApp iot-hub\Samples\device\TwinSample "IoTHub\Device\TwinSample"
RunApp iot-hub\Samples\module\MessageSample "IoTHub\Module\MessageSample"
RunApp iot-hub\Samples\module\TwinSample "IoTHub\Module\TwinSample"
RunApp iot-hub\Samples\service\AutomaticDeviceManagementSample "IoTHub\Service\AutomaticDeviceManagementSample"
RunApp iot-hub\Samples\service\JobsSample "IoTHub\Service\JobsSample"
RunApp iot-hub\Samples\service\RegistryManagerSample "IoTHub\Service\RegistryManagerSample"
$deviceId = ($Env:IOTHUB_DEVICE_CONN_STRING.Split(';') | where {$_ -like "DeviceId*"}).Split("=")[1]
Write-Warning $deviceId
RunApp iot-hub\Samples\service\ServiceClientSample "IoTHub\Service\ServiceClientSample" - $deviceId
# TODO #11: Modify Provisioning\device samples to run unattended.
RunApp provisioning\Samples\service\BulkOperationSample "Provisioning\Service\BulkOperationSample"
# TODO #11 :RunApp provisioning\Samples\service\EnrollmentGroupSample "Provisioning\Service\EnrollmentGroupSample"
RunApp provisioning\Samples\service\EnrollmentSample "Provisioning\Service\EnrollmentSample"
# IoT Hub devices and DPS enrollments cleanup
RunApp provisioning\Samples\service\CleanupEnrollmentsSample "Provisioning\Service\CleanupEnrollmentsSample"
RunApp iot-hub\Samples\service\CleanUpDevicesSample "IoTHub\Service\CleanUpDevicesSample"
}
$buildFailed = $false
}
catch [Exception]{
$buildFailed = $true
$errorMessage = $Error[0]
}
finally {
cd $rootDir
$endTime = Get-Date
}
Write-Host
Write-Host
Write-Host ("Time Elapsed {0:c}" -f ($endTime - $startTime))
if ($buildFailed) {
Write-Host -ForegroundColor Red "Build failed ($errorMessage)"
exit 1
}
else {
Write-Host -ForegroundColor Green "Build succeeded."
exit 0
}