参考
利用 Github Actions 自动部署 Hexo 博客
GitHub Action + Hexo 实现在线写作
前言
为了搭建HexoPlusPlus所以先部署了Actions.
准备仓库
Source_code //放源代码文件scaffolds、source、themes、_config.yml、package.json、package-lock.json(删除.git)
limitationai.github.io //放静态文件(也就是发布页)
生成密钥,公钥
1 2
| #生成公钥,密钥 ssh-keygen -f github-deploy-key
|
Windows生成后会在C:\Users\你的用户名.ssh文件夹里面有两个文件分别是公钥github_rsa.pub和密钥github_rsa。
配置密钥
复制 github-deploy-key 文件内容,在放源码的Source_code仓库 Settings -> Secrets -> Add a new secret 页面上添加。

配置公钥
复制 github-deploy-key.pub 文件内容,在 limitationai.github.io 仓库 Settings -> Deploy keys -> Add deploy key 页面上添加。

添加Actions

将以下的代码复制粘贴,并且根据自身情况修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| name: 自動部署 Hexo
on: push: branches: - main
jobs: build: runs-on: ubuntu-latest strategy: matrix: node-version: [12.x]
steps: - name: 开始运行 uses: actions/checkout@v1
- name: 设置 Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }}
- name: 配置 Git 环境 env: ACTION_DEPLOY_KEY: ${{secrets.HEXO_DEPLOY_PRIVATE_KEY}} run: | mkdir -p ~/.ssh/ echo "$ACTION_DEPLOY_KEY" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa ssh-keyscan github.com >> ~/.ssh/known_hosts git config --global user.name "limitationai" git config --global user.email "limitationai@gmail.com" - name: 安装 Hexo CI run: | export TZ='Asia/Shanghai' npm i -g hexo-cli npm i - name: 安装插件 run: | npm install hexo-renderer-pug --save npm install hexo-renderer-stylus --save npm install hexo-deployer-git --save npm install hexo-generator-search --save npm install hexo-douban --save npm install hexo-generator-feed --save npm install hexo-abbrlink --save npm install hexo-wordcount --save - name: 部署博客 run: | rm -rf .deploy_git hexo g && hexo douban && hexo deploy rm ~/.ssh/id_rsa
|
结语
最后去github个人仓库界面看见有橙色的小圆点就代表部署成功了