STC214/使用git Action部署博客

Created Mon, 25 Sep 2023 19:06:03 +0800 Modified Tue, 26 Sep 2023 23:47:53 +0800
416 Words

参考网址:

https://zhuanlan.zhihu.com/p/403221054

https://zhuanlan.zhihu.com/p/240522090

https://zhuanlan.zhihu.com/p/109057290

https://client.sspai.com/post/73512#!

https://immmmm.com/hugo-github-actions/

01.生成token

# 注意生成路径不要覆盖掉原本的key
ssh-keygen -t rsa -b 4096 -C '账号邮箱'

02.配置

pub key用在pages的设置中

settings-Dewploy keys- 标题(随意)-key

pravite_key用在源文件设置

settings– Secrets and variables– Actions–New –title(ACTIONS_DEPLOY_KEY)-key

Actions

源码仓库

Actions- New workflow -new file- main.yml


name: Deploy Hugo Site to Github Pages on Master Branch

on:
    push:
    workflow_dispatch:
    schedule:
        # Runs everyday at 8:00 AM
        - cron: "0 0 * * *"

jobs:
  build-deploy:
    runs-on: ubuntu-latest # 环境推荐最新的ubuntu
    steps:
      - uses: actions/checkout@v1  # 不变 v2 does not have submodules option now
        # with:
        #   submodules: true

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2 # 不变
        with:
          hugo-version: '0.119.0' # hugo版本 2023年9月25日最新版为0.119.0
          # extended: true

      - name: Build
        run: hugo --minify

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3 # 不变
        with:
          deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} # 这里的 ACTIONS_DEPLOY_KEY 则是上面设置 Private Key的变量名
          external_repository: JaredTan95/JaredTan95.github.io # Pages 远程仓库 (即为部署平台的仓库)
          publish_dir: "./public/"  # 推送过去的目录
          keep_files: True # 是否保留源码库的源文件 remove existing files
          publish_branch: main  # 推送到的目标分支 deploying branch
          commit_message: ${{ github.event.head_commit.message }}

编辑完成后提交commit此文件

设置pages

将站点pages仓库的pages选项中的

Build and deployment

选成GitHub Actions

等待页面变化为可以直接访问文章站点的状态即可

其他问题

暂无