forked from abdelbahgat/microsoft-graph-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test-Docs.ps1
84 lines (71 loc) · 2.5 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
Param(
[switch]$cleanUp,
[string]$file
)
$repoPath = (Get-Location).Path
$downloadedApiDoctor = $false
$downloadedNuGet = $false
Write-Host "Repository location: ", $repoPath
# Check for ApiDoctor in path
$apidoc = $null
if (Get-Command "apidoc.exe" -ErrorAction SilentlyContinue) {
$apidoc = (Get-Command "apidoc.exe").Source
} else {
$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 $repoPath -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
}
$packagesPath = Join-Path $repoPath -ChildPath "apidoctor"
$result = New-Item -ItemType Directory -Force -Path $packagesPath
# install apidoctor from nuget
Write-Host "Running nuget.exe from ", $nugetPath
$nugetParams = "install", "ApiDoctor", "-OutputDirectory", $packagesPath, "-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
}
# get the path to the Api Doctor exe
$pkgfolder = Get-ChildItem -LiteralPath $packagesPath -Directory | Where-Object {$_.name -match "ApiDoctor"}
$apidoc = [System.IO.Path]::Combine($packagesPath, $pkgfolder.Name, "tools\apidoc.exe")
$downloadedApiDoctor = $true
}
$lastResultCode = 0
# run validation at the root of the repository
$appVeyorUrl = $env:APPVEYOR_API_URL
$parms = "check-all", "--path", $repoPath
if ($appVeyorUrl -ne $null)
{
$parms = $parms += "--appveyor-url", $appVeyorUrl
}
& $apidoc $parms
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 $packagesPath -Recurse
}
}
if ($lastResultCode -ne 0) {
Write-Host "Errors were detected. This build failed."
exit $lastResultCode
}