ci: refine the Github action workflows

This commit is contained in:
Andy Pan 2022-11-20 11:17:50 +08:00
parent b604f7dc64
commit b4dedcd523
6 changed files with 131 additions and 139 deletions

View File

@ -1,72 +0,0 @@
name: Tests
on:
push:
branches:
- master
- dev
- test
paths-ignore:
- '**.md'
pull_request:
branches:
- master
paths-ignore:
- '**.md'
env:
GO111MODULE: on
GOPROXY: "https://proxy.golang.org"
jobs:
test:
name: Go-Test
strategy:
fail-fast: false
matrix:
go: [1.17.x, 1.18.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os}}
steps:
- name: Installing Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- name: Checkout code
uses: actions/checkout@v2
- name: Print Go environment
id: vars
run: |
printf "Using go at: $(which go)\n"
printf "Go version: $(go version)\n"
printf "\n\nGo environment:\n\n"
go env
printf "\n\nSystem environment:\n\n"
env
# Calculate the short SHA1 hash of the git commit
echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
echo "::set-output name=go_cache::$(go env GOCACHE)"
- name: Cache go modules
uses: actions/cache@v2
with:
path: |
${{ steps.vars.outputs.go_cache }}
~/go/pkg/mod
key: ${{ runner.os }}-${{ matrix.go }}-go-ci-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-${{ matrix.go }}-go-ci
- name: Run unit tests
run: go test -race -coverprofile=coverage -covermode=atomic -v
- name: Upload code coverage report to Codecov
uses: codecov/codecov-action@v2
with:
file: ./coverage
flags: unittests
verbose: true
name: codecov-ants

View File

@ -1,53 +1,62 @@
name: CodeQL
name: "Code scanning"
on:
push:
branches:
- master
- dev
- test
paths-ignore:
- '**.md'
pull_request:
branches:
- master
paths-ignore:
- '**.md'
- dev
schedule:
- cron: '0 5 * * 6'
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
- cron: '30 4 * * 6'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
CodeQL-Build:
# CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
runs-on: [ubuntu-latest, macos-latest]
permissions:
# required for all workflows
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: go
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below).
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
# ✏️ If the Autobuild fails above, remove it and uncomment the following
# three lines and modify them (or add more) to build your code if your
# project uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2

View File

@ -1,27 +0,0 @@
name: Lint
on:
push:
branches:
- master
- dev
- test
paths-ignore:
- '**.md'
pull_request:
branches:
- master
paths-ignore:
- '**.md'
jobs:
golangci:
name: Golangci-Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.40
args: -E goimports -E gocritic -E misspell -E revive

98
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,98 @@
name: Run tests
on:
push:
branches:
- master
- dev
- test
paths-ignore:
- '**.md'
pull_request:
branches:
- master
paths-ignore:
- '**.md'
env:
GO111MODULE: on
GOPROXY: "https://proxy.golang.org"
jobs:
lint:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
name: Run golangci-lint
runs-on: ${{ matrix.os }}
steps:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '^1.16'
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup and run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.50.1
args: -v -E gofumpt -E gocritic -E misspell -E revive -E godot
test:
needs: lint
strategy:
fail-fast: false
matrix:
go: [1.16, 1.17, 1.18, 1.19]
os: [ubuntu-latest, macos-latest, windows-latest]
name: Go ${{ matrix.go }} @ ${{ matrix.os }}
runs-on: ${{ matrix.os}}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '^1.16'
- name: Print Go environment
id: go-env
run: |
printf "Using go at: $(which go)\n"
printf "Go version: $(go version)\n"
printf "\n\nGo environment:\n\n"
go env
printf "\n\nSystem environment:\n\n"
env
# Calculate the short SHA1 hash of the git commit
echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "GO_CACHE=$(go env GOCACHE)" >> $GITHUB_OUTPUT
- name: Cache go modules
uses: actions/cache@v3
with:
path: |
${{ steps.go-env.outputs.GO_CACHE }}
~/go/pkg/mod
key: ${{ runner.os }}-${{ matrix.go }}-go-ci-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-${{ matrix.go }}-go-ci
- name: Run unit tests
run: go test -v -race -coverprofile="codecov.report" -covermode=atomic
- name: Upload code coverage report to Codecov
uses: codecov/codecov-action@v3
with:
file: ./codecov.report
flags: unittests
name: codecov-ants
fail_ci_if_error: true
verbose: true

View File

@ -48,9 +48,6 @@ const (
)
var (
//
//--------------------------Error types for the Ants API------------------------------
// ErrLackPoolFunc will be returned when invokers don't provide function for pool.
ErrLackPoolFunc = errors.New("must provide function for pool")
@ -69,8 +66,6 @@ var (
// ErrTimeout will be returned after the operations timed out.
ErrTimeout = errors.New("operation timed out")
//---------------------------------------------------------------------------
// workerChanCap determines whether the channel of a worker should be a buffered channel
// to get the best performance. Inspired by fasthttp at
// https://github.com/valyala/fasthttp/blob/master/workerpool.go#L139

View File

@ -38,12 +38,6 @@ const (
_ = 1 << (10 * iota)
KiB // 1024
MiB // 1048576
// GiB // 1073741824
// TiB // 1099511627776 (超过了int32的范围)
// PiB // 1125899906842624
// EiB // 1152921504606846976
// ZiB // 1180591620717411303424 (超过了int64的范围)
// YiB // 1208925819614629174706176
)
const (
@ -189,9 +183,7 @@ func TestAntsPoolWithFuncGetWorkerFromCachePreMalloc(t *testing.T) {
t.Logf("memory usage:%d MB", curMem)
}
//-------------------------------------------------------------------------------------------
// Contrast between goroutines without a pool and goroutines with ants pool.
//-------------------------------------------------------------------------------------------
func TestNoPool(t *testing.T) {
var wg sync.WaitGroup
@ -232,9 +224,6 @@ func TestAntsPool(t *testing.T) {
t.Logf("memory usage:%d MB", curMem)
}
//-------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------
func TestPanicHandler(t *testing.T) {
var panicCounter int64
var wg sync.WaitGroup