Commit Graph

29 Commits

Author SHA1 Message Date
Tim Hockin
a0215badb8
Change pushd $d; go ...; popd to go -C $d ...
Just an annoyance in reading these scripts.
2024-03-02 14:40:10 -08:00
Tim Hockin
d61f299614
Call verify_go_version at the END of setup_env
Prior to this it would download Go, setup the environment, then (maybe)
download Go again.

I renamed verify_go_version to be internal and fixed all callers.
2024-02-29 22:06:56 -08:00
Tim Hockin
e84adf611f
Remove references to "GO111MODULE" 2024-02-29 22:06:55 -08:00
Tim Hockin
530c4352fb
Rename new::setup_env back to setup_env 2024-02-29 22:06:44 -08:00
Tim Hockin
bad67dc973
Fix golangci-lint for workspaces 2024-02-29 22:06:07 -08:00
Tim Hockin
58ab5eea89
Remove some references to GOPATH 2024-02-29 22:05:59 -08:00
Tim Hockin
f47e0cb779
Rename KUBE_OUTPUT_BINPATH -> KUBE_OUTPUT_BIN
"...PATH" doesn't add anything and confuses it with KUBE_OUTPUT_SUBPATH.
2024-02-29 00:22:14 -08:00
Patrick Ohly
b450224c12 golangci-lint: inline logcheck configuration
This has the advantage that the golangci-lint cache gets invalidated
automatically each time the logcheck config changes.
2023-12-14 20:21:58 +01:00
Patrick Ohly
49084fe577 golangci-lint: logcheck v0.7.0, golangci-lint v1.55.2
This adds support for the new golangci-lint plugin interface and settings
mechanism.
2023-12-14 20:21:19 +01:00
Kubernetes Prow Robot
e8c265169b
Merge pull request #121478 from pohly/golangci-lint-message
verify-golangci-lint.sh: clarify intended usage of warnings
2023-12-13 21:26:45 +01:00
Patrick Ohly
d20edf697a verify-golangci-lint.sh: support arbitrary GOBIN
The in-tree configs use a relative path to find logcheck.so. This is useful
because then the invocation of golangci-lint also works outside of the script.
But when running with a containerized build, GOBIN points somewhere else. For
that case, a temporary copy of the configuration has to be created with an
absolute path.
2023-10-25 09:25:53 +02:00
Patrick Ohly
ae5bf8e4c6 verify-golangci-lint.sh: clarify intended usage of warnings
Contributors have created PRs because the linter found them. That is often not
necessary and should be discussed before working on a PR.

While at it, output formatting gets updated a bit (extra blank lines, wording).
2023-10-24 14:42:14 +02:00
Patrick Ohly
ce9e668a93 golangci-lint: suppress one issue, demote others to "hints"
The voting in https://github.com/kubernetes/kubernetes/issues/117288 led to
one check that got rejected ("ifElseChain: rewrite if-else to switch
statement") and several that are "nice to know".

golangci-lint's support for issue "severity" is too limited to identify "nice
to know" issues in the output (filtering is only by linter without considering
the issue text; not part of text output). Therefore a third configuration gets
added which emits all issues (must fix and nits). The intention is to use
the "strict" configuration in pull-kubernetes-verify and the "hints"
configuration in a new non-blocking pull-kubernetes-linter-hints.

That way, "must fix" issues will block merging while issues that may be useful
will show up in a failed optional job. However, that job then also contains
"must fix" issues, partly because filtering out those would make the
configuration a lot larger and is likely to be unreliably (all "must fix"
issues would need to be identified and listed), partly because it may be useful
to have all issues in one place.

The previous approach of manually keeping two configs in sync with special
comments didn't scale to three configs. Now a single golangci.yaml.in with
text/template constructs contains the source for all three configs. A new
simple CLI frontend for text/template (cmd/gotemplate) is used by
hack/update-golangci-lint-config.sh to generate the three flavors.
2023-08-22 20:39:23 +02:00
Patrick Ohly
9742e276b9 update to golangci-lint v1.54.1 + go-ruleguard v0.4.0
That release is the first one with official support for Go 1.21. go-ruleguard
must be >= 0.3.20 because of
https://github.com/quasilyte/go-ruleguard/issues/449 with Go
1.21. golangci-lint itself doesn't depend on a recent enough release yet, so
this was done manually.
2023-08-16 09:07:30 +02:00
Patrick Ohly
dbbb21469f verify: pick relevant lines from verify-golangci-lint.sh as failure message
When sh2ju.sh was called to generate the junit_verify.xml, it used to include
the entire output of a failed script twice: once as failure message, once as
log output.

