使用github action发布hugo到github page
2021-06-25, updated 2021-09-12
可以使用github action来进行发布hugo
hugo发布到新的仓库作为github page
在github仓库上选择action,选择set up a workflow yourself
,将下面的内容填入打开的编辑框。
external_repository配置为对应的github page的仓库.
示例代码
name: github pages
on:
push:
branches:
- main # Set a branch to deploy
pull_request:
jobs:
deploy:
runs-on: ubuntu-20.04
steps:
- uses: actions/[email protected]
with:
submodules: true # Fetch Hugo themes (true OR recursive)
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: Setup Hugo
uses: peaceiris/[email protected]
with:
hugo-version: 'latest'
extended: true
- name: Build
run: hugo --minify
- name: Deploy
uses: peaceiris/[email protected]
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
external_repository: xxxx # 发布到的repository. 例如: https://github.com/torvalds/linux.git填入torvalds/linux
publish_branch: main # default: gh-pages
publish_dir: ./public
问题一: 将对应的key填入两个github仓库
-
生成key
ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/action_deploy_key`
会生成两个文件
action_deploy_key.pub
和action_deploy_key
-
选择external_repository仓库的
Settings-->Deploy keys-->Add deploy key
Title
中填入ACTIONS_DEPLOY_KEY
Key
中填入action_deploy_key.pub
文件内容
-
选择当前仓库的
Settings-->Secrets-->New repository secret
Name
中填入ACTIONS_DEPLOY_KEY
Value
中填入action_deploy_key
文件内容
问题二: 自定义域名
添加CNAME到hugo的staic目录,内容为custom-domain.com
详细内容查看 https://docs.github.com/cn/actions/learn-github-actions