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

project-infra: add make targets lint and coverage #3825

Merged
merged 6 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
linters:
# initially we disable all linters, since this is an old code base with quite a lot of issues
disable-all: true
enable:
- gocyclo
# - staticcheck
# - unused
# - ineffassign
# - govet
# - gosimple
# - errcheck
#linters-settings:
# gocyclo:
# min-complexity: 10
34 changes: 32 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,25 @@ querier := robots/cmd/release-querier
kubevirtci := robots/cmd/kubevirtci-bumper
bazelbin := bazelisk

.PHONY: all clean deps-update gazelle-update-repos update-labels $(limiter) $(flake-report-writer) $(querier) $(kubevirtci) $(flake-issue-creator)
ifndef GOLANGCI_LINT_VERSION
GOLANGCI_LINT_VERSION=v1.62.2
export GOLANGCI_LINT_VERSION
endif
ifndef ARTIFACTS
ARTIFACTS=/tmp/artifacts
export ARTIFACTS
endif
ifndef COVERAGE_OUTPUT_PATH
COVERAGE_OUTPUT_PATH=${ARTIFACTS}/coverage.html
export COVERAGE_OUTPUT_PATH
endif

.PHONY: all clean deps-update gazelle-update-repos update-labels install-metrics-binaries lint $(limiter) $(flake-report-writer) $(querier) $(kubevirtci) $(flake-issue-creator)
all: deps-update $(limiter) $(flake-report-writer) $(querier) $(kubevirtci) $(flake-issue-creator)

clean:
clean: install-metrics-binaries
$(bazelbin) clean
golangci-lint cache clean

$(limiter) $(flake-report-writer) $(querier) $(kubevirtci) $(flake-issue-creator): deps-update
$(MAKE) --directory=$@
Expand Down Expand Up @@ -40,3 +54,19 @@ test:

update-labels:
./hack/labels/update.sh

install-metrics-binaries:
if ! command -V golangci-lint; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GOPATH}/bin ${GOLANGCI_LINT_VERSION} ; fi

lint: install-metrics-binaries
./hack/lint.sh

coverage:
if ! command -V covreport; then go install github.com/cancue/covreport@latest; fi
go test \
./external-plugins/... \
./releng/... \
./robots/... \
-coverprofile=/tmp/coverage.out
mkdir -p ${ARTIFACTS}
covreport -i /tmp/coverage.out -o ${COVERAGE_OUTPUT_PATH}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,46 @@ presubmits:
memory: "4Gi"
securityContext:
runAsUser: 0
- always_run: false
cluster: kubevirt-prow-control-plane
decorate: true
name: pull-project-infra-lint
run_if_changed: "external-plugins/.*|releng/.*|robots/.*"
spec:
containers:
- args:
- make lint
command:
- "/usr/local/bin/runner.sh"
- "/bin/sh"
- "-ce"
image: quay.io/kubevirtci/golang:v20241206-ae344ab
resources:
requests:
memory: "1Gi"
limits:
memory: "1Gi"
- always_run: false
cluster: kubevirt-prow-control-plane
decorate: true
name: pull-project-infra-coverage
run_if_changed: "external-plugins/.*|releng/.*|robots/.*"
spec:
containers:
- args:
- |
GOBIN=/usr/local/bin/ go install github.com/onsi/ginkgo/v2/[email protected]
Copy link
Member

Choose a reason for hiding this comment

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

Having a specific image for this would remove the need for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true - but since we only need this in two cases currently I am not sure whether it's worth it. Also I don't want to put this into the golang image, doesn't seem like a good fit. Maybe some project-infra-test image? WDYT?
(I am not really sure whether we would want to tackle that in this PR, maybe create an issue as tracker?)

make coverage
command:
- "/usr/local/bin/runner.sh"
- "/bin/sh"
- "-ce"
image: quay.io/kubevirtci/golang:v20241206-ae344ab
resources:
requests:
memory: "1Gi"
limits:
memory: "1Gi"
- name: build-kubevirt-infra-bootstrap-image
always_run: false
run_if_changed: "images/kubevirt-infra-bootstrap/.*"
Expand Down
30 changes: 30 additions & 0 deletions hack/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
#
# This file is part of the KubeVirt project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright the KubeVirt Authors.
#
#

set -e
set -u
set -o pipefail

golangci-lint --version
golangci-lint run

if [ $(git grep '//nolint' -- '**/*.go' | wc -l) -gt 0 ]; then
echo 'WARNING: nolint directive detected';
fi
4 changes: 2 additions & 2 deletions releng/release-tool/release-tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ func (r *releaseData) getReleases() ([]*github.RepositoryRelease, error) {
return r.allReleases, nil
}

func (r *releaseData) autoDetectData(autoReleaseCadance string, autoPromoteAfterDays int) error {
func (r *releaseData) autoDetectData(autoReleaseCadance string, autoPromoteAfterDays int) error { //nolint:gocyclo
Copy link
Member

Choose a reason for hiding this comment

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

Are these nolints here just to get something running initially?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, also the git grep is to remind us to remove them


log.Printf("Attempting to auto detect release for %s/%s", r.org, r.repo)

Expand Down Expand Up @@ -975,7 +975,7 @@ func (r *releaseData) autoDetectData(autoReleaseCadance string, autoPromoteAfter
return nil
}

func (r *releaseData) verifyTag() error {
func (r *releaseData) verifyTag() error { //nolint:gocyclo
// must be a valid semver version
tagSemver, err := semver.NewVersion(r.tag)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion robots/pkg/kubevirt/cmd/get/support-matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type SupportMatrixTemplateData struct {
MapK6tToK8sVersions map[string]map[string]bool
}

func GenerateMarkdownForSupportMatrix(_ *cobra.Command, _ []string) error {
func GenerateMarkdownForSupportMatrix(_ *cobra.Command, _ []string) error { //nolint:gocyclo
if err := getSupportMatrixOpts.validateOptions(); err != nil {
return fmt.Errorf("failed to validate options: %v", err)
}
Expand Down