From b6d5ee07349db88f962a0d054cf4dce38ced73da Mon Sep 17 00:00:00 2001 From: David Gannon <19214156+dgannon991@users.noreply.github.com> Date: Thu, 4 Apr 2024 21:22:47 +0100 Subject: [PATCH] Changed to golangci-lint and introduced LintChanges command Signed-off-by: David Gannon <19214156+dgannon991@users.noreply.github.com> --- .github/workflows/porter.yml | 2 +- magefile.go | 12 +++++++++--- pkg/tracing/traceLogger.go | 9 +++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/porter.yml b/.github/workflows/porter.yml index e7deb53f3..12534d027 100644 --- a/.github/workflows/porter.yml +++ b/.github/workflows/porter.yml @@ -82,7 +82,7 @@ jobs: run: go run mage.go Vet shell: bash - name: Lint - run: go run mage.go Lint + run: go run mage.go LintChanges shell: bash Build-docker-images: diff --git a/magefile.go b/magefile.go index 5d5f1532a..aaff96c2f 100644 --- a/magefile.go +++ b/magefile.go @@ -699,10 +699,16 @@ func Vet() { must.RunV("go", "vet", "./...") } -// Run staticcheck on the project +// Run golangci-lint on the project, but only for the latest changes +func LintChanges() { + mg.Deps(tools.EnsureGolangCILint) + must.RunV("golangci-lint", "run", "--new-from-rev=HEAD~1", "--whole-files", "./...") +} + +// Run golangci-lint on the project func Lint() { - mg.Deps(tools.EnsureStaticCheck) - must.RunV("staticcheck", "./...") + mg.Deps(tools.EnsureGolangCILint) + must.RunV("golangci-lint", "run", "./...") } func getPorterHome() string { diff --git a/pkg/tracing/traceLogger.go b/pkg/tracing/traceLogger.go index 5d5aa0856..88dc0963a 100644 --- a/pkg/tracing/traceLogger.go +++ b/pkg/tracing/traceLogger.go @@ -85,7 +85,7 @@ type RootTraceLogger interface { TraceLogger // Close the tracer and send data to the telemetry collector - Close() + Close() error } var _ TraceLogger = traceLogger{} @@ -102,12 +102,13 @@ type traceLogger struct { } // Close the root span and send the telemetry data to the collector. -func (l traceLogger) Close() { +func (l traceLogger) Close() error { l.span.End() if err := l.tracer.Close(context.Background()); err != nil { - l.Errorf("error closing the Tracer: %w", err) + return l.Errorf("error closing the Tracer: %w", err) } + return nil } // ShouldLog returns if the current log level includes the specified level. @@ -151,7 +152,7 @@ func (l traceLogger) EndSpan(opts ...trace.SpanEndOption) { // If there was a panic, mark the span and include the stack trace if panicErr := recover(); panicErr != nil { - l.Error(fmt.Errorf("%s", panicErr), + panicErr = l.Error(fmt.Errorf("%s", panicErr), attribute.Bool("panic", true), attribute.String("stackTrace", string(debug.Stack()))) panic(panicErr) // rethrow