This output can be large and often the actual failure isn't near the top, but
rather at the end or (in the case of the different golangci-lint invocations)
embedded in the log. This makes them hard to see at a glance when looking at
the Prow result page for a job.

Now a verify script can prefix relevant lines with "ERROR: " and then only
those lines are used as failure message in JUnit, without that prefix.

That string was chosen because Prow itself also then picks up those lines when
viewing the entire build log and it is unlikely that some script prints such
lines when they are not meant to be part of the failure.

If some script outputs no such lines, "see stderr for details" is used as
failure message. This is better than before because it avoids the redundancy.
2023-06-02 15:37:50 +02:00
Patrick Ohly
04700e97d3 hack: prepare for strict golangci-lint in pull-verify-kubernetes
The long-term goal is that when "make verify" is invoked in pull job, it will
also run golangci-lint with the strict configuration and write an
$ARTIFACTS/golangci-lint-githubactions.log file with GitHub actions
annotations. How to get those published for the GitHub PR is open.

When "make verify" is invoked manually or in any other job, the stricter check
will be skipped. That works because "PR_NUMBER" is only set for pre-merge
jobs (https://github.com/kubernetes/test-infra/blob/master/prow/jobs.md#job-environment-variables).

Because strict linting is still new and might not be useful without a better
UI (= GitHub annotations), this PR does not fully enable the integration into
"make verify". Instead, the new verify-golangci-lint-pr.sh is excluded from it
and needs to be run in a separate job.
2023-03-07 19:38:32 +01:00
Patrick Ohly
78a3430606 golangci-lint: support stricter checking in new code
It is useful to check new code with a stricter configuration because we want it
to be of higher quality. Code reviews also become easier when reviewers don't
need to point out inefficient code manually.

What exactly should be enabled is up for debate. The current config uses the
golangci-lint defaults plus everything that is enabled explicitly by the normal
golangci.yaml, just to be on the safe side.
2023-03-07 19:37:57 +01:00
Patrick Ohly
fd8523aa08 golangci-lint: enable running specific linters
To run just a specific linter based on command line flags, the default
configuration needs to be disabled (because it would enable additional ones)
and then command line flags must be passed through to "golangci-lint run".

For example, to lint with just "go vet" in verbose mode, use:

    verify-golangci-lint.sh -c none -- --disable-all --enable=govet -v
2023-03-03 07:51:04 +01:00
Patrick Ohly
cf2e6291d1 hack: move golangci-lint config files
Because the script now explicitly selects the configuration file, the files no
longer have to be in the root directory. Having them in hack without the
leading dot is better because they then have the same owners as the script and
are more visible.

The downside is that manual invocations of golangci-lint without the parameter
no longer work.
2023-02-28 17:22:31 +01:00
Patrick Ohly
2d513e1330 golangci-lint: show more information about actual invocation
Both env variables and parameters are relevant for users who want to invoke the
command directly or follow how it is used.
2023-02-28 17:21:52 +01:00
Davanum Srinivas
a2408f39c7
[golang] Fix things commented out in 1.19rc2
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2022-08-04 10:27:09 -04:00
Davanum Srinivas
6c0a434db0
Try disabling logcheck for golang 1.19rc2
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2022-07-26 13:14:05 -04:00
Patrick Ohly
0284c6c06e hack/tools: use logcheck v0.1.0 from sigs.k8s.io/logtools/logcheck
The code was moved out of k8s.io/klog into its own repo with proper
tagging. Functionally there is no difference.
2022-06-14 17:27:16 +02:00
Patrick Ohly
17e3c555c5 hack: integrate logcheck into golangci-lint
Running logcheck as part of golangci-lint has several advantages:
- faster checking because finding files and parsing is shared
  with other linters
- gets rid of the complex and buggy
  hack/verify-structured-logging.sh (https://github.com/kubernetes/kubernetes/issues/106746)
- support for // nolint:logcheck
- works with Go 1.18
2022-03-24 11:21:03 +01:00
Antonio Ojea
272b31da50 use golangci-lint and remove legacy verify-staticcheck.sh 2021-11-17 13:58:53 +01:00
Tim Hockin
3bca4e6d67 Move golangci-lint config to a file
Make verify-golangci-lint.sh work across modules and take an optional
argument for a package.
2021-11-17 08:56:57 +01:00
Hanna Lee
7ea01c0bdb Add staticcheck to verify-golangci-lint.sh 2021-11-17 08:56:01 +01:00
Supriya Premkumar
e52e5e486c
Adds ineffassign to GO linter script.
Changes:
 - Enables ineffassign check in the verify scripts.
 - Fixes lint errs.
2021-03-03 08:28:10 -08:00
Davanum Srinivas
865fd2f04f
Use golangci-lint to find unused/dead code
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2021-02-19 12:12:02 -05:00