#!/usr/bin/env bash
# If a command fails then the deploy stopsset -e
printf"\033[0;32mDeploying updates to GitHub...\033[0m\n"cd ~/hugo
if[ -e "public"];then rm -rf public
figit clone -b gh-pages git@github.com:cnsunyour/cnsunyour.github.io.git public
hugo --gc --minify
cd public
git add .
msg="rebuilding site $(date)"if[ -n "$*"];thenmsg="$*"figit commit -m "$msg"git push -u origin gh-pages
rm -rf public
name:Deploy Hugo site to Pageson:# Runs on pushes targeting the default branchpush:branches:- master- mainpull_request:# Allows you to run this workflow manually from the Actions tabworkflow_dispatch:jobs:# Deployment jobdeploy:runs-on:ubuntu-lateststeps:- name:Setup Hugouses:peaceiris/actions-hugo@v2with:hugo-version:'latest'extended:true- name:Checkoutuses:actions/checkout@v4with:submodules:recursivefetch-depth:0- name:Build with Hugoenv:# For maximum backward compatibility with Hugo modulesHUGO_ENVIRONMENT:productionHUGO_ENV:productionrun:| hugo --gc --minify- name:Deployuses:peaceiris/actions-gh-pages@v3with:deploy_key:${{ secrets.DEPLOY_PRIVATE_KEY }}external_repository:cnsunyour/cnsunyour.github.iopublish_branch:gh-pagespublish_dir:./publiccname:sunyour.orgfull_commit_message:${{ github.event.head_commit.message }}
actions-hugo 的一个特点是可以安装最新版的 hugo ,而不用设置具体的版本号,对于我这个更新强迫症非常友好。