创建文件.github/workflows/hugo.yml
内容:
name: GitHub Pages
on:
push:
branches:
- main # Set a branch to deploy
pull_request:
jobs:
deploy:
runs-on: ubuntu-22.04
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- uses: actions/checkout@v3
with:
submodules: true # Fetch Hugo themes (true OR recursive)
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: '0.110.0'
# extended: true
- name: Build
run: hugo --minify
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.ref == 'refs/heads/main' }}
with:
github_token: ${{ secrets.ACCESS_TOKEN }}
publish_dir: ./public
- name: Pushes to another repository
uses: cpina/github-action-push-to-another-repository@main
env:
API_TOKEN_GITHUB: ${{ secrets.ACCESS_TOKEN }}
with:
source-directory: 'public'
destination-github-username: 'username'
destination-repository-name: 'repo name'
user-email: *@gmail.com
target-branch: gh-pages
对于配置中需要修改的参数
- ACCESS_TOKEN
- destination-github-username
- destination-repository-name
- user-email
API_TOKEN_GITHUB:需要到github tokens页面设置,比如设置名称ACCESS_TOKEN
,记得保存token,只会出现一次。设置完后,可以在自己的repo中设置,设置路径settings/secrets/actions
;
destination-github-username:自己的username;
destination-repository-name:源码repo;
user-email:提交代码的邮箱;