forked from dotnet/docfx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
183 lines (159 loc) · 5.35 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
param(
[string] $configuration = "Release",
[switch] $raw = $false,
[switch] $prod = $false
)
################################################################################################
# Usage:
# Run build.ps1
# [-configuration Configuration]: Default to be Release
# [-raw]: If it's set, the build process will skip updating template
# [-prod]: If it's set, the build process will update version
################################################################################################
$ErrorActionPreference = 'Stop'
$scriptPath = $MyInvocation.MyCommand.Path
$scriptHome = Split-Path $scriptPath
function DotnetBuild {
param($folder)
if (Test-Path (Join-Path $folder.FullName "project.json"))
{
& dotnet build $folder.FullName -c $configuration -f net452
ProcessLastExitCode $lastexitcode "dotnet build $folder error"
}
}
function DotnetPublish {
param($folder)
if (Test-Path (Join-Path $folder.FullName "project.json"))
{
& dotnet publish $folder.FullName -c $configuration -f net452 -o target\$configuration\$folder
ProcessLastExitCode $lastexitcode "dotnet publish $folder error"
}
}
function DotnetPack {
param($folder)
if (Test-Path (Join-Path $folder.FullName "project.json"))
{
& dotnet pack $folder.FullName -c $configuration -o artifacts\$configuration
ProcessLastExitCode $lastexitcode "dotnet pack $folder error"
}
}
function ProcessLastExitCode {
param($exitCode, $msg)
if ($exitCode -ne 0)
{
Write-Error "$msg, exit code: $exitCode"
Pop-Location
Exit 1
}
}
Push-Location $scriptHome
# Check if dotnet cli exists globally
if ((Get-Command "dotnet" -ErrorAction SilentlyContinue) -eq $null)
{
Write-Host "dotnet CLI is not successfully configured."
Write-Host "Please follow https://www.microsoft.com/net/core to install .NET Core."
Pop-Location
Exit 1
}
# Check if nuget.exe exists
$nuget = "$env:LOCALAPPDATA\Nuget\Nuget.exe"
if (-not(Test-Path $nuget))
{
Write-Host "Downloading NuGet.exe..."
$ProgressPreference = 'SilentlyContinue'
[Net.WebRequest]::DefaultWebProxy.Credentials = [Net.CredentialCache]::DefaultCredentials
Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' -OutFile $nuget
}
if ($raw -eq $false)
{
& ".\UpdateTemplate.cmd"
ProcessLastExitCode $lastexitcode "Update templte error"
}
else
{
Write-Host "Skip updating template"
}
if ($prod -eq $true)
{
& ".\UpdateVersion.cmd"
ProcessLastExitCode $lastexitcode "Update version error"
}
# Restore package
Write-Host "Start to restore package"
foreach ($folder in @("src", "test", "tools"))
{
CD $folder
& dotnet restore
ProcessLastExitCode $lastexitcode "dotnet restore $folder error"
CD ..
}
# Build project
Write-Host "Start to build project"
foreach ($folder in (dir "src"))
{
DotnetBuild($folder)
}
# Publish project
Write-Host "Start to publish project"
foreach ($folder in (dir "src"))
{
DotnetPublish($folder)
}
# Run unit test cases
Write-Host "Start to run unit test"
foreach ($folder in (dir "test"))
{
if ((Test-Path (Join-Path $folder.FullName "project.json")) -and ($folder.Name -ne "Shared") -and ($folder.Name -ne "docfx.E2E.Tests"))
{
& dotnet test test\$folder
ProcessLastExitCode $lastexitcode "dotnet test $folder error"
}
}
# Build tools
Write-Host "Build tools"
foreach ($folder in (dir "tools"))
{
DotnetBuild($folder)
}
# Publish tools
Write-Host "Publish tools"
foreach ($folder in (dir "tools"))
{
DotnetPublish($folder)
}
# Pack artifacts
Write-Host "Publish artifacts"
foreach ($folder in (dir "src"))
{
DotnetPack($folder)
}
# Pack docfx.console
Copy-Item -Path "target\$configuration\docfx\*.dll" -Destination "src\nuspec\docfx.console\tools\"
Copy-Item -Path "target\$configuration\docfx\*.exe" -Destination "src\nuspec\docfx.console\tools\"
Copy-Item -Path "target\$configuration\docfx\*.exe.config" -Destination "src\nuspec\docfx.console\tools\"
$version = "1.0.0"
if (Test-Path "TEMP/version.txt")
{
$version = cat "TEMP/version.txt"
$version = $version.Substring(1)
}
& $nuget pack "src\nuspec\docfx.console\docfx.console.nuspec" -Version $version -OutputDirectory artifacts\$configuration
ProcessLastExitCode $lastexitcode "nuget pack docfx.console error"
# Pack azure tools
$null = New-Item -ItemType Directory -Force -Path "src\nuspec\AzureMarkdownRewriterTool\tools\"
Copy-Item -Path "target\$configuration\AzureMarkdownRewriterTool\*.dll" -Destination "src\nuspec\AzureMarkdownRewriterTool\tools\"
Copy-Item -Path "target\$configuration\AzureMarkdownRewriterTool\*.exe" -Destination "src\nuspec\AzureMarkdownRewriterTool\tools\"
Copy-Item -Path "target\$configuration\AzureMarkdownRewriterTool\*.exe.config" -Destination "src\nuspec\AzureMarkdownRewriterTool\tools\"
# Build VscPreviewExe
src\VscPreviewExtension\buildVscPreviewExe.cmd -c $configuration
ProcessLastExitCode $lastexitcode "build VscPreviewExe error"
$version = "1.0.0"
if (Test-Path "TEMP/version.txt")
{
$version = cat "TEMP/version.txt"
$version = $version.Substring(1)
}
& $nuget pack "src\nuspec\AzureMarkdownRewriterTool\AzureMarkdownRewriterTool.nuspec" -Version $version -OutputDirectory artifacts\$configuration
ProcessLastExitCode $lastexitcode "nuget pack AzureMarkdownRewriterTool error"
Write-Host "Build completed."
Pop-Location