Skip to content

Commit dfcf303

Browse files
authored
improve the hugo server building in CI (#347)
* improve the hugo server building in CI Signed-off-by: Rupam-It <mannarupam3@gmail.com> * Update hugo-build-status-check.yml Signed-off-by: Rupam Manna <111190901+Rupam-It@users.noreply.github.com> * remove the build status check as it is redudant Signed-off-by: Rupam-It <mannarupam3@gmail.com> * remove the line continue on error so that the workflow failed if the build failed Signed-off-by: Rupam-It <mannarupam3@gmail.com> * comment out manual run for github action Signed-off-by: Rupam-It <mannarupam3@gmail.com> --------- Signed-off-by: Rupam-It <mannarupam3@gmail.com> Signed-off-by: Rupam Manna <111190901+Rupam-It@users.noreply.github.com>
1 parent a5d4444 commit dfcf303

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

.github/workflows/hugo-build-status-check.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ name: Hugo Build and Status Check
55

66
# Trigger the workflow on push events to the main branch
77
on:
8+
# ucomment the following line if you want to run the workflow manually
9+
# workflow_dispatch:
810
push:
911
branches:
1012
- master
@@ -33,22 +35,28 @@ jobs:
3335
# Step to build the site
3436
- name: Build site
3537
run: hugo --minify
36-
# Capture output and error code
37-
continue-on-error: true
3838
id: build
3939

4040
# Step to start Hugo server in the background
4141
- name: Start Hugo server
4242
run: hugo server --minify --port=8888 &
4343

44-
# Check if build failed
45-
- name: Check build status
44+
# Step to verify that Hugo server started successfully
45+
- name: Verify Hugo server
4646
run: |
47-
if [ ${{ steps.build.outcome }} != 'success' ]; then
48-
echo "::error::Hugo build failed, blocking commit..."
47+
sleep 5 # Wait for a few seconds for the server to start
48+
if ! lsof -i:8888; then
49+
echo "::error::Hugo server failed to start!"
4950
exit 1
5051
fi
5152
52-
# Stop the Hugo server at the end of the workflow as is running in the background
53+
# Step to stop the Hugo server at the end of the workflow as it's running in the background
5354
- name: Stop Hugo server
54-
run: kill $(lsof -t -i:8888) || true
55+
run: |
56+
PID=$(lsof -t -i:8888)
57+
if [ -n "$PID" ]; then
58+
kill $PID
59+
echo "Hugo server stopped."
60+
else
61+
echo "Hugo server was not running."
62+
fi

0 commit comments

Comments
 (0)