[研究笔记] Travis CI 使用介绍

版权声明:如需转载或引用,请注明出处。 https://blog.csdn.net/weixin_39278265/article/details/87696624

前言

本文旨在记录:
1)Travis CI 集成部署工具介绍;
2)如何给自己的Github项目配置Travis CI
3)自己的一些使用体会

最近在Github项目中接触了 Travis CI 的运行,感觉功能挺强大的,故在此记录。

1. Travis CI 是什么?和Github什么关系?

1.1 Travis CI的主页

Travis CI 主页:https://travis-ci.org/
在这里插入图片描述
如上,主页的介绍就是:满怀信心地测试和部署,轻松用 Travis CI 同步你的 Github 项目,并且你可以在几分钟内就能测试你的项目!(听起来很酷哦)

Test and Deploy with Confidence
Easily sync your GitHub projects with Travis CI and you’ll be testing your code in minutes!

1.2 Travis CI 的介绍

Travis CI is a hosted, distributed[2] continuous integration service used to build and test software projects hosted at GitHub.[3]

Travis CI 的介绍如上,大意是:Travis CI 是一个托管的分布式持续集成服务,用来构建并测试托管在Github上的软件项目,其中 CI 就是持续集成(continuous integration)的缩写 [2]。

The company is headquartered in Berlin, Germany and was founded in 2011.[12] In 2012 the project experienced significant growth[13] and launched a crowd funding campaign to fund further development[14] which was sponsored by dozens of technology companies.[15]

Travis的发展历史如上,还是发展的很快的。

1.3 Travis CI 和 github的关系

从上面信息来看,Travis CI和github是紧紧联系在一起的,即Travis是专门用来构建(build),测试(test),部署(deploy)Github上的项目的。


以上,参考 [1],[2]

2. Travis CI 在 Github项目上的配置

2.1 怎么让自己的Github项目用Travis CI 测试?

我只用过这个功能,改过.travis.yml文件,但是没有自己部署过,所以不详细介绍了。

具体过程可以参考: [1],[3]。

当然,最权威的还是官方文档: [5] https://docs.travis-ci.com/user/tutorial/

这里简单介绍如下:


要在Github项目上使用Travis CI,需如下步骤: ( Travis CI Tutorial https://docs.travis-ci.com/user/tutorial/

2.1.1 前提(Prerequisites)

  • A GitHub account. 即一个Github账户
  • Owner permissions for a project hosted on GitHub. 即对某个Github项目的所有者许可(也就是在github上有自己的项目仓库啦)

2.1.2 配置步骤(To get started with Travis CI)

1)进入 Travis-ci.com 并用github账户来登录;
2)接受 Travis CI 的授权,就会被重定向到github
3)点击绿色的激活按钮,选择你想使用Travis CI 的github项目;
4)给你的项目添加一个 .travis.yml 文件(来告诉Travis CI 对你的项目怎么做,运行什么命令等等);
5)提交这个文件到你的github仓库;
6)然后登陆你的 Travis CI,就可以看到构建是否成功,还有构建过程的详细信息。


以上就是简单的Travis CI和github项目的关联过程。

3. 我的Travis CI 使用体会

这个Travis CI真的有点强,等于免费有一台服务器在帮你测试程序,确实很给力。

我认为一个好的项目,是应该有一个 .travis.yml文件的,是应该在Travis CI上构建测试过的。因为Travis CI的命令很简单,如果在Travis CI 上能够运行,说明,这个项目下载到本地,也是很容易配置、运行的。

以我研究的Nopol为例 (https://github.com/SpoonLabs/nopol ),最近我在Nopol上提了一个issue https://github.com/SpoonLabs/nopol/issues/179 ,作者建议我复现一下这个bug。

为此可以说是很累了。
1)先fork这个Nopol项目到自己的仓库 (https://github.com/DehengYang/nopol );
2)在自己仓库下修改Nopol源码,编写测试用例来复现bug,然后提交一个PR(pull request)到Nopol源仓库;
3)发起的pull request在 https://github.com/SpoonLabs/nopol/pull/180 ,在自己的仓库的Nopol源码中做的修改都会及时同步到pull request中,而且马上就会被 Travis CI 捕捉到并运行,Travis CI对Nopol进行的操作全部是依据 .travis.yml 文件中的指示来进行的;
4)然后发现当前的Nopol版本支持的是jdk 1.8,bug发生在jdk 1.7下;所以呢,为此又跟作者反馈,让作者帮忙建了一个march2017的分支版本(支持jdk 1.7);
5)然后又重新提交了一个pull request https://github.com/SpoonLabs/nopol/pull/182 ;前面已经是困难重重,这里还有困难,如org.eclipse.jdt:org.eclipse.jdt.core:jar:3.12.0.v20160516-2131 这个jar包一直装不上,也找不到,原因是 groupid 错了,不应该是 org.eclipse.jdt,而应该是org.eclipse.tycho

但是如何做到最少的修改来解决这个依赖问题呢?
我想了很久,最后通过修改 .travis.yml 文件来解决问题 :(https://github.com/DehengYang/nopol/blob/march2017/.travis.yml ):

install:
- mvn dependency:get -DrepoUrl=http://download.java.net/maven/2/ -Dartifact=org.eclipse.tycho:org.eclipse.jdt.core:3.12.0.v20160516-2131
- mkdir -p $HOME/.m2/repository/org/eclipse/jdt/
- cp -rf $HOME/.m2/repository/org/eclipse/tycho/* $HOME/.m2/repository/org/eclipse/jdt/
- “./.travis_install.sh”

可以说很不容易了。
经过以上的努力,最后Travis CI 终于运行出了我想要的bug信息,到此,bug reproduction 算是完成了。

4. 总结

如上,就是关于Travis CI 的介绍,以及我的使用体会。

参考文献

[1] 使用travis-ci自动部署github上的项目 https://www.cnblogs.com/morang/p/7228488.html
[2] Travis CI https://en.wikipedia.org/wiki/Travis_CI
[3] GitHub项目加入Travis-CI的自动集成 https://www.cnblogs.com/senlinyang/p/7852446.html
[4] Core Concepts for Beginners https://docs.travis-ci.com/user/for-beginners/
[5] Travis CI Tutorial https://docs.travis-ci.com/user/tutorial/
[6] Getting Started https://docs.travis-ci.com/?utm_source=help-page&utm_medium=travisweb

猜你喜欢

转载自blog.csdn.net/weixin_39278265/article/details/87696624