为Github项目添加Travis持续集成服务

参考链接:https://www.jianshu.com/p/3b8d86f25ee2
http://www.ruanyifeng.com/blog/2017/12/travis_ci_tutorial.html

使用Travis-ci自动SSH部署代码: https://www.zhuwenlong.com/blog/article/5c24b6f2895e3a0fb4072a5c

以下为个人修改

1. 添加Github Pages(https://docs.travis-ci.com/user/deployment/pages/)搜索gh-pages即可得到该链接

deploy:
  provider: pages
  skip_cleanup: true
  github_token: $GITHUB_TOKEN  # Set in the settings page of your repository, as a secure variable
  keep_history: true
  on:
    branch: master

这里的$GITHUB_TOKEN 是在GitHub配置的personal token(设置token链接:https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line

由于这个是私密token,可以采用文档提及的两种方式之一,通过在travis配置环境变量来获取

2. 加密文件

# 安装travis命令行工具,如无法使用gem;可以将ruby更换成国内的源;gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
gem install travis
# --auto自动登录github帐号
travis login --auto
# 此处的--add参数表示自动添加脚本到.travis.yml文件中
travis encrypt-file ~/.ssh/id_rsa --add
# 这个命令会自动把 id_rsa 加密传送到 .git 指定的仓库对应的 travis 中去

登录失败

 对应的issue: https://github.com/travis-ci/travis.rb/issues/190 

题外话:

ruby采用源码安装(https://www.runoob.com/ruby/ruby-installation-unix.html

Homebrew 采用官方提供的安装命令:https://brew.sh/index_zh-cn

原文地址:https://www.cnblogs.com/luguiqing/p/11711018.html