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

Fix make cmds #810

Merged
merged 12 commits into from
Jun 13, 2024
  •  
  •  
  •  
43 changes: 16 additions & 27 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
run:
go: "1.21"
timeout: 10m
tests: false
allow-parallel-runners: true
issues-exit-code: 2
skip-dirs:
- "hack"
# External code from containerd/containerd
- "pkg/docker"


linters:
enable-all: true
Expand All @@ -33,14 +29,13 @@ linters:
- stylecheck # Too many issues.
# No snake_case in Go.
# convert_ComponentReferences_from should be convertComponentReferencesFrom
- nosnakecase
- prealloc # Performance.
- exportloopref
- nilerr # There a few places where we don't return with an error
# in an 'if err != nil {}' block. If it's intentional,
# we should add a '//nolint: nilerr // Reason why...'
- nlreturn # Use empty line at least before return/break/continue.
- goerr113 # Do not define dynamic errors with Errorf.
- err113 # Do not define dynamic errors with Errorf.
- varnamelen # m, d, p < These are not so meaningful variables.
- testpackage # Blackbox testing is preferred.
- funlen # Break long functions.
Expand Down Expand Up @@ -70,6 +65,9 @@ linters:
- tagliatelle
- wsl
- interfacebloat
- inamedparam
- mnd
- perfsprint


# Disabled with reason
Expand All @@ -79,26 +77,17 @@ linters:
- dogsled
- exhaustruct # Doesn't really make sense.
- exhaustive # Doesn't really make sense.
- logrlint # Doesn't really make sense.
- loggercheck # Doesn't really make sense.
- goimports # acts weirdly, dci handles imports anyway
- intrange # Confusing, since manipulating a range variable in a loop does not change the number of
# iterations. Thus, an integer range is constant.

# Disabled because of generics in go 1.18
- contextcheck
- rowserrcheck
- sqlclosecheck
- wastedassign

# Deprecated
- deadcode
- exhaustivestruct
- golint
- ifshort
- interfacer
- maligned
- scopelint
- structcheck
- varcheck

linters-settings:
gci:
sections:
Expand All @@ -108,18 +97,13 @@ linters-settings:
- default
- prefix(github.com/open-component-model/ocm)
custom-order: true
staticcheck:
go: "1.21"
stylecheck:
go: "1.21"
funlen:
lines: 110
statements: 60
cyclop:
max-complexity: 15
skip-tests: true
nolintlint:
allow-leading-space: false
allow-unused: false
require-explanation: true
require-specific: false
Expand All @@ -128,8 +112,6 @@ linters-settings:
- err
- wg
- id
govet:
check-shadowing: true
lll:
line-length: 120
gosec:
Expand All @@ -139,6 +121,12 @@ linters-settings:
- elseif

issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-dirs:
- "hack"
# External code from containerd/containerd
- "pkg/docker"
exclude:
- composites
exclude-rules:
Expand All @@ -159,7 +147,7 @@ issues:
- govet
- path: _test\.go
linters:
- goerr113
- err113
- gocyclo
- errcheck
- gosec
Expand All @@ -179,3 +167,4 @@ issues:
- path: ignore/.*\.go
linters:
- dupword

26 changes: 16 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,37 @@ install-requirements:
.PHONY: prepare
prepare: generate format generate-deepcopy build test check

EFFECTIVE_DIRECTORIES := $(REPO_ROOT)/cmds/ocm/... $(REPO_ROOT)/cmds/helminstaller/... $(REPO_ROOT)/cmds/ecrplugin/... $(REPO_ROOT)/cmds/demoplugin/... $(REPO_ROOT)/examples/... $(REPO_ROOT)/pkg/...

.PHONY: format
format:
@$(REPO_ROOT)/hack/format.sh $(REPO_ROOT)/pkg $(REPO_ROOT)/cmds/ocm $(REPO_ROOT)/cmds/helminstaller $(REPO_ROOT)/cmds/ecrplugin $(REPO_ROOT)/cmds/demoplugin
@$(REPO_ROOT)/hack/format.sh $(EFFECTIVE_DIRECTORIES)

