1. 準備工作#
2. 創建庫和環境#
-
在 GitHub 中
Create a new repository
- 名字:
yourusername.github.com
- 名字:
-
創建 TOKEN
- 賬戶 - 設置 - Develop Settings-Personal access tokens
- Expiration 設置永不
- 勾選
repo
和workflow
-
鏈接 Token 到
repository
- 打開庫 - 設置
- 新建密鑰。名稱 TOKEN
3. 本地創建 workflow#
- 在 your-blog-site 目錄裡面依次創建
.github/workflows/hugo_de.yaml
name: deploy
# 代碼提交到main分支時觸發github action
on:
push:
branches:
- dev
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: "latest"
extended: true
- name: Build Web
run: hugo -D
- name: Deploy Web
uses: peaceiris/actions-gh-pages@v4
with:
PERSONAL_TOKEN: ${{ secrets.TOKEN }} #TOKEN是剛才在庫裡面創建的名字,按照你的填。
EXTERNAL_REPOSITORY: your-username/your-repository-name
PUBLISH_BRANCH: main
PUBLISH_DIR: ./public
commit_message: auto deploy
這個自動程序是將你本地未部署的文件發布到 dev 分支,然後 Action 自動部署到 main 分支
4. 部署到 GitHub#
- 在主目錄下輸入:
git init
git add .
git commit -m "update"
git branch -M dev
git remote add origin https://github.com/your-username/your-repository-name.git
git push -u origin dev
- 設置 GitHub Page
- repository-setting-general-Default branch:
main
- repository-setting-page-Deploy from a branch:
main
- repository-setting-general-Default branch: