From b4dedcd5239337ccec769608803a7a1133814976 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sun, 20 Nov 2022 11:17:50 +0800 Subject: [PATCH] ci: refine the Github action workflows --- .github/workflows/ci.yml | 72 -------------------------- .github/workflows/codeql.yml | 57 ++++++++++++--------- .github/workflows/lint.yml | 27 ---------- .github/workflows/test.yml | 98 ++++++++++++++++++++++++++++++++++++ ants.go | 5 -- ants_test.go | 11 ---- 6 files changed, 131 insertions(+), 139 deletions(-) delete mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 25f378a..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -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 - diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index ff618db..da1678e 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -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 + # make bootstrap + # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 \ No newline at end of file + uses: github/codeql-action/analyze@v2 \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 99e2aac..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..6c8d1e6 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 + diff --git a/ants.go b/ants.go index 3439c48..df77ace 100644 --- a/ants.go +++ b/ants.go @@ -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 diff --git a/ants_test.go b/ants_test.go index bb4104f..7342542 100644 --- a/ants_test.go +++ b/ants_test.go @@ -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