sayi.github.com icon indicating copy to clipboard operation
sayi.github.com copied to clipboard

为你的Github项目加上徽章

Open Sayi opened this issue 7 years ago • 0 comments

程序员是有趣的,他们喜欢简简单单的字母,有时候也想变得好玩点,他们使用emoji,并且为他们的项目加上了徽章。

image

徽章就是如上图的东西,每个徽章通过色彩和数字简要的说明了项目的某种特征,更加直观的多维度了解这个项目。

Travis CI徽章

Travis CI是一个持续集成平台,通过CI我们可以第一时间知道我们的项目有没有打包成功,获得徽章,我们参照官网的指南就可以了。

  1. 使用GitHub登录,激活github 仓库
  2. 在项目根目录下,编写.travis.yml文件
  3. 提交代码会自动触发build

接下来我们就可以在travis-ci上获得这个徽章,我们可以选择Markdown语法,然后写到项目的Readme里。

Sonar 徽章

打开https://sonarcloud.io/,同样使用GitHub登录,按照说明我们获取到token,然后在Github项目根目录下执行命令:

mvn sonar:sonar \
>   -Dsonar.organization=sayi-github \
>   -Dsonar.host.url=https://sonarcloud.io \
>   -Dsonar.login=XXXXXX

执行好后,在sonarcloud上的项目目录下,就可以领取徽章了。

Coveralls

对于普通的Java项目,需要两步:

  1. Add your repository to Coveralls. 打开https://coveralls.io/,使用GitHub账号登录,将你需要测试的代码项目开关打开。

  2. Configure your build to install the Coveralls library for the programming language you’re using. Coveralls与Travis是自动集成的,修改Travis的.travis.yml文件,最后加上这一行:

after_success:
  - mvn clean cobertura:cobertura org.eluder.coveralls:coveralls-maven-plugin:report

同时在项目的POM.xml文件里面,引入响应的插件:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>2.7</version>
    <configuration>
    <format>xml</format>
    <maxmem>256m</maxmem>
    <!-- aggregated reports for multi-module projects -->
    <aggregate>true</aggregate>
    </configuration>
</plugin>
<plugin>
    <groupId>org.eluder.coveralls</groupId>
    <artifactId>coveralls-maven-plugin</artifactId>
    <version>4.3.0</version>
</plugin>

至此,当触发CI的时候,就会上传覆盖率的报告,我们可以去coveralls领徽章了。

更多徽章

我们可以去gitter领社交徽章、也可以接着去领取license徽章,等等。

但是程序员的世界你不懂,当我们不断的领徽章的时候,有一部分程序员提供了徽章服务,你完全可以自定义自己的徽章。打开下面这个链接,你将看到一个GoodGame徽章:

https://img.shields.io/badge/goodgame-100%25-green.svg

服务是由https://shields.io/提供。

Sayi avatar May 09 '18 14:05 Sayi