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: on:
push: push:
branches: branches:
- master - master
- dev - dev
- test
paths-ignore:
- '**.md'
pull_request: pull_request:
branches: branches:
- master - master
paths-ignore: - dev
- '**.md'
schedule: 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: jobs:
analyze: CodeQL-Build:
name: Analyze # CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
runs-on: ubuntu-latest runs-on: [ubuntu-latest, macos-latest]
permissions:
# required for all workflows
security-events: write
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v3
with: 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 fetch-depth: 2
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - 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). # 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) # If this step fails, then you should remove it and run the build manually (see below).
- name: Autobuild - name: Autobuild
uses: github/codeql-action/autobuild@v1 uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell. # 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 # ✏️ If the Autobuild fails above, remove it and uncomment the following
# and modify them (or add more) to build your code if your project # three lines and modify them (or add more) to build your code if your
# uses a compiled language # project uses a compiled language
#- run: | #- run: |
# make bootstrap # make bootstrap
# make release # make release
- name: Perform CodeQL Analysis - 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 ( var (
//
//--------------------------Error types for the Ants API------------------------------
// ErrLackPoolFunc will be returned when invokers don't provide function for pool. // ErrLackPoolFunc will be returned when invokers don't provide function for pool.
ErrLackPoolFunc = errors.New("must 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 will be returned after the operations timed out.
ErrTimeout = errors.New("operation timed out") ErrTimeout = errors.New("operation timed out")
//---------------------------------------------------------------------------
// workerChanCap determines whether the channel of a worker should be a buffered channel // workerChanCap determines whether the channel of a worker should be a buffered channel
// to get the best performance. Inspired by fasthttp at // to get the best performance. Inspired by fasthttp at
// https://github.com/valyala/fasthttp/blob/master/workerpool.go#L139 // https://github.com/valyala/fasthttp/blob/master/workerpool.go#L139

View File

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