-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CI] add basic static check, complie, test #292
Conversation
@357447923 麻烦先尝试让 CI 跑过 :) |
c0279c7
to
aec00ff
Compare
ok,我已经解决了CI不通过的问题了,麻烦您再试试看 |
.golangci.yml
Outdated
- gosimple | ||
text: "S1009:" | ||
# Fix found issues (if it's supported by the linter). | ||
fix: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里需要一个换行。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里需要一个换行。
是在最后加一个换行吗?抱歉,我不是很理解这个“需要一个换行”,麻烦您跟我说一下是在哪一行加上。
cli/cli/cli.go
Outdated
@@ -143,7 +143,7 @@ func (curveadm *CurveAdm) init() error { | |||
if err := log.Init(config.GetLogLevel(), logpath); err != nil { | |||
return errno.ERR_INIT_LOGGER_FAILED.E(err) | |||
} else { | |||
log.Info("Init logger success", | |||
_ = log.Info("Init logger success", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @357447923 ,在目前的检查工具里面,赋值这个返回值是必须的是吗?有没有参数可以跳过该强制限制,因为我觉得这样的写法是比较常见的,或者说如果不赋值返回值会带来哪些副作用呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @357447923 ,在目前的检查工具里面,赋值这个返回值是必须的是吗?有没有参数可以跳过该强制限制,因为我觉得这样的写法是比较常见的,或者说如果不赋值返回值会带来哪些副作用呢?
按照目前的配置来说,这个赋值返回值是必须的。是有跳过该限制的参数,不过可能得找一下有没有粒度更小的处理方法。我之前加上过一次这个参数,它会把另外的一些问题也进行忽略。
我最近来找一下这个处理方法。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @357447923 ,在目前的检查工具里面,赋值这个返回值是必须的是吗?有没有参数可以跳过该强制限制,因为我觉得这样的写法是比较常见的,或者说如果不赋值返回值会带来哪些副作用呢?
你的意思是把errcheck给关闭还是说只忽略打印日志的这种情况?
另外值得一提的是,在修改之后,咱们有尝试部署一个 BS/FS 集群并挂载客户端来进行测试吗? |
还没有尝试。等我最近的一些急事做完后,我就来进行测试。 |
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation. |
b0a9e4d
to
75de135
Compare
cli/command/deploy.go
Outdated
@@ -223,7 +223,7 @@ func genDeployPlaybook(curveadm *cli.CurveAdm, | |||
role := DEPLOY_FILTER_ROLE[step] | |||
config = curveadm.FilterDeployConfigByRole(config, role) | |||
} | |||
n := len(config) | |||
var n int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的代码逻辑好像改变了,n
没有默认值了,应该是有问题的~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的代码逻辑好像改变了,
n
没有默认值了,应该是有问题的~
您好,不过我看了下,这个值似乎只在下面的一小段代码块中使用,并且是使用之前会进行赋值。所以ci就提示我说这个赋值冗余
var n int
if DEPLOY_LIMIT_SERVICE[step] > 0 {
n = DEPLOY_LIMIT_SERVICE[step]
config = config[:n]
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的代码逻辑好像改变了,
n
没有默认值了,应该是有问题的~您好,不过我看了下,这个值似乎只在下面的一小段代码块中使用,并且是使用之前会进行赋值。所以ci就提示我说这个赋值冗余
var n int if DEPLOY_LIMIT_SERVICE[step] > 0 { n = DEPLOY_LIMIT_SERVICE[step] config = config[:n] }
那这个 n 是不是可以不用定义,直接赋值~
// multi-configs | ||
case []*hosts.HostConfig: | ||
c.ctype = TYPE_CONFIG_HOST | ||
c.hcs = configs.([]*hosts.HostConfig) | ||
c.hcs = configs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里类型会做自动转换是吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里类型会做自动转换是吗?
把switch configs.(type) 改为 switch configs := configs.(type) 之后,case语句下的configs就自动转为对应类型了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里类型会做自动转换是吗?
把switch configs.(type) 改为 switch configs := configs.(type) 之后,case语句下的configs就自动转为对应类型了
💯
internal/playbook/playbook.go
Outdated
@@ -91,7 +91,7 @@ func (p *Playbook) run(steps []*PlaybookStep) error { | |||
return err | |||
} | |||
|
|||
isLast := (i == len(steps)-1) | |||
isLast := i == len(steps)-1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为什么要把括号去掉,加上括号可能更好理解一点~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为什么要把括号去掉,加上括号可能更好理解一点~
可能是我误删了,我记得还有好几个类似场景,但是ci是通过的
case *topology.DeployConfig: | ||
dc := cfg.(*topology.DeployConfig) | ||
dc := cfg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
75de135
to
794d342
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
.golangci.yml
Outdated
- loopclosure | ||
|
||
staticcheck: | ||
checks: ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-SA4006"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is default value? no need to config here if so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is default value? no need to config here if so.
Yes, you're right. These configs are redundant. I had already read official document of golangci-lint just now and made ensure my configs was default value. So I think these configs can be removed. Need I remove them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, you can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, you can.
Oh,no. After my test remove them. I recalled why I didn't use the default values directly because some of the checks I think them were not necessary. For example, MD5 cannot be used (because golangci-lint would think it is used for encryption, and it believes that weak encryption should not be used for encryption), but in reality, when we use MD5, it may not necessarily be used for encryption.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what happend after remove the configuration for our programe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what happend after remove the configuration for our programe.
I paste all my local environment error messages here:
internal/task/task/checker/network.go:142:17: G601: Implicit memory aliasing in for loop. (gosec)
Destination: &address,
^
internal/task/task/checker/kernel_test.go:50:32: G601: Implicit memory aliasing in for loop. (gosec)
lambda := checkKernelVersion(&t.version, &dc)
^
internal/utils/common.go:30:2: G501: Blocklisted import crypto/md5: weak cryptographic primitive (gosec)
"crypto/md5"
^
internal/utils/common.go:205:7: G401: Use of weak cryptographic primitive (gosec)
m := md5.New()
^
internal/utils/common.go:220:9: G204: Subprocess launched with a potential tainted input or cmd arguments (gosec)
return exec.Command(args[0], args[1:]...)
^
internal/utils/common.go:242:22: G404: Use of weak random number generator (math/rand instead of crypto/rand) (gosec)
b[i] = letterRunes[rand.Intn(len(letterRunes))]
^
cli/command/exec.go:51:4: SA4006: this value of args
is never used (staticcheck)
args = args[:1]
^
internal/common/common.go:73:2: G101: Potential hardcoded credentials (gosec)
KEY_CHECK_KERNEL_MODULE_NAME = "CHECK_KERNEL_MODULE_NAME"
^
internal/build/debug.go:34:2: G101: Potential hardcoded credentials (gosec)
DEBUG_CURVEADM_CONFIGURE = "DEBUG_CURVEADM_CONFIGURE"
^
internal/tools/ssh.go:88:9: G204: Subprocess launched with a potential tainted input or cmd arguments (gosec)
return exec.Command(items[0], items[1:]...), nil
^
internal/tools/upgrade.go:105:9: G204: Subprocess launched with a potential tainted input or cmd arguments (gosec)
cmd := exec.Command("/bin/bash", "-c", fmt.Sprintf("curl -fsSL %s | bash", URL_INSTALL_SCRIPT))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what happend after remove the configuration for our programe.
Could you tell me which problems need to be ignored? I will try to handle those need to fix.
.golangci.yml
Outdated
|
||
bidichk: | ||
# The following configurations check for all mentioned invisible unicode runes. | ||
# All runes are enabled by default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All runes are enabled by default? So no need config here also?
.golangci.yml
Outdated
pop-directional-isolate: true | ||
|
||
|
||
issues: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the work of issue here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the work of issue here?
Only bidichk can be removed. Removing it has no impact.
.golangci.yml
Outdated
text: "S1009:" | ||
|
||
# Fix found issues (if it's supported by the linter). | ||
fix: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix is mean that lint rune can fix problem that already been detected? Is it possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix is mean that lint rune can fix problem that already been detected? Is it possible?
Can only solve a few problems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think can take a closer look at the configuration options and whether the default configuration is enough. The .golangci.yaml is necessary? for example, gosec and govet why check these other than check all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think can take a closer look at the configuration options and whether the default configuration is enough. The .golangci.yaml is necessary? for example, gosec and govet why check these other than check all.
The. golangci.yaml file is required as it is a configuration for golangci-lint. Although golangci-lint has many default configurations, but not every configuration is suitable for all projects. Many default configurations burden developers, such as forcing errcheck, ensure project has no unused functions and variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think can take a closer look at the configuration options and whether the default configuration is enough. The .golangci.yaml is necessary? for example, gosec and govet why check these other than check all.
Using the default configuration is not bad, but it covers nearly everything. It can lead to some issues, such as not being able to use MD5, Rand and also so. If you find all of the Gosec checks acceptable, I will use the default configs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, you are right. We are not familiar with this configuration also, but we can see from the error report above that some errors need to be handled. For example, unused
plugin should report as an error or warning, but some may not be necessary. For example, errorcheck plugin in staticcheck may not always be necessary, for gosec, G501, G401 may be etc. You can run once according to default configuration, see which ones will report errors for our program, but which of these errors can be ignored, and then enable or disable them may be more effective.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, you are right. We are not familiar with this configuration also, but we can see from the error report above that some errors need to be handled. For example,
unused
plugin should report as an error or warning, but some may not be necessary. For example, errorcheck plugin in staticcheck may not always be necessary, for gosec, G501, G401 may be etc. You can run once according to default configuration, see which ones will report errors for our program, but which of these errors can be ignored, and then enable or disable them may be more effective.
Good suggestion! I may find more necessary configs after running project and reaing official document. Please waiting for the change of '.golangci.yaml'
.golangci.yml
Outdated
text: "SA1019:" | ||
- linters: | ||
- gosimple | ||
text: "S1009:" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S1009 means that redundant nil check on slices and seems to belong to staticcheck, but why exclude it? Also, SA1019. we can fix it now if we use deprecated function If it's easy to modify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S1009 means that redundant nil check on slices and seems to belong to staticcheck, but why exclude it? Also, SA1019. we can fix it now if we use deprecated function If it's easy to modify.
You are right. they don't seem too difficult to modify. I will now attempt to make some changes and see if I can remember why I configured them that way originally
You can modify the Makefile for example: build: fmt vet
debug: fmt vet
fmt:
go fmt ./...
vet:
go vet ./... Then we can lookup the problem in compile phase . |
.golangci.yml
Outdated
- bidichk | ||
disable: | ||
# ignore unused check | ||
- unused |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If go vet is executed, unused functions or variables will no longer appear here. Enable it or delete it directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If go vet is executed, unused functions or variables will no longer appear here. Enable it or delete it directly.
Are you suggesting that I remove the 'unused' configuration and remove unused variables and functions in this project code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but you seems to have deleted them in code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but you seems to have deleted them in code?
no, this rule 'unused' considers fields in a struct and functions belonging to a struct as well. So, I'm unsure if I should remove them, as I don't know if they are useful in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they can be removed.
Okey, I had removed them just now.
f3fd9f0
to
c6f9757
Compare
Signed-off-by: xiaoming <[email protected]> [fix]playbook: fix format related variables position Signed-off-by: sjf <[email protected]> [fix] add support for recognizing kernel versions like "3.15.0_.*" Signed-off-by: jyf111 <[email protected]> support enable etcd auth Signed-off-by: wanghai01 <[email protected]> Feature: podman can be an alternative container engine Signed-off-by: caoxianfei1 <[email protected]> bugfix: docker ps specify both --format and --quiet will warning since v24.0.0. WARNING: Ignoring custom format, because both --format and --quiet are set. Signed-off-by: caoxianfei1 <[email protected]> change replicas to instances Signed-off-by: tec-rubbish maker <[email protected]> change topology variable change service_replicas_sequence and format_replicas_sequence to service_instances_sequence and format_instances_sequence Signed-off-by: tec-rubbish maker <[email protected]> fix the worng instances Signed-off-by: tec-rubbish maker <[email protected]> mistake Signed-off-by: tec-rubbish maker <[email protected]> Update cli/command/status.go Signed-off-by: Wine93 <[email protected]> [fix] older versions of the ss command do not have the --no-header option solution: execute the ss command in a temporary container to precheck for ports in use instead Signed-off-by: jyf111 <[email protected]> Signed-off-by: xiaoming <[email protected]>
lgtm. |
No description provided.