Skip to content

Commit

Permalink
*: update CI to add static tests (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroProfundis authored Feb 3, 2023
1 parent c112ee3 commit b05d398
Show file tree
Hide file tree
Showing 47 changed files with 352 additions and 138 deletions.
13 changes: 13 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
codecov:
require_ci_to_pass: no
notify:
wait_for_ci: no

coverage:
round: nearest
range: 30..70

ignore:
- "api/types"
- "pkg/models"

57 changes: 57 additions & 0 deletions .github/workflows/reprotest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Check for reproducible build

name: reprotest

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
pull_request:
branches:
- master
- release-*
paths-ignore:
- '**.html'
- '**.md'
- 'LICENSE'
- 'doc/**'
push:
branches:
- release-*
paths-ignore:
- '**.html'
- '**.md'
- 'LICENSE'
- 'doc/**'

jobs:
reprotest:
# The type of runner that the job will run on
runs-on: ubuntu-20.04

strategy:
matrix:
go:
- 1.19.x

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v3

- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}

- name: Install reprotest and prepare
id: prepare_env
run: |
sudo apt-get update && sudo apt-get -qy install reprotest
- name: Check for reproducible build
run: |
sudo reprotest \
"make clean && \
PATH=$GOROOT/bin:$PATH \
BUILD_FLAGS='-trimpath -buildmode=pie -mod=readonly -modcacherw -buildvcs=false' \
make build" \
bin
57 changes: 57 additions & 0 deletions .github/workflows/static-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
name: static-tests

on:
# schedule:
# # times are in UTC
# - cron: '19 21 * * *'
pull_request:
branches:
- master
- release-*
paths-ignore:
- '**.html'
- '**.md'
- 'LICENSE'
- 'doc/**'
push:
branches:
- master
paths-ignore:
- '**.html'
- '**.md'
- 'LICENSE'
- 'doc/**'

jobs:
unit-test:
runs-on: ubuntu-latest
env:
working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
path: go/src/github.com/${{ github.repository }}

- name: Set up Go 1.19
uses: actions/setup-go@v2
with:
go-version: 1.19.x
id: go

- name: make unit-test
working-directory: ${{ env.working-directory }}
run: |
export GOPATH=${GITHUB_WORKSPACE}/go
export PATH=$PATH:$GOPATH/bin
make check
make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
working-directory: ${{ env.working-directory }}
files: ./tests/cov.unit-test.out
flags: unittests
58 changes: 58 additions & 0 deletions .revive.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
ignoreGeneratedHeader = false
severity = "error"
confidence = 0.8
errorCode = -1
warningCode = 0

[rule.atomic]
[rule.blank-imports]
[rule.context-as-argument]
[rule.dot-imports]
[rule.duplicated-imports]
[rule.error-return]
[rule.error-strings]
[rule.error-naming]
[rule.confusing-naming]
[rule.unexported-naming]
[rule.confusing-results]
#[rule.exported]
[rule.if-return]
[rule.var-declaration]
[rule.var-naming]
[rule.range]
[rule.range-val-in-closure]
[rule.range-val-address]
[rule.receiver-naming]
[rule.indent-error-flow]
[rule.superfluous-else]
[rule.modifies-parameter]
[rule.modifies-value-receiver]
[rule.time-naming]
[rule.empty-block]
[rule.empty-lines]
#[rule.early-return]
#[rule.unnecessary-stmt]
#[rule.struct-tag] # https://github.com/mgechev/revive/issues/520
[rule.string-of-int]
[rule.string-format]
[rule.constant-logical-expr]
[rule.bool-literal-in-expr]
[rule.redefines-builtin-id]
[rule.waitgroup-by-value]
[rule.unconditional-recursion]

[rule.cognitive-complexity]
severity = "warning"
arguments =[48]
#[rule.cyclomatic]
# severity = "warning"
# arguments = [48]

[imports-blacklist]
arguments =["crypto/md5", "crypto/sha1", "io/ioutil"]

[rule.defer]
arguments=[["call-chain", "method-call", "return"]]

# This can be checked by other tools like megacheck
[rule.unreachable-code]
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ images: k8s
cp configs/info.toml k8s/images/diag/bin/
docker build --tag "${DOCKER_REPO}/diag:${IMAGE_TAG}" -f k8s/images/diag/Dockerfile k8s/images/diag

test:
$(GO) test -cover ./...
test: unit-test

check: fmt vet check-static
unit-test:
$(GO) test ./... -covermode=count -coverprofile tests/cov.unit-test.out

check: fmt vet lint check-static

fmt:
@echo "gofmt (simplify)"
Expand All @@ -106,11 +108,9 @@ vet:

lint: tests/bin/revive
@echo "linting"
./tests/check/check-lint.sh
@tests/bin/revive -formatter friendly \
-exclude ./k8s/apis/... \
-exclude ./api/types/... \
-config tests/check/revive.toml \
-config .revive.toml \
$(FILES)

