From 871ed3360aebf3280d9dd3e982836ba757e64c4a Mon Sep 17 00:00:00 2001 From: Callum Gardner <10970827+ctgardner@users.noreply.github.com> Date: Thu, 19 Dec 2024 09:10:40 +1100 Subject: [PATCH] fix: remove duplicate logging (#17) * refactor: rename module Renamed the Go module to match the repo name. * fix: remove duplicate logging Errors are now wrapped and returned to the caller, rather than logged and returned to the caller. Propagating the error to the caller causes errors to logged by the `main` function (if they're propagated that far). Logging them elsewhere results in the error being logged more than once. --- src/Dockerfile | 6 +++--- src/go.mod | 2 +- src/main.go | 4 ++-- src/plugin/config_test.go | 2 +- src/plugin/example.go | 9 ++++----- src/plugin/example_test.go | 2 +- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Dockerfile b/src/Dockerfile index 89b2f34..95b51be 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -18,13 +18,13 @@ COPY . ./ # build as a static binary without debug symbols RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ -ldflags='-w -s -extldflags "-static"' -a \ - -o /dist/examplego . + -o /dist/example-go-buildkite-plugin . # runtime image using static distroless base # using static nonroot image # user:group is nobody:nobody, uid:gid = 65534:65534 FROM ${DISTROLESS_IMAGE} -COPY --from=builder /dist/examplego /examplego +COPY --from=builder /dist/example-go-buildkite-plugin /example-go-buildkite-plugin -ENTRYPOINT ["/examplego"] +ENTRYPOINT ["/example-go-buildkite-plugin"] diff --git a/src/go.mod b/src/go.mod index 81c6463..b0fd0df 100644 --- a/src/go.mod +++ b/src/go.mod @@ -1,4 +1,4 @@ -module github.com/cultureamp/examplego +module github.com/cultureamp/example-go-buildkite-plugin go 1.20 diff --git a/src/main.go b/src/main.go index 82711da..59f1592 100644 --- a/src/main.go +++ b/src/main.go @@ -4,8 +4,8 @@ import ( "context" "os" - "github.com/cultureamp/examplego/buildkite" - "github.com/cultureamp/examplego/plugin" + "github.com/cultureamp/example-go-buildkite-plugin/buildkite" + "github.com/cultureamp/example-go-buildkite-plugin/plugin" ) func main() { diff --git a/src/plugin/config_test.go b/src/plugin/config_test.go index 5754738..6adaece 100644 --- a/src/plugin/config_test.go +++ b/src/plugin/config_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - "github.com/cultureamp/examplego/plugin" + "github.com/cultureamp/example-go-buildkite-plugin/plugin" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/src/plugin/example.go b/src/plugin/example.go index 0fcde5c..6a7c0fb 100644 --- a/src/plugin/example.go +++ b/src/plugin/example.go @@ -2,8 +2,9 @@ package plugin import ( "context" + "fmt" - "github.com/cultureamp/examplego/buildkite" + "github.com/cultureamp/example-go-buildkite-plugin/buildkite" ) type ExamplePlugin struct { @@ -21,8 +22,7 @@ func (ep ExamplePlugin) Run(ctx context.Context, fetcher ConfigFetcher, agent Ag var config Config err := fetcher.Fetch(&config) if err != nil { - buildkite.LogFailuref("plugin configuration error: %s\n", err.Error()) - return err + return fmt.Errorf("plugin configuration error: %w", err) } annotation := config.Message @@ -30,8 +30,7 @@ func (ep ExamplePlugin) Run(ctx context.Context, fetcher ConfigFetcher, agent Ag err = agent.Annotate(ctx, annotation, "info", "message") if err != nil { - buildkite.LogFailuref("buildkite annotation error: %s\n", err.Error()) - return err + return fmt.Errorf("buildkite annotation error: %w", err) } buildkite.Log("done.") diff --git a/src/plugin/example_test.go b/src/plugin/example_test.go index 69cf7cf..2a2da46 100644 --- a/src/plugin/example_test.go +++ b/src/plugin/example_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "github.com/cultureamp/examplego/plugin" + "github.com/cultureamp/example-go-buildkite-plugin/plugin" "github.com/stretchr/testify/assert" )