编写工作流
由于众所周知的稳定性缘故,所以需要使用同步代理站 kkgithub.com
创建完仓库,push 好之后。直接点进 Action 栏目,选择 Node.js 项目,把代码复制下来。
然后本地创建文件:./.github/workflows/hexo.yml
我这就直接放我测试通过的了。
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
name: Hexo Blog CI
on: push: branches: [ "master" ]
jobs: build: name: 构建 Hexo 静态页 runs-on: ubuntu-latest
strategy: matrix: node-version: [ 22.x ]
steps: - name: 1.检出 master uses: actions/checkout@v4
- name: 2.设置 NodeJS ${{ matrix.node-version }} uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} cache: 'npm'
- name: 3.安装 yarn run: npm install yarn -g
- name: 4.安装 Hexo 命令行工具 run: yarn global add hexo-cli
- name: 5.缓存 node_modules uses: actions/cache@v4 id: cache-yarn with: path: ./node_modules key: ${{runner.OS}}-${{hashFiles('**/yarn.lock')}} restore-keys: | ${{runner.OS}}-${{hashFiles('**/yarn.lock')}} ${{runner.OS}}-
- name: 5.1.缓存 public uses: actions/cache@v4 id: cache-public with: path: ./public key: ${{runner.OS}}-public restore-keys: | ${{runner.OS}}-public
- name: 6.配置 gitssh env: PRIVATE: ${{ secrets.GIT_SSH_PRIVATE }} run: | mkdir -p ~/.ssh/ echo "$PRIVATE" > ~/.ssh/github chmod 600 ~/.ssh/github printf "Host github.com\nHostName github.com\nIdentityFile ~/.ssh/github" > ~/.ssh/config ssh-keyscan github.com >> ~/.ssh/known_hosts git config --global user.name '${{ secrets.GIT_USER }}' git config --global user.email '${{ secrets.GIT_MAIL }}'
- if: ${{ steps.cache-yarn.outputs.cache-hit != 'true' }} name: 7.初始化Hexo run: yarn
- name: 8.Hexo构建静态页 run: | hexo g
- name: 9.Git Push run: | git config --global core.autocrlf false hexo deploy
|
敲黑板,划重点。github库设置(存放 Hexo 源码的库,不是 public 库)
| 变量名 | 含义 |
|---|
| GIT_SSH_PRIVATE | git ssh的私钥,直接复制即可 |
| GIT_USER | git 用于提交的用户名 |
| GIT_MAIL | git 用于提交的邮箱 |
跟着下面两张图去找到设置变量的位置,一个一个设置就完事了。
找到位置
设置变量完事直接 push 就可以了。
后记
我是真服了啊,deploy 得另外准备一个库【<username>.github.io】才行啊。得强行覆盖了。
我本地的
Github上的【<username>.github.io】这个库是关键,博客 pages 服务靠的就是这个库,然后去又拍云做加速。
体验一下流程就完事了,action 是真不好用,可能是我不太熟悉吧。public 库的 commit 不是连续的,就很难受。还是本地 deploy 来得舒服,关键是可以保留 commit 记录。
参考文献