Skip to content

Fixed cibuild: poll for started webserver instead of fixed sleep #928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@ before_build:
if (-Not $env:APPVEYOR_PULL_REQUEST_TITLE) {
# https://dotnet.github.io/docfx/tutorial/docfx_getting_started.html
git checkout $env:APPVEYOR_REPO_BRANCH -q
choco install docfx -y
}
choco install docfx -y

after_build:
- pwsh: |
CD ./docs
& ./generate-examples.ps1
& docfx docfx.json
if ($lastexitcode -ne 0) {
throw [System.Exception] "docfx build failed with exit code $lastexitcode."
}

git config --global credential.helper store
Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:ACCESS_TOKEN):[email protected]`n"
git config --global user.email "[email protected]"
git config --global user.name "Jared Nance"
git config --global core.autocrlf false
git config --global core.safecrlf false
git clone https://github.com/json-api-dotnet/JsonApiDotNetCore.git -b gh-pages origin_site -q
Copy-Item origin_site/.git _site -recurse
Copy-Item CNAME _site/CNAME
Copy-Item home/*.html _site/
Copy-Item home/*.ico _site/
Copy-Item -Recurse home/assets/* _site/styles/
CD _site
git add -A 2>&1
git commit -m "CI Updates" -q
if (-Not $env:APPVEYOR_PULL_REQUEST_TITLE) {
CD ./docs
& ./generate-examples.ps1
& docfx docfx.json
if ($lastexitcode -ne 0) {
throw [System.Exception] "docfx build failed with exit code $lastexitcode."
}

git config --global credential.helper store
Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:ACCESS_TOKEN):[email protected]`n"
git config --global user.email "[email protected]"
git config --global user.name "Jared Nance"
git config --global core.autocrlf false
git config --global core.safecrlf false
git clone https://github.com/json-api-dotnet/JsonApiDotNetCore.git -b gh-pages origin_site -q
Copy-Item origin_site/.git _site -recurse
Copy-Item CNAME _site/CNAME
Copy-Item home/*.html _site/
Copy-Item home/*.ico _site/
Copy-Item -Recurse home/assets/* _site/styles/
CD _site
git add -A 2>&1
git commit -m "CI Updates" -q
git push origin gh-pages -q
echo "Documentation updated successfully."
}
Expand Down
28 changes: 20 additions & 8 deletions docs/generate-examples.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,46 @@

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

function Kill-WebServer {
function Get-WebServer-ProcessId {
$processId = $null
if ($IsMacOs || $IsLinux) {
$processId = $(lsof -ti:8080)
$processId = $(lsof -ti:14141)
}
elseif ($IsWindows) {
$processId = $(Get-NetTCPConnection -LocalPort 14141 -ErrorAction SilentlyContinue).OwningProcess
}
else {
throw [System.Exception] "Unsupported operating system."
}

return $processId
}

function Kill-WebServer {
$processId = Get-WebServer-ProcessId

if ($processId -ne $null) {
Write-Output "Stopping web server"
Get-Process -Id $processId | Stop-Process
}

}

function Start-Webserver {
function Start-WebServer {
Write-Output "Starting web server"
Start-Job -ScriptBlock { dotnet run --project ..\src\Examples\GettingStarted\GettingStarted.csproj } | Out-Null

$webProcessId = $null
Do {
Start-Sleep -Seconds 1
$webProcessId = Get-WebServer-ProcessId
} While ($webProcessId -eq $null)
}

Kill-WebServer
Start-Webserver
Start-WebServer

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

Start-Sleep -Seconds 10

$scriptFiles = Get-ChildItem .\request-examples\*.ps1
foreach ($scriptFile in $scriptFiles) {
$jsonFileName = [System.IO.Path]::GetFileNameWithoutExtension($scriptFile.Name) + "_Response.json"
Expand All @@ -38,7 +50,7 @@ foreach ($scriptFile in $scriptFiles) {
& $scriptFile.FullName > .\request-examples\$jsonFileName

if ($LastExitCode -ne 0) {
throw [System.Exception] "Example request from '$($scriptFile.Name)' failed."
throw [System.Exception] "Example request from '$($scriptFile.Name)' failed with exit code $LastExitCode."
}
}

Expand Down