Skip to content

Commit b4c8083

Browse files
committed
Added support for website wait functionality in build to make testing a bit more intuitive
Signed-off-by: David Söderlund <[email protected]>
1 parent 54a2631 commit b4c8083

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

jekyll.build.ps1

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
param(
33
[parameter()]$jekyllversion = '4',
44
[parameter()]$servecontainername = 'jekyll-serve',
5-
[parameter()][string]$postname = ''
5+
[parameter()][string]$postname = '',
6+
[switch]$wait
67
)
78
$rootdir = git rev-parse --show-toplevel
89
task proofread {
910
$learntospellyoudunce = @("kubernets", "kuberen", "oath", "serer", "challange")
1011
$spellingmisstakes = gci "$rootdir/docs/_posts/*.md" | % {
1112
gc $_ | Select-String -Pattern $learntospellyoudunce
1213
}
13-
if($spellingmisstakes) {
14+
if ($spellingmisstakes) {
1415
$spellingmisstakes
1516
throw 'learn to spell you dunce'
1617
}
@@ -46,15 +47,35 @@ task stop {
4647
}
4748

4849
task serve stop, remove, {
49-
if (test-path .\docs) {
50+
if (-not (test-path .\docs)) {
51+
throw "You cannot run what does not exist, run invokebuild new first!"
52+
}
53+
else {
5054
Push-Location $rootdir/docs
5155
#serve
5256
docker run -d --name $servecontainername --volume="$($PWD):/srv/jekyll" --volume="$PWD/vendor/bundle:/usr/local/bundle" --env JEKYLL_ENV=development -p 4000:4000 jekyll/jekyll:$jekyllversion jekyll serve --watch --drafts
5357

5458
Pop-Location
55-
}
56-
else {
57-
throw "You cannot run what does not exist, run invokebuild new first!"
59+
$tries = 15;
60+
while ($wait -and $tries -gt 0) {
61+
Start-Sleep 5
62+
try {
63+
$result = Invoke-WebRequest -Uri "http://localhost:4000"
64+
if ($result.StatusCode -eq 200) {
65+
Write-Host "Server is up"
66+
$tries = 0;
67+
break;
68+
}
69+
else {
70+
Throw ("Server is not up")
71+
}
72+
}
73+
catch {
74+
Write-Host "Server is not up"
75+
Start-Sleep 5;
76+
$tries--;
77+
}
78+
}
5879
}
5980
}
6081

0 commit comments

Comments
 (0)