-
-
Save wastu01/0c35f26e087de833530b8b9b2e269506 to your computer and use it in GitHub Desktop.
如何使用 Github Actions 自動部署 Hugo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# link: https://sujingjhong.com/posts/how-to-deploy-hugo-automatically-with-github-actions/ | |
# author: lisez <[email protected]> | |
# 參照原作著提供的流程並修改成自己適用版本 | |
name: Deploy Hugo site to Pages | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: true | |
fetch-depth: 0 | |
lfs: true | |
- name: Setup Hugo | |
uses: peaceiris/actions-hugo@v2 | |
with: | |
hugo-version: "0.132.1" # 自己的 hugo 版本 | |
extended: true # 支援 SCSS/CSS 處理 | |
# 快取減少 build 時間 | |
- name: Cache resources | |
uses: actions/cache@v3 | |
with: | |
path: resources | |
key: ${{ runner.os }}-hugocache-${{ hashFiles('content/**/*', 'static/**/*', 'config.toml') }} | |
restore-keys: ${{ runner.os }}-hugocache- | |
# Hugo build 網站,清理舊檔案 | |
- name: Build | |
run: hugo --minify --gc --cleanDestinationDir | |
# 自動部署到 GitHub Pages | |
- name: Deploy | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} | |
external_repository: wastu01/wastu01.github.io | |
publish_dir: ./public | |
user_name: "wastu01" | |
user_email: "[email protected]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment