-
Notifications
You must be signed in to change notification settings - Fork 46
/
build.ps1
109 lines (77 loc) · 2.6 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
param (
[ValidateSet("debug", "release")]
[string]$Configuration = 'release'
)
$RepoRoot = $PSScriptRoot
$ArtifactsDir = Join-Path $RepoRoot 'artifacts'
$CLIRoot = Join-Path $RepoRoot 'cli'
$DotNetExe = Join-Path $CLIRoot 'dotnet.exe'
$NuGetExe = Join-Path $RepoRoot '.nuget\nuget.exe'
if (Test-Path $ArtifactsDir)
{
rm -r $ArtifactsDir -Force | Out-Null
}
Function Error-Log {
param(
[string]$ErrorMessage,
[switch]$Fatal)
if (-not $Fatal) {
Write-Error "[$(Trace-Time)]`t$ErrorMessage"
}
else {
Write-Error "[$(Trace-Time)]`t[FATAL] $ErrorMessage" -ErrorAction Stop
}
}
Function Trace-Time() {
$currentTime = Get-Date
$lastTime = $Global:LastTraceTime
$Global:LastTraceTime = $currentTime
"{0:HH:mm:ss} +{1:F0}" -f $currentTime, ($currentTime - $lastTime).TotalSeconds
}
$Global:LastTraceTime = Get-Date
New-Item -ItemType Directory -Force -Path $CLIRoot | Out-Null
New-Item -ItemType Directory -Force -Path $ArtifactsDir | Out-Null
if (-not (Test-Path $NuGetExe))
{
wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile $NuGetExe
}
& $NuGetExe restore (Join-Path $RepoRoot '.nuget\packages.config') -SolutionDirectory $RepoRoot
# install dotnet CLI
$env:DOTNET_HOME=$CLIRoot
$installDotnet = Join-Path $CLIRoot "install.ps1"
$env:DOTNET_INSTALL_DIR=$NuGetClientRoot
New-Item -ItemType Directory -Force -Path $CLIRoot
wget https://raw.githubusercontent.com/dotnet/cli/5a77b03f36904670faa36c0d294237ec8841e8f1/scripts/obtain/dotnet-install.ps1 -OutFile cli/install.ps1
& cli/install.ps1 -Channel beta -i $CLIRoot -Version 1.0.0-preview1-002702
if (-not (Test-Path $DotNetExe)) {
Write-Host "Unable to find dotnet.exe. The CLI install may have failed."
Exit 1
}
# Display build info
& $DotNetExe --info
# download nuget packages
& $DotNetExe restore $RepoRoot
# Run tests
$TestDir = Join-Path $RepoRoot test\json-ld.net.tests
pushd $TestDir
# core clr
& $DotNetExe test --configuration $Configuration -f netcoreapp1.0
if (-not $?) {
popd
Error-Log "Tests failed!!!"
Exit 1
}
# net46
& $DotNetExe build --configuration $Configuration -f net46 --runtime win7-x64
$xunit = Join-Path $RepoRoot packages\xunit.runner.console.2.1.0\tools\xunit.console.exe
& $xunit bin\$Configuration\net46\win7-x64\json-ld.net.tests.dll -html (Join-Path $ArtifactsDir "testresults.html")
if (-not $?) {
popd
Write-Host "Tests failed!!!"
Exit 1
}
popd
# Pack
Write-Host "Creating nupkg"
& $DotNetExe pack (Join-Path $RepoRoot src\json-ld.net) --configuration $Configuration --output $ArtifactsDir
Write-Host "Success!"