Skip to content

Commit 0074423

Browse files
author
Bart Koelman
committed
The cibuild was failing on documentation example generation. We had a fixed sleep of 10 seconds after starting the webserver, which turned out to be insufficient.
Switched to polling with 1 second interval for webserver to become online. Also changed to run this during PR build (without push), so we'll know in advance if docs generation breaks. Fixed invalid port number on mac/linux builds.
1 parent e756f6a commit 0074423

File tree

2 files changed

+43
-31
lines changed

2 files changed

+43
-31
lines changed

Diff for: appveyor.yml

+23-23
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,34 @@ before_build:
1313
if (-Not $env:APPVEYOR_PULL_REQUEST_TITLE) {
1414
# https://dotnet.github.io/docfx/tutorial/docfx_getting_started.html
1515
git checkout $env:APPVEYOR_REPO_BRANCH -q
16-
choco install docfx -y
1716
}
17+
choco install docfx -y
1818
1919
after_build:
2020
- pwsh: |
21+
CD ./docs
22+
& ./generate-examples.ps1
23+
& docfx docfx.json
24+
if ($lastexitcode -ne 0) {
25+
throw [System.Exception] "docfx build failed with exit code $lastexitcode."
26+
}
27+
28+
git config --global credential.helper store
29+
Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:ACCESS_TOKEN):[email protected]`n"
30+
git config --global user.email "[email protected]"
31+
git config --global user.name "Jared Nance"
32+
git config --global core.autocrlf false
33+
git config --global core.safecrlf false
34+
git clone https://github.com/json-api-dotnet/JsonApiDotNetCore.git -b gh-pages origin_site -q
35+
Copy-Item origin_site/.git _site -recurse
36+
Copy-Item CNAME _site/CNAME
37+
Copy-Item home/*.html _site/
38+
Copy-Item home/*.ico _site/
39+
Copy-Item -Recurse home/assets/* _site/styles/
40+
CD _site
41+
git add -A 2>&1
42+
git commit -m "CI Updates" -q
2143
if (-Not $env:APPVEYOR_PULL_REQUEST_TITLE) {
22-
CD ./docs
23-
& ./generate-examples.ps1
24-
& docfx docfx.json
25-
if ($lastexitcode -ne 0) {
26-
throw [System.Exception] "docfx build failed with exit code $lastexitcode."
27-
}
28-
29-
git config --global credential.helper store
30-
Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:ACCESS_TOKEN):[email protected]`n"
31-
git config --global user.email "[email protected]"
32-
git config --global user.name "Jared Nance"
33-
git config --global core.autocrlf false
34-
git config --global core.safecrlf false
35-
git clone https://github.com/json-api-dotnet/JsonApiDotNetCore.git -b gh-pages origin_site -q
36-
Copy-Item origin_site/.git _site -recurse
37-
Copy-Item CNAME _site/CNAME
38-
Copy-Item home/*.html _site/
39-
Copy-Item home/*.ico _site/
40-
Copy-Item -Recurse home/assets/* _site/styles/
41-
CD _site
42-
git add -A 2>&1
43-
git commit -m "CI Updates" -q
4444
git push origin gh-pages -q
4545
echo "Documentation updated successfully."
4646
}

Diff for: docs/generate-examples.ps1

+20-8
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,46 @@
22

33
# This script generates response documents for ./request-examples
44

5-
function Kill-WebServer {
5+
function Get-WebServer-ProcessId {
66
$processId = $null
77
if ($IsMacOs || $IsLinux) {
8-
$processId = $(lsof -ti:8080)
8+
$processId = $(lsof -ti:14141)
99
}
1010
elseif ($IsWindows) {
1111
$processId = $(Get-NetTCPConnection -LocalPort 14141 -ErrorAction SilentlyContinue).OwningProcess
1212
}
13+
else {
14+
throw [System.Exception] "Unsupported operating system."
15+
}
16+
17+
return $processId
18+
}
19+
20+
function Kill-WebServer {
21+
$processId = Get-WebServer-ProcessId
1322

1423
if ($processId -ne $null) {
1524
Write-Output "Stopping web server"
1625
Get-Process -Id $processId | Stop-Process
1726
}
18-
1927
}
2028

21-
function Start-Webserver {
29+
function Start-WebServer {
2230
Write-Output "Starting web server"
2331
Start-Job -ScriptBlock { dotnet run --project ..\src\Examples\GettingStarted\GettingStarted.csproj } | Out-Null
32+
33+
$webProcessId = $null
34+
Do {
35+
Start-Sleep -Seconds 1
36+
$webProcessId = Get-WebServer-ProcessId
37+
} While ($webProcessId -eq $null)
2438
}
2539

2640
Kill-WebServer
27-
Start-Webserver
41+
Start-WebServer
2842

2943
Remove-Item -Force -Path .\request-examples\*.json
3044

31-
Start-Sleep -Seconds 10
32-
3345
$scriptFiles = Get-ChildItem .\request-examples\*.ps1
3446
foreach ($scriptFile in $scriptFiles) {
3547
$jsonFileName = [System.IO.Path]::GetFileNameWithoutExtension($scriptFile.Name) + "_Response.json"
@@ -38,7 +50,7 @@ foreach ($scriptFile in $scriptFiles) {
3850
& $scriptFile.FullName > .\request-examples\$jsonFileName
3951

4052
if ($LastExitCode -ne 0) {
41-
throw [System.Exception] "Example request from '$($scriptFile.Name)' failed."
53+
throw [System.Exception] "Example request from '$($scriptFile.Name)' failed with exit code $LastExitCode."
4254
}
4355
}
4456

0 commit comments

Comments
 (0)