tests/bin/revive: tests/check/go.mod
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Language](https://img.shields.io/badge/Language-Go-blue.svg)](https://golang.org/)
[![Go Report Card](https://goreportcard.com/badge/github.com/pingcap/diag)](https://goreportcard.com/badge/github.com/pingcap/diag)
[![Coverage Status](https://codecov.io/gh/pingcap/diag/branch/master/graph/badge.svg)](https://codecov.io/gh/pingcap/diag/)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fpingcap%diag.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fpingcap%2Fdiag?ref=badge_shield)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fpingcap%2Fdiag.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fpingcap%2Fdiag?ref=badge_shield)

# What is diag

Expand Down
1 change: 0 additions & 1 deletion checker/engine/assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ func (w *Wrapper) GetDataSet(namestructs string) ([]*proto.HandleData, error) {
return nil, err
}
chainData = append(chainData, singleclassData)

}
cd := w.CrossData(chainData)
return w.GenHandleData(cd), nil
Expand Down
3 changes: 1 addition & 2 deletions checker/engine/compute_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ func (u *ComputeUnit) Compute() (map[string]interface{}, error) {

func (u *ComputeUnit) Register(dataContext *genginecontext.DataContext) {
// register global func
GlobalRegisterFunc := GetRegisterFunc()
for globalName, globalFunc := range GlobalRegisterFunc {
for globalName, globalFunc := range GetRegisterFunc() {
dataContext.Add(globalName, globalFunc)
}
// register data acting name
Expand Down
4 changes: 2 additions & 2 deletions checker/engine/compute_unit_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package engine

import (
"testing"

"github.com/pingcap/diag/checker/config"
"github.com/pingcap/diag/checker/proto"
"github.com/stretchr/testify/require"
"testing"
)

// rule 105 should return ok if `performance.feedback-probability` is set to 0, otherwise it should return false.
Expand Down Expand Up @@ -68,5 +69,4 @@ func Test_Issue243(t *testing.T) {
assert.Equal(v, true)
}
}

}
5 changes: 4 additions & 1 deletion checker/proto/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,15 @@ func TestJsonDecodeTidbConfigData(t *testing.T) {
t.Fatal("wrong json decode result")
}
// for nullable bool
//revive:disable-next-line:bool-literal-in-expr
if cfg.Log.DisableTimestamp != false {
t.Fatal("wrong json decode result")
}
//revive:disable-next-line:bool-literal-in-expr
if cfg.Log.DisableErrorStack != false {
t.Fatal("wrong json decode result")
}
//revive:disable-next-line:bool-literal-in-expr
if cfg.Log.EnableErrorStack != false {
t.Fatal("wrong json decode result")
}
Expand Down Expand Up @@ -222,7 +225,7 @@ func TestTidbConfigData_GetDeprecatedValueByTagPath(t *testing.T) {
if err := json.Unmarshal(bs, cfg); err != nil {
t.Fatal(err)
}
if cfg.TidbConfig.EnableStreaming == false {
if !cfg.TidbConfig.EnableStreaming {
t.Fatal("wrong")
}
result := cfg.GetValueByTagPath("enable-streaming")
Expand Down
3 changes: 2 additions & 1 deletion checker/proto/tikv_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func TestJsonDecodeTikvConfigData(t *testing.T) {
if len(cfg.LogLevel) == 0 {
t.Fatal("wrong json decode result")
}
if cfg.Gc.EnableCompactionFilter == false {
//revive:disable-next-line:bool-literal-in-expr
if cfg.Gc.EnableCompactionFilter != true {
t.Fatal("wrong json decode result")
}
}
1 change: 0 additions & 1 deletion checker/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ func (w *ResultWrapper) OutputSummary(logger *logprinter.Logger, checkresult map
writer.WriteString(logger, "\n### Configuration Summary")
writer.WriteString(logger, fmt.Sprintf("The configuration rules are all derived from PingCAP’s OnCall Service.\nIf the results of the configuration rules are found to be abnormal, they may cause the cluster to fail.\nThere were **%v** abnormal results.",
abnormalConfigCnt))

} else if ruleType == proto.PerformanceType {
continue
} else if ruleType == proto.DefaultConfigType {
Expand Down
18 changes: 9 additions & 9 deletions checker/sourcedata/slow_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -1047,19 +1047,19 @@ const (

// BytesToString converts the memory consumption to a readable string.
func BytesToString(numBytes int64) string {
GB := float64(numBytes) / float64(byteSizeGB)
if GB > 1 {
return fmt.Sprintf("%v GB", GB)
gb := float64(numBytes) / float64(byteSizeGB)
if gb > 1 {
return fmt.Sprintf("%v GB", gb)
}

MB := float64(numBytes) / float64(byteSizeMB)
if MB > 1 {
return fmt.Sprintf("%v MB", MB)
mb := float64(numBytes) / float64(byteSizeMB)
if mb > 1 {
return fmt.Sprintf("%v MB", mb)
}

KB := float64(numBytes) / float64(byteSizeKB)
if KB > 1 {
return fmt.Sprintf("%v KB", KB)
kb := float64(numBytes) / float64(byteSizeKB)
if kb > 1 {
return fmt.Sprintf("%v KB", kb)
}

return fmt.Sprintf("%v Bytes", numBytes)
Expand Down
2 changes: 0 additions & 2 deletions collector/auditlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type AuditLogCollectOptions struct {
// Desc implements the Collector interface
func (c *AuditLogCollectOptions) Desc() string {
return fmt.Sprintf("%s audit logs of components", c.topoType)

}

// GetBaseOptions implements the Collector interface
Expand Down Expand Up @@ -136,7 +135,6 @@ func (c *AuditLogCollectOptions) Collect(m *Manager, _ *models.TiDBCluster) erro
return err
}
if len(files) != 0 {

err := os.MkdirAll(filepath.Join(c.resultDir, fmt.Sprintf("%s_audit", c.topoType)), 0755)
if err != nil {
return err
Expand Down
Loading

0 comments on commit b05d398

Please sign in to comment.