update: GitHub pages build
This commit is contained in:
143
.github/workflows/hugo.yml
vendored
143
.github/workflows/hugo.yml
vendored
@@ -1,77 +1,148 @@
|
|||||||
# Sample workflow for building and deploying a Hugo site to GitHub Pages
|
name: Build and deploy
|
||||||
name: Deploy Hugo site to Pages
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
# Runs on pushes targeting the default branch
|
|
||||||
push:
|
push:
|
||||||
branches: ["main"]
|
branches:
|
||||||
|
- main
|
||||||
# Allows you to run this workflow manually from the Actions tab
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
pages: write
|
pages: write
|
||||||
id-token: write
|
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:
|
concurrency:
|
||||||
group: "pages"
|
group: pages
|
||||||
cancel-in-progress: false
|
cancel-in-progress: false
|
||||||
|
|
||||||
# Default to bash
|
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# Build job
|
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
|
# Define tool versions
|
||||||
|
DART_SASS_VERSION: 1.101.0
|
||||||
|
GO_VERSION: 1.26.4
|
||||||
HUGO_VERSION: 0.163.1
|
HUGO_VERSION: 0.163.1
|
||||||
|
NODE_VERSION: 24.16.0
|
||||||
|
|
||||||
|
# Set the build time zone
|
||||||
|
TZ: Asia/Shanghai
|
||||||
steps:
|
steps:
|
||||||
- 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
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v6
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Setup Pages
|
- name: Setup Pages
|
||||||
id: pages
|
id: pages
|
||||||
uses: actions/configure-pages@v5
|
uses: actions/configure-pages@v6
|
||||||
- name: Install Node.js dependencies
|
|
||||||
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
|
- name: Create a local tools directory
|
||||||
- name: Build with Hugo
|
|
||||||
env:
|
|
||||||
HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache
|
|
||||||
HUGO_ENVIRONMENT: production
|
|
||||||
run: |
|
run: |
|
||||||
hugo \
|
mkdir -p "${HOME}/.local"
|
||||||
|
|
||||||
|
- name: Install Go
|
||||||
|
if: hashFiles('go.mod') != ''
|
||||||
|
uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: ${{ env.GO_VERSION }}
|
||||||
|
cache: false
|
||||||
|
|
||||||
|
- name: Install Node.js
|
||||||
|
if: hashFiles('package-lock.json') != ''
|
||||||
|
uses: actions/setup-node@v6
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
|
||||||
|
- name: Install Dart Sass
|
||||||
|
run: |
|
||||||
|
echo "Installing Dart Sass ${DART_SASS_VERSION}..."
|
||||||
|
curl -sfL --output-dir "${{ runner.temp }}" -O "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
|
||||||
|
tar -C "${HOME}/.local" -xf "${{ runner.temp }}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
|
||||||
|
echo "${HOME}/.local/dart-sass" >> "${GITHUB_PATH}"
|
||||||
|
|
||||||
|
- name: Install Hugo
|
||||||
|
run: |
|
||||||
|
echo "Installing Hugo ${HUGO_VERSION}..."
|
||||||
|
curl -sfL --output-dir "${{ runner.temp }}" -O "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"
|
||||||
|
mkdir "${HOME}/.local/hugo"
|
||||||
|
tar -C "${HOME}/.local/hugo" -xf "${{ runner.temp }}/hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"
|
||||||
|
echo "${HOME}/.local/hugo" >> "${GITHUB_PATH}"
|
||||||
|
|
||||||
|
- name: Log tool versions
|
||||||
|
run: |
|
||||||
|
echo "Logging tool versions..."
|
||||||
|
command -v sass &> /dev/null && echo "Dart Sass: $(sass --version)" || echo "Dart Sass: not installed"
|
||||||
|
command -v go &> /dev/null && echo "Go: $(go version)" || echo "Go: not installed"
|
||||||
|
command -v hugo &> /dev/null && echo "Hugo: $(hugo version)" || echo "Hugo: not installed"
|
||||||
|
command -v node &> /dev/null && echo "Node.js: $(node --version)" || echo "Node.js: not installed"
|
||||||
|
|
||||||
|
- name: Configure Git
|
||||||
|
run: |
|
||||||
|
echo "Configuring Git..."
|
||||||
|
git config --global core.quotepath false
|
||||||
|
|
||||||
|
- name: Fetch full Git history
|
||||||
|
run: |
|
||||||
|
if [[ $(git rev-parse --is-shallow-repository) == true ]]; then
|
||||||
|
echo "Fetching full Git history..."
|
||||||
|
git fetch --unshallow
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Initialize Git submodules
|
||||||
|
run: |
|
||||||
|
if [[ -f .gitmodules ]]; then
|
||||||
|
echo "Initializing Git submodules..."
|
||||||
|
git submodule update --init --recursive
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Install Node.js dependencies
|
||||||
|
run: |
|
||||||
|
if [[ -f package-lock.json ]]; then
|
||||||
|
echo "Installing Node.js dependencies..."
|
||||||
|
npm ci
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Cache restore
|
||||||
|
id: cache-restore
|
||||||
|
uses: actions/cache/restore@v5
|
||||||
|
with:
|
||||||
|
path: ${{ runner.temp }}/hugo_cache
|
||||||
|
key: hugo-${{ github.run_id }}
|
||||||
|
restore-keys: hugo-
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
echo "Building the project..."
|
||||||
|
hugo build \
|
||||||
--gc \
|
--gc \
|
||||||
--minify \
|
--minify \
|
||||||
--cleanDestinationDir \
|
--baseURL "${{ steps.pages.outputs.base_url }}/" \
|
||||||
--destination ./public \
|
--cacheDir "${{ runner.temp }}/hugo_cache"
|
||||||
--baseURL "${{ steps.pages.outputs.base_url }}/"
|
|
||||||
- name: Upload artifact
|
- name: Cache save
|
||||||
uses: actions/upload-pages-artifact@v3
|
uses: actions/cache/save@v5
|
||||||
with:
|
with:
|
||||||
|
path: ${{ runner.temp }}/hugo_cache
|
||||||
|
key: ${{ steps.cache-restore.outputs.cache-primary-key }}
|
||||||
|
|
||||||
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-pages-artifact@v5
|
||||||
|
with:
|
||||||
|
include-hidden-files: false
|
||||||
path: ./public
|
path: ./public
|
||||||
|
|
||||||
# Deployment job
|
|
||||||
deploy:
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
environment:
|
environment:
|
||||||
name: github-pages
|
name: github-pages
|
||||||
url: ${{ steps.deployment.outputs.page_url }}
|
url: ${{ steps.deployment.outputs.page_url }}
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: build
|
|
||||||
steps:
|
steps:
|
||||||
- name: Deploy to GitHub Pages
|
- name: Deploy to GitHub Pages
|
||||||
id: deployment
|
|
||||||
uses: actions/deploy-pages@v5
|
uses: actions/deploy-pages@v5
|
||||||
|
|||||||
Reference in New Issue
Block a user