Skip to content

Update CI config

Update CI config #59

Workflow file for this run

name: Go
on:
push:
branches: [ master , develop ]
pull_request:
branches: [ master ]
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.18' , '1.19' , '1.20' , '1.21' , '1.22']
# https://github.com/actions/setup-go?tab=readme-ov-file#using-stableoldstable-aliases
# If stable is provided, action will get the latest stable version from the go-versions repository manifest.
# If oldstable is provided, when current release is 1.19.x, action will resolve version as 1.18.x, where x is the latest patch release.
# go: [stable, oldstable]
steps:
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v5
with:
# go-version: ^1.13
go-version: ${{ matrix.go }}
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Get dependencies
run: |
go version
go get -v -t -d ./...
# - name: Build
# run: go build -v .
- name: Test
# 在并发情况下,同时运行的测试的数量默认取决于 GOMAXPROCS。它可以通过 -parallel n 被指定(go test -parallel 4)
# run: go test -cover -v ./...
# 从go1.20开始test子命令才支持-skip参数
run: |
if [[ "${{ matrix.go-version }}" < "1.20" ]]; then
go test -cover -v ./...
go test -race -v ./...
else
go test -skip "^TestSendMail$" -cover -v ./...
go test -race -skip "^TestSendMail$" -skip "^TestDataRaceError$" -v ./...
fi
go vet ./...
# golangci-lint run #golangci-lint run --enable-all 如果手动执行,需要提前下载golangci-lint
# CI是通过golangci-lint.yml配置文件启用的
- name: Test Parallel
# 在并发情况下,同时运行的测试的数量默认取决于 GOMAXPROCS。它可以通过 -parallel n 被指定(go test -parallel 4)
run: go test -parallel 4 -cover -v ./...
# html格式查看cover信息: https://blog.golang.org/cover
# go test -covermode=count -coverprofile=count.out ./... && go tool cover -html=count.out
# -count=1可以跳过缓存(默认情况下,第一次执行过了,第二次就会有缓存)
# run: go test -count=1