Skip to content
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

Add github golang lint CI pipeline #899

Merged
merged 7 commits into from
May 22, 2024
Merged

Conversation

dklimpel
Copy link
Contributor

@dklimpel dklimpel commented May 6, 2024

Checklist
  • make test-all (UNIX) passes. CI will also test this
  • unit and/or integration tests are included (if applicable)
  • documentation is changed or added (if applicable)

Description of change

Related to:

It is only a start for using gh pipelines. Add a linting pipeline for go with github actions.

Linting is currently broken in Travis CI:

INFO: Starting build lint
golint . ./cmd/... ./matchers/... ./outputs/... ./resource/... ./system/... ./util/... || true
/bin/sh: golint: command not found

Do not lint for latest-windows. There is a failure if nothing was changed:

only new issues on pull_request: C:\Users\RUNNER~1\AppData\Local\Temp\tmp-6348-vzusUQlR5XIf\pull.patch
  Running [D:\a\_temp\b2f1ab8f-0666-4c9f-8876-3984c905d141\golangci-lint-1.58.0-windows-amd64\golangci-lint run --out-format=github-actions --new-from-patch=C:\Users\RUNNER~1\AppData\Local\Temp\tmp-6348-vzusUQlR5XIf\pull.patch --new=false --new-from-rev=] in [D:\a\goss\goss] ...
  level=error msg="Running error: context loading failed: no go files to analyze: running `go mod tidy` may solve the problem"
  level=error msg="Timeout exceeded: try increasing it by passing --timeout option"

Only lint code changes (only-new-issues: true) and not all code.
Reason is that there are some failures at the code:

