注意:需要创建两个仓库
your_blog_name.github.io
:编译后的仓库(本次教程没有涉及,网上搜下就有)
hexo_blog
: hexo
生成 blog
的仓库(本次教程重点会在这里)
创建个人访问令牌
注意要勾选repo
权限和workflow
权限
注意:生成TOKEN
后要复制后保存好,因为在下次进来时这个值就看不到了
新建 Hexo Blog 仓库
建议使用private
来建,防止其它人克隆
设置仓库的secrets
取名为 ACCESS_TOKEN
后面部署的时候会用到
配置 _config.yml
1 2 3 4 5
| deploy: type: git repository: https://ACCESS_TOKEN@github.com/your_github_name/your_blog_name.github.io.git branch: master message: deploy
|
创建 Workflow
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
| name: Hexo Deploy
on: [push]
env: GIT_USER: your_github_name GIT_EMAIL: your@email.com DEPLOY_BRANCH: main
jobs: build: runs-on: ubuntu-latest
steps: - name: Download Source file uses: actions/checkout@v2 with: ref: ${{ env.DEPLOY_BRANCH }}
- name: Setup Node.js uses: actions/setup-node@v1 with: node-version: "12"
- name: Set env env: ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} run: | git config --global user.email $GIT_USER git config --global user.name $GIT_EMAIL sed -i "s/ACCESS_TOKEN/$ACCESS_TOKEN/g" ./_config.yml
- name: Hexo Setup run: | npm install hexo-cli -g npm install
- name: Hexo Deploy run: | hexo clean hexo deploy
|
验证
默认推送后就会执行 Workflow