Skip to content

Hugo build and deploy #991

Hugo build and deploy

Hugo build and deploy #991

Workflow file for this run

name: Hugo build and deploy
on:
schedule:
# Rebuid the site every day at 00:00 UTC to update the projects data
- cron: '0 0 * * *'
push:
branches: [ main ]
paths:
- 'assets/**'
- 'config/**'
- 'content/**'
- 'data/**'
- 'static/**'
- 'themes/**'
- 'go.mod'
- 'go.sum'
workflow_run:
workflows: ['Update theme']
types:
- completed
workflow_dispatch:
jobs:
Actions-Hugo-Deploy:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.SYNC_CONTENT }}
submodules: true # Fetch Hugo themes (true OR recursive)
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: Install
run: npm install
- name: Cache Hugo resources
uses: actions/cache@v4
env:
cache-name: cache-hugo-resources
with:
path: resources
key: ${{ env.cache-name }}
- uses: actions/setup-go@v5
with:
go-version: "^1.20.0"
- run: go version
- name: Cache Go Modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: latest
extended: true
- name: Build
env:
HUGO_PARAMS_GHTOKEN: ${{ secrets.HUGO_PARAMS_GHTOKEN }}
run: npm run build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
deploy_key: ${{ secrets.GP_DEPLOY_KEY }}
external_repository: Lruihao/lruihao.github.io
publish_branch: main
publish_dir: ./public
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
commit_message: ':rocket: ${{ github.event.head_commit.message }}'
force_orphan: false # once a year
- name: Update Algolia index
env:
ALGOLIA_APP_ID: MTJNHU0JVB
ALGOLIA_ADMIN_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }}
ALGOLIA_INDEX_NAME: 'index'
ALGOLIA_INDEX_FILE: './public/search.json'
run: npm run algolia
# - name: Install coscmd
# run: sudo pip install coscmd
# - name: Configure coscmd
# env:
# COS_SECRET_ID: ${{ secrets.COS_SECRET_ID }}
# COS_SECRET_KEY: ${{ secrets.COS_SECRET_KEY }}
# COS_BUCKET_NAME: blog-1256932288
# COS_BUCKET_REGION: ap-chengdu
# run: coscmd config -a $COS_SECRET_ID -s $COS_SECRET_KEY -b $COS_BUCKET_NAME -r $COS_BUCKET_REGION
# - name: Deploy to COS Bucket
# run: coscmd upload -r -s --delete -f public/ /
# - name: Refresh Qcloud CDN cache
# env:
# SECRET_ID: ${{ secrets.COS_SECRET_ID }}
# SECRET_KEY: ${{ secrets.COS_SECRET_KEY }}
# run: npm run qcloudcdn