Skip to content

Commit

Permalink
fix: remove duplicate logging (#17)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
ctgardner authored Dec 18, 2024
1 parent 3ccb905 commit 871ed33
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion src/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/cultureamp/examplego
module github.com/cultureamp/example-go-buildkite-plugin

go 1.20

Expand Down
4 changes: 2 additions & 2 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
9 changes: 4 additions & 5 deletions src/plugin/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -21,17 +22,15 @@ 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

buildkite.Logf("Annotating with message: %s\n", annotation)

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.")
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down

0 comments on commit 871ed33

Please sign in to comment.