I wrote a long time ago about Travis, Golang’s continuous integration service, and today I’m writing about how common badges on Github are created. Make your open source projects bigger and your code more robust.
The meaning of a badge
When you browse through an open source project, you see badges, some of which directly reflect the quality and completeness of the open source library, etc.
As shown above
- The first badge is the Continuous Integration (CI) and continuous Deployment (CD) badges provided by Github’s workflow. Officially, they are called Actions
- The second badge, Codecov, is a test results analysis tool, and the icon shows test coverage.
- The third badge is Shields. IO, a website that allows you to customize your badge
- The fourth badge, GoReportCard, is a project rating site
- The fifth badge is the Gitter custom discussion group website
CI&CD badge
Github introduced the Github Actions Continuous Integration service in October 2018. Before that, everyone was using the Travis-ci.org/ Continuous integration service, which I wrote about earlier. Travis tutorial for Golang Continuous Integration service.
Continuous integration and continuous deployment are currently supported by Github’s built-in support, known as Github Actions.
Whenever you create an open source repository on Github, you bring in Actions, which supports various languages. You can also automatically publish GitHub Pages, which is very powerful.
How to use GitHub Actions tutorial written by Ruan Yifeng
Continuous Integration service template reference for GO:
Using GitHub Actions will create a.github folder in your project, i.e. GitHub /workflows/go.yml
name: Go # Use language
on: # monitor action
push: # listen for push
branches: [ main ] # monitor which branch branch
pull_request:
branches: [ main ]
jobs: # work job
build: # Build action
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 # Build the project
run: go build -v . /...
- name: Test Run the use case
run: go test -v .
Copy the code
Badge making.
https://github.com/yezihack/e/workflows/Go/badge.svg
Copy the code
https://github.com/yezihack/e
Is the address of the projectworkflows/Go/badge.svg
In the middle of theGo
是 Github.com/yezihack/e/…Case sensitive
Test coverage badge
Log in to codecov. IO/use GitHub to authorize the export of your project.
Create a.travis. Yml file in the root directory of the project
Example file Reference
language: go # Use language.
go:
- 1.156. # Version number: supports multiple version numbers
sudo: required If you need to customize the development environment, the default value is false
os: # Operating system used
- linux
- osx
notifications: # Email notification
email: [email protected]
go_import_path: # Import packages to use Go.
- github.com/gin-gonic/gin
- github.com/pkg/errors
- github.com/smartystreets/goconvey
before_install: Install some system dependencies,
- go mod tidy
install: true # install, true skip
script: # Script execution.
- echo "run"
- go test -race -coverprofile=coverage.txt -covermode=atomic
- go test -v . /...
after_success: Upload test report
- bash <(curl -s https://codecov.io/bash)
Copy the code
Badge production
Go to Settings -> Badge
Document the badge
Pkg.go.dev/automatically generates documentation for Golang only
Open the website directly input your project access address, own generation.
Such as github.com/yezihack/e
File address: pkg.go.dev/github.com/…
Badge production
https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/dde570f4a4404564b768d3d5a97932c3~tplv-k3u1fbpfcp-zoom-1.image
Copy the code
[! [Go doc](https://img.shields.io/badge/go.dev-reference-brightgreen?logo=go&logoColor=white&style=flat)](https://pkg.go.dev/g ithub.com/yezihack/e)Copy the code
Integrated Reporting badge
Go to goreportcard.com/ directly fill in your project access address.
Badge production
https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/265054edfcb845a591d942045bc81caf~tplv-k3u1fbpfcp-zoom-1.image
Copy the code
Discussion Group badge
Open jitter. im/ to sign up and create a group that invites developers to join the discussion.
The best way to create a group is to use your username + repository name. It’s easy to identify.
Badge production
Get the address of your discussion group in shields. IO /category/ch… Choose Gitter. Fill in your username and warehouse name information
! [Gitter](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/c208232ae3f6425ab0710cb84072897d~tplv-k3u1fbpfcp-zoom-1.image )Copy the code
Other badge
Open shields. IO to customize many personalized ICONS to make your project more professional.