Running [/Users/runner/golangci-lint-1.58.0-darwin-arm64/golangci-lint run --out-format=github-actions] in [/Users/runner/work/goss/goss] ...
  Error: error	util/config.go:99:15:	Error return value is not checked (errcheck)
  Error: error	system/service_init.go:75:9:	Error return value of `cmd.Run` is not checked (errcheck)
  Error: error	system/service_systemd.go:38:9:	Error return value of `cmd.Run` is not checked (errcheck)
  Error: error	system/service_systemd.go:57:9:	Error return value of `cmd.Run` is not checked (errcheck)
  Error: error	outputs/json.go:102:16:	Error return value of `json.Unmarshal` is not checked (errcheck)
  Error: error	outputs/junit.go:99:16:	Error return value of `xml.EscapeText` is not checked (errcheck)
  Error: error	serve.go:94:19:	Error return value of `resp.body.WriteTo` is not checked (errcheck)
  Error: error	cmd/goss/goss.go:52:21:	Error return value is not checked (errcheck)
  Error: error	cmd/goss/goss.go:56:19:	Error return value is not checked (errcheck)
  Error: error	system/file.go:48:2:	field `fi` is unused (unused)
  Error: error	system/kernel_param.go:18:2:	field `value` is unused (unused)
  Error: error	matchers/have_patterns.go:149:6:	func `appendMissingStrings` is unused (unused)
  Error: error	resource/resource.go:69:6:	func `validAttrs` is unused (unused)
  Error: error	resource/validate.go:45:2:	const `maxScanTokenSize` is unused (unused)
  Error: error	cmd/goss/goss.go:428:7:	const `msgFormat` is unused (unused)
  Error: error	serve.go:88:2:	S1035: calling net/http.CanonicalHeaderKey on the 'key' argument of (net/http.Header).Set is redundant (gosimple)
  Error: error	serve_test.go:300:2:	S1031: unnecessary nil check around range (gosimple)
  Error: error	resource/resource_list.go:42:30:	S1002: should omit comparison to bool constant, can be simplified to `!e` (gosimple)
  Error: error	resource/resource_list.go:143:30:	S1002: should omit comparison to bool constant, can be simplified to `!e` (gosimple)
  Error: error	resource/resource_list.go:[24](https://github.com/dklimpel/goss/pull/2/checks#step:4:26)4:30:	S1002: should omit comparison to bool constant, can be simplified to `!e` (gosimple)
  Error: error	util/config.go:274:10:	S1005: unnecessary assignment to the blank identifier (gosimple)
  Error: error	system/file.go:170:30:	S1010: should omit second index in slice, s[a:len(s)] is identical to s[a:] (gosimple)
  Error: error	outputs/json.go:[27](https://github.com/dklimpel/goss/pull/2/checks#step:4:29):2:	S1021: should merge variable declaration with assignment on next line (gosimple)
  Error: error	outputs/junit.go:37:2:	S1021: should merge variable declaration with assignment on next line (gosimple)
  Error: error	outputs/nagios.go:34:2:	S1021: should merge variable declaration with assignment on next line (gosimple)
  Error: error	system/service.go:14:2:	S1008: should use 'return strings.ContainsRune(s, '/')' instead of 'if strings.ContainsRune(s, '/') { return true }; return false' (gosimple)
  Error: error	outputs/rspecish.go:46:5:	SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)
  Error: error	outputs/rspecish.go:49:5:	SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)
  Error: error	outputs/rspecish.go:54:5:	SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)
  Error: error	system/file.go:40:2:	SA9004: only the first constant in this group has an explicit type (staticcheck)
  Error: error	resource/addr.go:54:49:	SA10[29](https://github.com/dklimpel/goss/pull/2/checks#step:4:31): should not use built-in type string as key for value; define your own type to avoid collisions (staticcheck)
  Error: error	resource/command.go:52:49:	SA1029: should not use built-in type string as key for value; define your own type to avoid collisions (staticcheck)
  Error: error	resource/dns.go:55:49:	SA1029: should not use built-in type string as key for value; define your own type to avoid collisions (staticcheck)
  Error: error	util/config.go:298:6:	SA6005: should use strings.EqualFold instead (staticcheck)
  Error: error	serve_test.go:69:55:	SA1019: rr.HeaderMap has been deprecated since Go 1.11 and an alternative has been available since Go 1.7: HeaderMap exists for historical compatibility and should not be used. To access the headers returned by a handler, use the Response.Header map as returned by the Result method.  (staticcheck)
  Error: error	serve_test.go:176:55:	SA1019: rr.HeaderMap has been deprecated since Go 1.11 and an alternative has been available since Go 1.7: HeaderMap exists for historical compatibility and should not be used. To access the headers returned by a handler, use the Response.Header map as returned by the Result method.  (staticcheck)
  Error: error	matchers/type_conversion.go:7:2:	SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details.  (staticcheck)

@dklimpel dklimpel requested a review from aelsabbahy as a code owner May 6, 2024 20:18
@aelsabbahy
Copy link
Member

@dklimpel I see lots of amazing PRs from you. It's greatly appreciated and is a considerable amount of work.

If you don't mind, can you open an issue and in there cover the order of PRs and the order they should be reviewed/merged in.

@dklimpel
Copy link
Contributor Author

If you don't mind, can you open an issue and in there cover the order of PRs and the order they should be reviewed/merged in.

I have opend #911

aelsabbahy
aelsabbahy previously approved these changes May 21, 2024
@@ -13,6 +13,12 @@ updates:
- "aelsabbahy"
open-pull-requests-limit: 0

- package-ecosystem: "github-actions"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, didn't know this was a thing!

@aelsabbahy
Copy link
Member

Wow, the macOS build is extremely slow?

Also. I would think for linting Linux (or really any single OS) would be sufficient. I wouldn't think golangci-lint would give different results depending on OS.

@dklimpel
Copy link
Contributor Author

dklimpel commented May 21, 2024

I think Gihub has a few problems today. The job is finished and does not report the status back:

image

@aelsabbahy
Copy link
Member

Ah, yeah the output was confusing me. Either way, I think we can lint on just Linux and save GH some compute time 😄

Thanks for the quick response.

@dklimpel
Copy link
Contributor Author

Same result on linux only :/

@aelsabbahy
Copy link
Member

Awesome, thank you. Appreciate the permission lockdown =)

@aelsabbahy aelsabbahy merged commit 7ca5459 into goss-org:master May 22, 2024
2 checks passed
@dklimpel dklimpel deleted the lint_ci branch May 22, 2024 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants