美文网首页Hexo
hexo使用Travis CI自动更新

hexo使用Travis CI自动更新

作者: 洗洗睡吧i | 来源:发表于2019-06-12 11:17 被阅读9次

准备

  • 需要两个 github 仓库:
    • 一个用于发布页面: shenbo.github.io
    • 一个用于放源码: hexo-source
  • Travis CI 账户 (https://www.travis-ci.org/)

1. 创建 hexo-source 仓库

  • 在hexo的根目录下( ~/hexo)运行:
cd hexo

git init
git add .
git commit -m "first commit"
git remote add origin https://github.com/shenbo/hexo-source.git

git push -u origin master

2. Travis CI 与 Github 设置

2.1 打开 Github 个人设置,创建授权 tokens

2.2 设置 Travis CI 与 Github 绑定

  • 将 Travis 账号 与 Github绑定,激活 hexo-source仓库的开关
  • 打开仓库设置,在 Environment Variables 选项中新建 github_token 项,将刚刚获得的token填进去
  • 其他默认选项不用管

3. 添加 Travis CI 配置文件

  • 在hexo的根目录下( ~/hexo)新建 .travis.yml
    内容如下:
language: node_js
node_js: stable

cache:
    apt: true
    directories:
        - node_modules

before_install:
    - npm install hexo-cli -g

install:
  - npm install
  - npm install hexo-deployer-git --save

script:
  - hexo clean
  - hexo g

after_script:
  - git clone ${GH_REF} hexo-public
  - cp -rf public/* hexo-public/
  - cd hexo-public
  - git config user.name "shenbo"
  - git config user.email "shenbo@hotmail.com"
  - git add .
  - git commit -am "Travis CI Auto Builder..."
  - git push origin master 

branches:
  only:
    - master
env:
 global:
   - GH_REF: https://shenbo:${github_token}@github.com/shenbo/shenbo.github.io.git 

  • 在 hexo-source 仓库 push 一下, 几秒钟后在 Travis CI 页面应该能看到正在 build。

4. 使用

配置成功后,可以发现,本地就不需要nodejs环境了;

即使换了电脑只要clone hexo-source 仓库,更新这个仓库即可。

相关文章

网友评论

    本文标题:hexo使用Travis CI自动更新

    本文链接:https://www.haomeiwen.com/subject/mhmkfctx.html