.PHONY: check
check:
@$(REPO_ROOT)/hack/check.sh --golangci-lint-config=./.golangci.yaml $(REPO_ROOT)/cmds/ocm $(REPO_ROOT)/cmds/helminstaller/... $(REPO_ROOT)/cmds/ecrplugin/... $(REPO_ROOT)/cmds/demoplugin/... $(REPO_ROOT)/pkg/...
@$(REPO_ROOT)/hack/check.sh --golangci-lint-config=./.golangci.yaml $(EFFECTIVE_DIRECTORIES)

.PHONY: check-and-fix
check-and-fix:
@$(REPO_ROOT)/hack/check.sh --fix --golangci-lint-config=./.golangci.yaml $(EFFECTIVE_DIRECTORIES)

.PHONY: force-test
force-test:
@go test -parallel=1 --count=1 $(REPO_ROOT)/cmds/ocm $(REPO_ROOT)/cmds/helminstaller $(REPO_ROOT)/cmds/ocm/... $(REPO_ROOT)/cmds/ecrplugin/... $(REPO_ROOT)/cmds/demoplugin/... $(REPO_ROOT)/pkg/...
@go test --count=1 $(EFFECTIVE_DIRECTORIES)

.PHONY: test
test:
@echo "> Run Unit Tests"
@go test ./examples/lib/... $(REPO_ROOT)/cmds/ocm/... $(REPO_ROOT)/cmds/demoplugin/... $(REPO_ROOT)/pkg/...
@echo "> Run Tests"
@go test --tags=integration $(EFFECTIVE_DIRECTORIES)

.PHONY: test-all
test-all: install-requirements
@echo "> Run All Tests"
@go test --tags=integration ./examples/lib/... $(REPO_ROOT)/cmds/ocm/... $(REPO_ROOT)/cmds/demoplugin/... $(REPO_ROOT)/pkg/...
.PHONY: unit-test
unit-test:
@echo "> Run Unit Tests"
@go test $(EFFECTIVE_DIRECTORIES)

.PHONY: generate
generate:
@$(REPO_ROOT)/hack/generate.sh $(REPO_ROOT)/pkg/... $(REPO_ROOT)/cmds/ocm/... $(REPO_ROOT)/cmds/helminstaller/... $(REPO_ROOT)/examples/...
@$(REPO_ROOT)/hack/generate.sh $(EFFECTIVE_DIRECTORIES)

.PHONY: generate-deepcopy
generate-deepcopy: controller-gen
Expand Down
10 changes: 6 additions & 4 deletions cmds/demoplugin/valuesets/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (
"github.com/open-component-model/ocm/pkg/signing/handlers/rsa"
)

const ARCH = "/tmp/ctf"
const COMP = "acme.org/test"
const VERS = "1.0.0"
const PROV = "acme.org"
const (
ARCH = "/tmp/ctf"
COMP = "acme.org/test"
VERS = "1.0.0"
PROV = "acme.org"
)

