diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml new file mode 100644 index 0000000..5295b60 --- /dev/null +++ b/.github/workflows/CI.yaml @@ -0,0 +1,49 @@ +name: CI +on: + push: + branches: [main] + pull_request: +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-go@v7 + with: + go-version: 1.26 + - run: go build ./... + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-go@v7 + with: + go-version: 1.26 + - uses: golangci/golangci-lint-action@v9 + with: + version: v2.12 + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-go@v7 + with: + go-version: 1.26 + - run: go test ./... -race -cover + + cli-scaffold: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-go@v7 + with: + go-version: 1.26 + - name: CLI scaffolds a buildable project + run: | + go build -o /tmp/summer ./cmd/summer + cd $(mktemp -d) + /tmp/summer -b main init <<< "testproject" + go mod tidy + go build -o /tmp/build/ ./... diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..a7d447e --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,7 @@ +version: "2" +linters: + default: standard + +formatters: + enable: + - gofmt \ No newline at end of file diff --git a/cmd/summer/main.go b/cmd/summer/main.go index ad03709..0095786 100644 --- a/cmd/summer/main.go +++ b/cmd/summer/main.go @@ -3,12 +3,13 @@ package main import ( "bufio" "fmt" - "github.com/spf13/cobra" "io" "os" "os/exec" "path/filepath" "strings" + + "github.com/spf13/cobra" ) const ( @@ -347,7 +348,12 @@ func copyFileContents(srcFile, dstFile string) (err error) { if err != nil { return } - defer in.Close() + defer func(in *os.File) { + err := in.Close() + if err != nil { + return + } + }(in) info, err := in.Stat() if err != nil { @@ -363,7 +369,10 @@ func copyFileContents(srcFile, dstFile string) (err error) { if err != nil { _ = os.Remove(dstFile) } - out.Close() + err := out.Close() + if err != nil { + return + } }() _, err = io.Copy(out, in) diff --git a/pkg/log/logger.go b/pkg/log/logger.go index d90f63c..6d7e612 100644 --- a/pkg/log/logger.go +++ b/pkg/log/logger.go @@ -75,17 +75,6 @@ func WithContext(ctx context.Context, logger *zap.Logger) *zap.Logger { return logger } -// prettyEncodeCaller add padding to the caller string -func prettyEncodeCaller(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder) { - const fixedWidth = 25 - callerStr := caller.TrimmedPath() - if len(callerStr) < fixedWidth { - callerStr += strings.Repeat(" ", fixedWidth-len(callerStr)) - } - callerStr += "\t" - enc.AppendString(callerStr) -} - // relativePrettyCallerEncoder returns a zapcore.CallerEncoder that formats the caller path relative to the root directory // it enables clickable links in the GoLand console output func relativePrettyCallerEncoder(rootDir string) zapcore.CallerEncoder {