Fix test scripts because -race and -skip don't coexist when running g… #66
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Go | |
on: | |
push: | |
branches: [ master ] | |
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) | |
# 需要注意的是: | |
# 1. 并行测试的限制:仅当测试函数使用 t.Parallel() 来标记它们时,-parallel 参数才会生效。否则,测试函数会按顺序执行。 | |
# 2. CPU 核心数:-parallel 的值不应超过可用 CPU 核心数。Go 运行时会自动调整并行度来避免过载。 | |
# | |
# run: go test -cover -v ./... | |
# html格式查看cover信息: https://blog.golang.org/cover | |
# go test -covermode=count -coverprofile=count.out ./... && go tool cover -html=count.out | |
# | |
# 从go1.20开始test子命令才支持-skip参数,但是test的-skip和-race不能同时使用 | |
run: | | |
go vet ./... | |
nproc --all || sysctl -n hw.ncpu || grep -c ^processor /proc/cpuinfo || date | |
if [[ "${{ matrix.go }}" < "1.20" ]]; then | |
time SKIP_TEST_SEND_MAIL=1 go test -cover -v ./... && echo done | |
else | |
time go test -skip "^TestSendMail$" -cover -v ./... && echo done | |
fi | |
time SKIP_TEST_SEND_MAIL=1 go test -race -cover -v ./... && echo done | |
# golangci-lint run #golangci-lint run --enable-all 如果手动执行,需要提前下载golangci-lint | |
# CI是通过golangci-lint.yml配置文件启用的 | |
# -count=1可以跳过缓存(默认情况下,第一次执行过了,第二次就会有缓存) | |
# run: go test -count=1 |