关于golang:GitHub-徽章制作

3次阅读

共计 2427 个字符,预计需要花费 7 分钟才能阅读完成。

很早前写过一篇对于 Golang 继续集成服务之 Travis 教程, 明天再写写对于 github 上常见的徽章是如何制作的. 让你的开源我的项目更高大上, 让你的代码也更强壮.

徽章的含意

当你浏览一个开源我的项目时, 看到各种徽章, 有些徽章是间接反馈这个开源库的品质和完整性等等.

如上图所示

  1. 第一个徽章即 Github 自带的 workflow 提供的继续集成 (CI) 和继续部署(CD), 官网称之为 Actions, 图示显示为 CI, CD 是否通过
  2. 第二个徽章即 Codecov 是一个测试后果剖析工具, 图标显示测试覆盖率.
  3. 第三个徽章即 shields.io 一个能够自定义徽章的网站
  4. 第四个徽章即 goreportcard 是一个我的项目综合评分网站
  5. 第五个徽章即 gitter 自定义讨论组的网站

CI&CD 徽章

github 于 2018. 10 月举荐 GitHub Actions 继续集成服务, 在此之前大家都是应用 https://travis-ci.org/ 继续集成服务, 之前我也写过相干文章. Golang 继续集成服务之 Travis 教程.

继续集成和继续部署目前 github 官网自带反对, 官网称之为 GitHub Actions.

只有你在 github 上创立一个开源我的项目仓库就自带 Actions 性能, 反对各种语言. 还能够主动公布 GitHub Pages 等性能, 非常弱小.

如何应用能够参考阮一峰写的 GitHub Actions 入门教程

对于 GO 的继续集成服务模板参考:

应用 GitHub Actions 后会在你的我的项目里自带生成一个 .github 文件夹, 即.github/workflows/go.yml

name: Go # 应用语言

on:     # 监听动作
  push: # 监听 push 动作
    branches: [main] # 监听哪个分支 branch
  pull_request:
    branches: [main]

jobs: # 工作 job
  build: # 构建动作
    runs-on: ubuntu-latest # 基于 ubuntu 零碎
    steps: 
    - uses: actions/checkout@v2

    - name: Set up Go 
      uses: actions/setup-go@v2
      with:
        go-version: 1.15

    - name: Build # 构建我的项目
      run: go build -v ./...

    - name: Test # 运行用例
      run: go test -v .

徽章的制作.

https://github.com/yezihack/e/workflows/Go/badge.svg
  1. https://github.com/yezihack/e 是我的项目的地址
  2. workflows/Go/badge.svg 两头的Go 是 https://github.com/yezihack/e… 下的名称. 须要留神辨别大小写

测试覆盖率 徽章

登陆官网 https://codecov.io/ 应用 GitHub 帐号登陆, 受权导出你的我的项目.

在我的项目的根目录新建.travis.yml 文件

实例文件参考

language: go # 应用语言.
go: 
  - 1.15.6  # 版本号, 反对多种版本号

sudo: required #  #有定制化开发环境须要,默认 false,不开启容器,编译效率高 

os:            # 应用的操作系统 
  - linux
  - osx

notifications:  # 邮箱告诉
  email: freeit@126.com

go_import_path: # 应用 Go 须要导入的包. 
  - github.com/gin-gonic/gin
  - github.com/pkg/errors
  - github.com/smartystreets/goconvey

before_install: # 次要装置一些零碎依赖,
  - go mod tidy

install: true # 装置, true 跳过

script: # 脚本执行.
  - echo "run"
  - go test -race -coverprofile=coverage.txt -covermode=atomic
  - go test -v ./...

after_success: # 上传测试报告
  - bash <(curl -s https://codecov.io/bash)

徽章制作

点击 Settings -> Badge

文档徽章

https://pkg.go.dev/ 只针对 Golang 语言主动生成文档

关上网站间接输出你我的项目的拜访地址, 自带生成.

如 https://github.com/yezihack/e

文档地址即: https://pkg.go.dev/github.com…

徽章制作

https://img.shields.io/badge/go.dev-reference-brightgreen?logo=go&logoColor=white&style=flat
[![Go doc](https://img.shields.io/badge/go.dev-reference-brightgreen?logo=go&logoColor=white&style=flat)](https://pkg.go.dev/github.com/yezihack/e)

综合报告徽章

关上 https://goreportcard.com/ 间接填写你的我的项目拜访地址即可.

徽章制作

https://goreportcard.com/badge/github.com/yezihack/e

讨论组徽章

关上 https://gitter.im/ 注册, 创立一个小组, 能够邀请开发者一起探讨.

创立小组时最好以你的用户名 + 仓库名 命名. 这样不便辨认.

徽章制作

获取你的讨论组的地址, 而后在 https://shields.io/category/chat 抉择 Gitter 即可. 填写你的用户名和仓库名信息

![Gitter](https://img.shields.io/gitter/room/yezihack/e)

其它徽章

关上 https://shields.io 能够自定义很多共性的图标, 让你的我的项目更业余.

正文完
 0