-
Notifications
You must be signed in to change notification settings - Fork 321
/
Test-Docs.ps1
151 lines (129 loc) · 4.95 KB
/
Test-Docs.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
Param(
[switch]$cleanUp,
[string]$file
)
$useNuGetPackage = $env:USE_NUGET_PACKAGE
$apiDoctorNuGetVersion = $env:API_DOCTOR_NUGET_VERSION
$apiDoctorGitRepoUrl = $env:API_DOCTOR_GIT_REPO_URL
$apiDoctorGitBranch = $env:API_DOCTOR_GIT_BRANCH
$docsRepoPath = (Get-Location).Path
$docsSubPath = $env:DOCS_SUB_PATH
$downloadedApiDoctor = $false
$downloadedNuGet = $false
if ($useNuGetPackage -eq $true) {
Write-Host "API Doctor NuGet Version: ", $apiDoctorNuGetVersion
}
else {
Write-Host "API Doctor Git Repo:"
Write-Host "- URL: $apiDoctorGitRepoUrl"
Write-Host "- Branch: $apiDoctorGitBranch"
}
Write-Host "Repository Location: ", $docsRepoPath
Write-Host "Docs Subpath: ", $docsSubPath
# Check if API Doctor source has been set
if ($useNuGetPackage -eq $true -and [string]::IsNullOrWhiteSpace($apiDoctorNuGetVersion)) {
Write-Host "API Doctor NuGet package version has not been set. Aborting..."
exit 1
}
elseif ($useNuGetPackage -eq $false -and [string]::IsNullOrWhiteSpace($apiDoctorGitRepoUrl)) {
Write-Host "API Doctor Git Repo URL has not been set. Aborting..."
exit 1
}
# Check if docs subpath has been set
if ([string]::IsNullOrWhiteSpace($docsSubPath)) {
Write-Host "Docs subpath has not been set. Aborting..."
exit 1
}
# Get NuGet
$nugetPath = $null
if (Get-Command "nuget.exe" -ErrorAction SilentlyContinue) {
# Use the existing nuget.exe from the path
$nugetPath = (Get-Command "nuget.exe").Source
}
else {
# Download nuget.exe from the nuget server if required
$nugetPath = Join-Path $docsRepoPath -ChildPath "nuget.exe"
$nugetExists = Test-Path $nugetPath
if ($nugetExists -eq $false) {
Write-Host "nuget.exe not found. Downloading from dist.nuget.org"
Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile $nugetPath
}
$downloadedNuGet = $true
}
# Check for API Doctor executable in path
$apidoc = $null
if (Get-Command "apidoc.exe" -ErrorAction SilentlyContinue) {
$apidoc = (Get-Command "apidoc.exe").Source
}
else {
$apidocPath = Join-Path $docsRepoPath -ChildPath "apidoctor"
New-Item -ItemType Directory -Force -Path $apidocPath
if ($useNuGetPackage -eq $true) {
# Install API Doctor from NuGet
Write-Host "Running nuget.exe from ", $nugetPath
$nugetParams = "install", "ApiDoctor", "-Version", $apiDoctorNuGetVersion, "-OutputDirectory", $apidocPath, "-NonInteractive", "-DisableParallelProcessing"
& $nugetPath $nugetParams
if ($LastExitCode -ne 0) {
# NuGet error, so we can't proceed
Write-Host "Error installing API Doctor from NuGet. Aborting..."
Remove-Item $nugetPath
exit $LastExitCode
}
}
else {
# Default to 'master' branch of API Doctor if not set
if([string]::IsNullOrWhiteSpace($apiDoctorGitBranch)){
$apiDoctorGitBranch = "master"
Write-Host "API Doctor branch has not been set, defaulting to 'master' branch."
}
# Download API Doctor from GitHub
Write-Host "Cloning API Doctor repository from GitHub"
Write-Host "`tRemote URL: $apiDoctorGitRepoUrl"
Write-Host "`tBranch: $apiDoctorGitBranch"
& git clone -b $apiDoctorGitBranch $apiDoctorGitRepoUrl --recurse-submodules "$apidocPath\SourceCode"
$downloadedApiDoctor = $true
$nugetParams = "restore", "$apidocPath\SourceCode"
& $nugetPath $nugetParams
# Build API Doctor
Install-Module -Name Invoke-MsBuild -Scope CurrentUser -Force
Write-Host "`r`nBuilding API Doctor..."
Invoke-MsBuild -Path "$apidocPath\SourceCode\ApiDoctor.sln" -MsBuildParameters "/t:Rebuild /p:Configuration=Release /p:OutputPath=$apidocPath\ApiDoctor\tools"
# Delete existing API Doctor source code
Remove-Item $apidocPath\SourceCode -Force -Recurse -ErrorAction SilentlyContinue
}
# Get the path to the API Doctor exe
$pkgfolder = Get-ChildItem -LiteralPath $apidocPath -Directory | Where-Object {$_.name -match "ApiDoctor"}
$apidoc = [System.IO.Path]::Combine($apidocPath, $pkgfolder.Name, "tools\apidoc.exe")
$downloadedApiDoctor = $true
}
# Check if the autogenerated folders still exist and raise an error if they do
if(( Test-Path '.\doc-stubs\' -PathType Container) -or ( Test-Path '.\changelog-stubs\' -PathType Container)){
Write-Host "Ensure that the doc-stubs and changelog-stubs folders have been deleted. Aborting..."
exit 1
}
$lastResultCode = 0
# Run validation at the root of the repository
$appVeyorUrl = $env:APPVEYOR_API_URL
$fullPath = Join-Path $docsRepoPath -ChildPath $docsSubPath
$params = "check-all", "--path", $fullPath, "--ignore-warnings"
if ($appVeyorUrl -ne $null)
{
$params = $params += "--appveyor-url", $appVeyorUrl
}
& $apidoc $params
if ($LastExitCode -ne 0) {
$lastResultCode = $LastExitCode
}
# Clean up the stuff we downloaded
if ($cleanUp -eq $true) {
if ($downloadedNuGet -eq $true) {
Remove-Item $nugetPath
}
if ($downloadedApiDoctor -eq $true) {
Remove-Item $apidocPath -Recurse -Force
}
}
if ($lastResultCode -ne 0) {
Write-Host "Errors were detected. This build failed."
exit $lastResultCode
}