配置Travis-CI

第一步 新增travis 文件

.travis.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
# 指定语言环境
language: node_js
# 指定需要sudo权限
sudo: required
# 指定node_js版本
node_js:
- 7.9.0
# 指定缓存模块,可选。缓存可加快编译速度。
cache:
directories:
- node_modules

# 指定博客源码分支,因人而异。hexo博客源码托管在独立repo则不用设置此项
branches:
only:
- hexo

before_install:
- npm install -g hexo-cli

# Start: Build Lifecycle
install:
- npm install
- npm install hexo-deployer-git --save

# 执行清缓存,生成网页操作
script:
- hexo clean
- hexo generate

# 设置git提交名,邮箱;替换真实token到_config.yml文件,最后depoy部署
after_script:
- git config user.name "yourName"
- git config user.email "yourEmail"
# 替换同目录下的_config.yml文件中gh_token字符串为travis后台刚才配置的变量,注意此处sed命令用了双引号。单引号无效!
- sed -i "s/gh_token/${GH_TOKEN}/g" ./_config.yml
- hexo deploy
# End: Build LifeCycle

第二步 修改下_config.yml文件的deploy节点:

1
2
3
4
5
# 修改前
deploy:
- type: git
repo: git@github.com:xiong-it/xiong-it.github.io.git
branch: master
1
2
3
4
5
6
# 修改后
deploy:
- type: git
# 下方的gh_token会被.travis.yml中sed命令替换
repo: https://gh_token@github.com/xiong-it/xiong-it.github.io.git
branch: master

https://juejin.im/post/5a1fa30c6fb9a045263b5d2a

请作者喝一杯咖啡☕️