-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild-docs.ps1
More file actions
75 lines (65 loc) · 2.25 KB
/
build-docs.ps1
File metadata and controls
75 lines (65 loc) · 2.25 KB
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
$ErrorActionPreference = 'Stop'
function Find-FileRegex {
param(
[Parameter(Mandatory = $true)][string]$Pattern,
[Parameter(Mandatory = $true)][string]$Path
)
if (Get-Command rg -ErrorAction SilentlyContinue) {
& rg -n -e $Pattern $Path
return
}
Select-String -Path $Path -Pattern $Pattern | ForEach-Object {
"{0}:{1}:{2}" -f $_.Path, $_.LineNumber, $_.Line.TrimEnd()
}
}
function Clear-DocsOutputs {
Get-ChildItem (Join-Path $PSScriptRoot 'src') -Filter '*.api.json' -Recurse -File |
Where-Object { $_.FullName.Replace('\', '/') -like '*/obj/Release/*' } |
Remove-Item -Force
$apiCache = Join-Path $PSScriptRoot 'site/.lunet/build/cache/api/dotnet'
$wwwRoot = Join-Path $PSScriptRoot 'site/.lunet/build/www'
foreach ($path in @($apiCache, $wwwRoot)) {
Remove-Item $path -Recurse -Force -ErrorAction SilentlyContinue
}
}
Push-Location $PSScriptRoot
try {
$lockDir = Join-Path $PSScriptRoot 'site/.lunet/.build-lock'
while ($true) {
if (Test-Path $lockDir) {
Start-Sleep -Seconds 1
continue
}
try {
New-Item -ItemType Directory -Path $lockDir -ErrorAction Stop | Out-Null
break
}
catch {
Start-Sleep -Seconds 1
}
}
dotnet tool restore
dotnet build (Join-Path $PSScriptRoot 'XamlToCSharpGenerator.CI.slnf') -c Release --nologo -m:1 /nodeReuse:false --disable-build-servers
Clear-DocsOutputs
Push-Location site
try {
$lunetLog = [System.IO.Path]::GetTempFileName()
try {
dotnet tool run lunet --stacktrace build 2>&1 | Tee-Object -FilePath $lunetLog
$lunetErrors = Find-FileRegex -Pattern 'ERR lunet|Error while building api dotnet|Unable to select the api dotnet output' -Path $lunetLog
if ($lunetErrors) {
throw "Lunet reported API/site build errors.`n$lunetErrors"
}
}
finally {
Remove-Item $lunetLog -Force -ErrorAction SilentlyContinue
}
}
finally {
Pop-Location
}
}
finally {
Remove-Item (Join-Path $PSScriptRoot 'site/.lunet/.build-lock') -Force -Recurse -ErrorAction SilentlyContinue
Pop-Location
}