From fda81ac9fa840d5b5e7f51e3bbffb41c015c978c Mon Sep 17 00:00:00 2001 From: Corbin Bartsch Date: Sun, 23 Mar 2025 22:27:50 -0400 Subject: [PATCH] Tweak workflow --- .gitea/workflows/build_and_deploy.yaml | 11 +++++------ bin/test_static_page.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 bin/test_static_page.sh diff --git a/.gitea/workflows/build_and_deploy.yaml b/.gitea/workflows/build_and_deploy.yaml index 5aa3abb..40ecec5 100644 --- a/.gitea/workflows/build_and_deploy.yaml +++ b/.gitea/workflows/build_and_deploy.yaml @@ -1,7 +1,7 @@ --- -name: Build, and deploy Hugo site -run-name: ${{ gitea.actor }} is building, and deploying the static page +name: Build, test, and deploy Hugo site +run-name: ${{ gitea.actor }} is building, testing, and deploying the static page on: push: branches: @@ -11,8 +11,6 @@ jobs: deploy-prod: runs-on: ubuntu-latest steps: - - run: echo "The job was automatically triggered by a ${{ gitea.event_name }} event." - - run: echo "The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." - name: Check out repository code uses: actions/checkout@v3 with: @@ -30,11 +28,12 @@ jobs: run: tar -xf /tmp/hugo/* -C ${{ gitea.workspace }}/bin - name: Build the static webpage run: ${{ gitea.workspace }}/bin/hugo --minify - - name: Create private key + - name: Test static page + run: bash ${{ gitea.workspace}}/bin/test_static_page.sh + - name: Copy private key run: | echo "${{ secrets.ACT_RUNNER_KEY }}" > /tmp/act_runner_key chmod 600 /tmp/act_runner_key - name: rsync public directory run: | rsync -avz --delete -e "ssh -i /tmp/act_runner_key -o StrictHostKeyChecking=no" ${{ gitea.workspace }}/public/* act_runner@whatnow.site:/var/media/nginx/ - - run: echo "This job's status is ${{ job.status }}." diff --git a/bin/test_static_page.sh b/bin/test_static_page.sh new file mode 100644 index 0000000..99bdb97 --- /dev/null +++ b/bin/test_static_page.sh @@ -0,0 +1,26 @@ +#!/bin/bash +PORT=8080 +python3 -m http.server $PORT --directory public/ & + +SERVER_PID=$! + +# Give it a moment to start +sleep 2 + +# Check if the server is running +if ! ps -p $SERVER_PID > /dev/null; then + echo "HTTP server failed to start." + exit 1 +fi + +# Check HTTP status +status_code=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:$PORT) + +# Kill the http server +kill $SERVER_PID + +# Check if status code is 200 +if [ "$status_code" -ne 200 ]; then + echo "Website returned a non-200 status code: $status_code" + exit 1 +fi