-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-run.ps1
162 lines (133 loc) · 4.24 KB
/
build-run.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
162
$ErrorActionPreference = "Stop"
function DownloadWithRetry([string] $url, [string] $downloadLocation, [int] $retries)
{
while($true)
{
try
{
Invoke-WebRequest $url -OutFile $downloadLocation
break
}
catch
{
$exceptionMessage = $_.Exception.Message
Write-Host "Failed to download '$url': $exceptionMessage"
if ($retries -gt 0) {
$retries--
Write-Host "Waiting 10 seconds before retrying. Retries left: $retries"
Start-Sleep -Seconds 10
}
else
{
$exception = $_.Exception
throw $exception
}
}
}
}
$repoFolder = $PSScriptRoot
$env:REPO_FOLDER = $repoFolder
$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/2.0.0-preview2.zip"
if ($env:KOREBUILD_ZIP)
{
$koreBuildZip=$env:KOREBUILD_ZIP
}
$buildFolder = ".build"
if (!(Test-Path $buildFolder)) {
Write-Host "Downloading KoreBuild from $koreBuildZip"
$tempFolder=$env:TEMP + "\KoreBuild-" + [guid]::NewGuid()
New-Item -Path "$tempFolder" -Type directory | Out-Null
$localZipFile="$tempFolder\korebuild.zip"
DownloadWithRetry -url $koreBuildZip -downloadLocation $localZipFile -retries 6
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($localZipFile, $tempFolder)
New-Item -Path "$buildFolder" -Type directory | Out-Null
copy-item "$tempFolder\**\build\*" $buildFolder -Recurse
# Cleanup
if (Test-Path $tempFolder) {
Remove-Item -Recurse -Force $tempFolder
}
}
$dotnetArch = 'x64'
$dotnetChannel = "preview"
$dotnetVersion = "2.0.0-preview2-006484"
$dotnetLocalInstallFolder = $env:DOTNET_INSTALL_DIR
if (!$dotnetLocalInstallFolder)
{
$dotnetLocalInstallFolder = "$env:LOCALAPPDATA\Microsoft\dotnet\"
}
function InstallSharedRuntime([string] $version, [string] $channel)
{
$sharedRuntimePath = [IO.Path]::Combine($dotnetLocalInstallFolder, 'shared', 'Microsoft.NETCore.App', $version)
# Avoid redownloading the CLI if it's already installed.
if (!(Test-Path $sharedRuntimePath))
{
& "$buildFolder\dotnet\dotnet-install.ps1" -Channel $channel `
-SharedRuntime `
-Version $version `
-Architecture $dotnetArch `
-InstallDir $dotnetLocalInstallFolder
}
}
# Sometimes, MyGet re-uses a build server, clean SDK before attempting to install
if ($env:BuildRunner -eq "MyGet"){
Remove-Item -Force -Recurse $dotnetLocalInstallFolder
}
& "$buildFolder\dotnet\dotnet-install.ps1" -Channel $dotnetChannel -Version $dotnetVersion -Architecture $dotnetArch
InstallSharedRuntime -version "1.1.2" -channel "release/1.1.0"
dotnet --info
##########################
# BEGIN REPOSITORY TESTS
##########################
# restore
cd "$repoFolder"
dotnet restore
if ($LASTEXITCODE -ne 0){
exit $LASTEXITCODE;
}
# build to verify no build errors
cd (Join-Path $repoFolder (Join-Path "src" "EFCore.MySql"))
dotnet build -c Release
if ($LASTEXITCODE -ne 0){
exit $LASTEXITCODE;
}
# run unit tests
cd (Join-Path $repoFolder (Join-Path "test" "EFCore.MySql.Tests"))
dotnet test -c Release
if ($LASTEXITCODE -ne 0){
exit $LASTEXITCODE;
}
# run functional tests if not on MyGet
if ($env:BuildRunner -ne "MyGet"){
cd (Join-Path $repoFolder (Join-Path "test" "EFCore.MySql.FunctionalTests"))
cp config.json.example config.json
echo "Building Migrations"
scripts\rebuild.ps1
echo "Test applying migrations"
dotnet run -c Release testMigrate
if ($LASTEXITCODE -ne 0){
exit $LASTEXITCODE;
}
echo "Test with EF_BATCH_SIZE=1"
dotnet test -c Release
if ($LASTEXITCODE -ne 0){
exit $LASTEXITCODE;
}
echo "Test with EF_BATCH_SIZE=10"
$env:EF_BATCH_SIZE = 10
dotnet test -c Release
if ($LASTEXITCODE -ne 0){
exit $LASTEXITCODE;
}
}
##########################
# END REPOSITORY TESTS
##########################
# MyGet expects nuget packages to be build
cd (Join-Path $repoFolder (Join-Path "src" "EFCore.MySql"))
if ($env:BuildRunner -eq "MyGet"){
dotnet pack -c Release
if ($LASTEXITCODE -ne 0){
exit $LASTEXITCODE;
}
}