From a338c363ed1205665ea84b695111555f39c1f85c Mon Sep 17 00:00:00 2001 From: Xin Date: Wed, 26 Mar 2025 21:55:31 +0000 Subject: [PATCH] chore(ci): add support for building docs for multiple versions (#633) * chore(ci): add support for building docs for multiple versions * chore(ci): enable fetching tags in GitHub Actions workflow * chore(build): add v0.8.6 version to build script --- .github/workflows/pages.yml | 28 +++++++++++-------- build.sh | 55 +++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 12 deletions(-) create mode 100755 build.sh diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index bc5a0d3..567f9fd 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -1,5 +1,5 @@ -# Sample workflow for building and deploying a Hugo site to GitHub Pages -name: Deploy Hugo site to Pages +# Build and deploy Hextra docs site to GitHub Pages +name: Deploy Hextra docs site to Pages on: # Runs on pushes targeting the default branch @@ -36,34 +36,38 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - fetch-depth: 0 # fetch all history for .GitInfo and .Lastmod + fetch-depth: 0 # fetch all history for .GitInfo and .Lastmod + fetch-tags: true submodules: recursive + - name: Setup Go uses: actions/setup-go@v5 with: - go-version: '1.23' + go-version: "1.24" + - name: Setup Pages id: pages uses: actions/configure-pages@v5 + - name: Setup Hugo 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: Build with Hugo + + - name: Make build script executable + run: chmod +x ./build.sh + + - name: Build all site versions env: - # For maximum backward compatibility with Hugo modules HUGO_ENVIRONMENT: production HUGO_ENV: production - # Use the latest release of the theme to build exampleSite run: | - cd exampleSite && rm go.mod - hugo mod init github.com/imfing/hextra/exampleSite - hugo mod get -u github.com/imfing/hextra - hugo --minify --baseURL "${{ steps.pages.outputs.base_url }}/" + ./build.sh "${{ steps.pages.outputs.base_url }}" + - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: - path: ./exampleSite/public + path: ./public # Deployment job deploy: diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..a254987 --- /dev/null +++ b/build.sh @@ -0,0 +1,55 @@ +#!/bin/bash +set -e + +# Specify the base URL +BASE_URL=${1:-"http://localhost:1313"} + +echo "Using base URL: $BASE_URL" + +# Version configuration - modify these arrays to specify versions to build +# Format: "ref:display_name" (ref can be tag, branch, or commit hash, display name is what will appear in URL) +MAIN_VERSION="main:latest" +VERSIONS=( + "main:latest" # latest version always builds from main + "v0.9.6:v0.9" + "v0.8.6:v0.8" +) + +# Parse main version +IFS=':' read -r MAIN_REF MAIN_NAME <<< "$MAIN_VERSION" + +# Ensure clean public directory +rm -rf public +mkdir -p public +mkdir -p public/versions + +# Checkout and build main site +git checkout $MAIN_REF +GIT_HASH=$(git rev-parse --short HEAD) +echo "Building main site from $MAIN_REF (commit: $GIT_HASH)" +hugo \ + --minify \ + --themesDir=../.. --source=exampleSite \ + --baseURL "$BASE_URL/" \ + --destination=../public + +# Build all versions +for VERSION in "${VERSIONS[@]}"; do + IFS=':' read -r REF NAME <<< "$VERSION" + + git checkout $REF + GIT_HASH=$(git rev-parse --short HEAD) + echo "Building version $NAME from $REF (commit: $GIT_HASH)" + + mkdir -p "public/versions/$NAME" + hugo \ + --minify \ + --themesDir=../.. --source=exampleSite \ + --baseURL "$BASE_URL/versions/$NAME/" \ + --destination="../public/versions/$NAME" +done + +# Return to main branch +git checkout main + +echo "Build completed"