var _ = Describe("demoplugin", func() {
/*
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func NewVersionCommand(ctx clictx.Context) *cobra.Command {
Run: func(_ *cobra.Command, _ []string) {
v := version.Get()
s := fmt.Sprintf("%#v", v)
out.Outf(ctx, "%s\n", prepare(s[strings.Index(s, "{"):]))
out.Outf(ctx, "%s\n", prepare(s[strings.Index(s, "{"):])) //nolint:gocritic // yes
},
}
}
1 change: 0 additions & 1 deletion cmds/ocm/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,4 @@ ERROR <nil> ctxerror realm ocm realm test
attr = mapocirepoattr.Get(env.Context)
Expect(attr.Mode).To(Equal(mapocirepoattr.ShortHashMode))
})

})
2 changes: 0 additions & 2 deletions cmds/ocm/commands/cachecmds/clean/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ func (o *Command) Complete(args []string) error {
}

func (o *Command) Run() error {

cnt, ncnt, fcnt, size, nsize, fsize, err := o.cache.Cleanup(common.NewPrinter(o.Context.StdErr()), &o.before, o.dryrun)

if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var _ options.Options = (*Option)(nil)
func (o *Option) GetError() error {
return o.err
}

func (o *Option) SetError(err error) {
o.err = err
}
Expand All @@ -42,7 +43,7 @@ func (o *Option) AddError(err error) {
if o.err == nil {
o.err = errors.ErrList().Add(err)
} else {
if l, ok := o.err.(*errors.ErrorList); ok {
if l, ok := o.err.(*errors.ErrorList); ok { //nolint:errorlint // has to be of type ErrorList to call its method
l.Add(err)
} else {
o.err = errors.ErrList().Add(o.err, err)
Expand Down
4 changes: 1 addition & 3 deletions cmds/ocm/commands/controllercmds/names/names.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
package names

var (
Controller = []string{"controller"}
)
var Controller = []string{"controller"}
1 change: 0 additions & 1 deletion cmds/ocm/commands/misccmds/hash/sign/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func (o *Command) AddFlags(set *pflag.FlagSet) {
set.StringVarP(&o.pubFile, "publicKey", "", "", "public key certificate file")
set.StringVarP(&o.rootFile, "rootCerts", "", "", "root certificates file (deprecated)")
set.StringArrayVarP(&o.rootCAs, "ca-cert", "", nil, "additional root certificate authorities (for signing certificates)")

}

func (o *Command) Complete(args []string) error {
Expand Down
1 change: 1 addition & 0 deletions cmds/ocm/commands/misccmds/hash/sign/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/open-component-model/ocm/cmds/ocm/testhelper"

"github.com/open-component-model/ocm/pkg/contexts/ocm/signing/signingtest"
)

Expand Down
2 changes: 0 additions & 2 deletions cmds/ocm/commands/misccmds/rsakeypair/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ var _ = Describe("Test Environment", func() {
})

It("create key pair", func() {

buf := bytes.NewBuffer(nil)
Expect(env.CatchOutput(buf).Execute("create", "rsakeypair", "key.priv")).To(Succeed())
Expect(buf.String()).To(StringEqualTrimmedWithContext(`
Expand Down Expand Up @@ -67,7 +66,6 @@ created rsa key pair key.priv[key.pub]
})

It("create self-signed key pair", func() {

buf := bytes.NewBuffer(nil)
Expect(env.CatchOutput(buf).Execute("create", "rsakeypair", "key.priv", "CN=mandelsoft")).To(Succeed())
Expect(buf.String()).To(StringEqualTrimmedWithContext(`
Expand Down
9 changes: 5 additions & 4 deletions cmds/ocm/commands/ocicmds/artifacts/download/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ func (d *download) Save(o *artifacthdlr.Object, f string) error {
return err
}

if len(opts.Layers) > 0 {
switch {
case len(opts.Layers) > 0:
var finalize finalizer.Finalizer
defer finalize.Finalize()

Expand All @@ -176,7 +177,7 @@ func (d *download) Save(o *artifacthdlr.Object, f string) error {
if len(opts.Layers) > 1 {
name = fmt.Sprintf("%s-%d", f, l)
}
file, err := dest.PathFilesystem.OpenFile(name, vfs.O_CREATE|vfs.O_TRUNC|vfs.O_WRONLY, 0640)
file, err := dest.PathFilesystem.OpenFile(name, vfs.O_CREATE|vfs.O_TRUNC|vfs.O_WRONLY, 0o640)
if err != nil {
return errors.Wrapf(err, "cannot create target file %s for layer %d", name, l)
}
Expand All @@ -188,7 +189,7 @@ func (d *download) Save(o *artifacthdlr.Object, f string) error {
out.Outf(d.opts.Context, "%s: layer %d: %d byte(s) downloaded\n", name, l, n)
nested.Finalize()
}
} else if opts.DirTree {
case opts.DirTree:
format := formatoption.From(d.opts)

if !art.IsManifest() {
Expand Down Expand Up @@ -232,7 +233,7 @@ func (d *download) Save(o *artifacthdlr.Object, f string) error {
} else {
return accessio.CopyFileSystem(format.Format, fs, "/", dest.PathFilesystem, f, 0o640)
}
} else {
default:
blob, err := art.Blob()
if err != nil {
return err
Expand Down
10 changes: 6 additions & 4 deletions cmds/ocm/commands/ocicmds/artifacts/download/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import (
"github.com/open-component-model/ocm/pkg/mime"
)

const ARCH = "/tmp/ctf"
const VERSION = "v1"
const NS = "mandelsoft/test"
const OUT = "/tmp/res"
const (
ARCH = "/tmp/ctf"
VERSION = "v1"
NS = "mandelsoft/test"
OUT = "/tmp/res"
)

var _ = Describe("Test Environment", func() {
var env *TestEnv
Expand Down
15 changes: 7 additions & 8 deletions cmds/ocm/commands/ocicmds/artifacts/get/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import (
"github.com/open-component-model/ocm/pkg/mime"
)

const ARCH = "/tmp/ctf"
const VERSION1 = "v1"
const VERSION2 = "v2"
const NS1 = "mandelsoft/test"
const NS2 = "mandelsoft/index"
const (
ARCH = "/tmp/ctf"
VERSION1 = "v1"
VERSION2 = "v2"
NS1 = "mandelsoft/test"
NS2 = "mandelsoft/index"
)

var _ = Describe("Test Environment", func() {
var env *TestEnv
Expand Down Expand Up @@ -82,7 +84,6 @@ var _ = Describe("Test Environment", func() {
})

It("get single artifacts", func() {

buf := bytes.NewBuffer(nil)
Expect(env.CatchOutput(buf).Execute("get", "artifact", ARCH+"//"+NS1+":"+VERSION1)).To(Succeed())
Expect(buf.String()).To(StringEqualTrimmedWithContext(
Expand All @@ -92,7 +93,6 @@ REGISTRY REPOSITORY KIND TAG DIGEST
`))
})
It("get all artifacts in namespace", func() {

buf := bytes.NewBuffer(nil)
Expect(env.CatchOutput(buf).Execute("get", "artifact", ARCH+"//"+NS1)).To(Succeed())
Expect(buf.String()).To(StringEqualTrimmedWithContext(
Expand Down Expand Up @@ -263,6 +263,5 @@ NESTING REGISTRY REPOSITORY KIND TAG
└─ /tmp/ctf mandelsoft/index manifest - sha256:60b245b3de64c43b18489e9c3cf177402f9bd18ab62f8cc6653e2fc2e3a5fc39
`))
})

})
})
10 changes: 6 additions & 4 deletions cmds/ocm/commands/ocicmds/artifacts/transfer/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import (
"github.com/open-component-model/ocm/pkg/mime"
)

const ARCH = "/tmp/ctf"
const VERSION = "v1"
const NS = "mandelsoft/test"
const OUT = "/tmp/res"
const (
ARCH = "/tmp/ctf"
VERSION = "v1"
NS = "mandelsoft/test"
OUT = "/tmp/res"
)

var _ = Describe("Test Environment", func() {
var env *TestEnv
Expand Down
1 change: 0 additions & 1 deletion cmds/ocm/commands/ocicmds/ctf/create/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var _ = Describe("Test Environment", func() {
})

It("creates common transport archive", func() {

Expect(env.Execute("create", "ctf", "-ft", "directory", ARCH)).To(Succeed())
Expect(env.DirExists(ARCH)).To(BeTrue())
Expect(env.ReadTextFile(env.Join(ARCH, ctf.ArtifactIndexFileName))).To(Equal("{\"schemaVersion\":1,\"artifacts\":null}"))
Expand Down
Loading
Loading