From b09c2adebf95ed927e0fc1f003734904496c873a Mon Sep 17 00:00:00 2001 From: Gregory Horvath Date: Sat, 9 Nov 2024 03:02:55 -0500 Subject: [PATCH] workflow tweaks --- .github/workflows/hugo.yaml | 50 +++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/.github/workflows/hugo.yaml b/.github/workflows/hugo.yaml index f49650a..9e16fed 100644 --- a/.github/workflows/hugo.yaml +++ b/.github/workflows/hugo.yaml @@ -1,10 +1,13 @@ -# Sample workflow for building and deploying a Hugo site to GitHub Pages +# Sample workflow for building and deploying a Hugo site to Pages name: Deploy Hugo site to Pages on: # Runs on pushes targeting the default branch push: branches: ["main"] + paths: + - 'docs/**' # Only trigger on changes to docs directory + - '.github/workflows/hugo.yml' # And on workflow file changes # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -16,7 +19,6 @@ permissions: id-token: write # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. -# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. concurrency: group: "pages" cancel-in-progress: false @@ -33,21 +35,42 @@ jobs: env: HUGO_VERSION: 0.128.0 steps: + # Add cache for Hugo modules and builds + - name: Cache Hugo resources + uses: actions/cache@v3 + with: + path: | + ${{ runner.temp }}/hugo_cache + ./docs/resources + key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-hugomod- + - name: Install Hugo CLI run: | wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ && sudo dpkg -i ${{ runner.temp }}/hugo.deb + - name: Install Dart Sass run: sudo snap install dart-sass + - name: Checkout uses: actions/checkout@v4 with: submodules: recursive + fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod + - name: Setup Pages id: pages uses: actions/configure-pages@v5 + - name: Install Node.js dependencies run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true" + + # Add HTML validation + - name: Setup HTML validation + run: npm install -g html-validator-cli + - name: Build with Hugo env: HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache @@ -57,6 +80,23 @@ jobs: --minify \ --source docs \ --baseURL "${{ steps.pages.outputs.base_url }}/" + + # Add error checking + - name: Check for Hugo errors + run: | + if [ -d "./docs/public" ]; then + echo "Build succeeded" + else + echo "Build failed" + exit 1 + fi + + # Validate HTML output + - name: Validate HTML + run: | + find ./docs/public -name '*.html' -exec html-validator {} \; + continue-on-error: true # Optional: set to false if you want validation errors to fail the build + - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: @@ -73,3 +113,9 @@ jobs: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 + + # Add deployment verification + - name: Verify deployment + run: | + curl -s --head --request GET ${{ steps.deployment.outputs.page_url }} | grep "200\|301" + shell: bash \ No newline at end of file