Skip to content

Replace AppVeyor with GitHub Actions #1294

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 3 commits into from
Sep 17, 2023
Merged
Changes from 1 commit
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
Next Next commit
Fix generation of request examples for docs on linux/macOS; timeout i…
…nstead of hang when webserver does not start
  • Loading branch information
bkoelman committed Sep 17, 2023
commit 90a2879de223eb66d47fd5cceb4eb75a07105dab
44 changes: 28 additions & 16 deletions docs/generate-examples.ps1
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
#Requires -Version 7.3

# This script generates response documents for ./request-examples
# This script generates HTTP response files (*.json) for .ps1 files in ./request-examples

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

return $processId
return $webProcessId
}

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

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

if ($stopErrorMessage) {
throw "Failed to stop web server: $stopErrorMessage"
Expand All @@ -32,16 +32,28 @@ function Kill-WebServer {

function Start-WebServer {
Write-Output "Starting web server"
Start-Job -ScriptBlock { dotnet run --project ..\src\Examples\GettingStarted\GettingStarted.csproj } | Out-Null
$startTimeUtc = Get-Date -AsUTC
$job = Start-Job -ScriptBlock {
dotnet run --project ..\src\Examples\GettingStarted\GettingStarted.csproj --configuration Debug --property:TreatWarningsAsErrors=True --urls=http://0.0.0.0:14141
}

$webProcessId = $null
$timeout = [timespan]::FromSeconds(30)

Do {
Start-Sleep -Seconds 1
$hasTimedOut = ($(Get-Date -AsUTC) - $startTimeUtc) -gt $timeout
$webProcessId = Get-WebServer-ProcessId
} While ($webProcessId -eq $null)
} While ($webProcessId -eq $null -and -not $hasTimedOut)

if ($hasTimedOut) {
Write-Host "Failed to start web server, dumping output."
Receive-Job -Job $job
throw "Failed to start web server."
}
}

Kill-WebServer
Stop-WebServer
Start-WebServer

try {
Expand All @@ -55,10 +67,10 @@ try {
& $scriptFile.FullName > .\request-examples\$jsonFileName

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