From d27279088c4fd13e2f435ba910abd0a7fe7a6d6c Mon Sep 17 00:00:00 2001 From: jay <38236622+JayJamieson@users.noreply.github.com> Date: Tue, 9 Dec 2025 21:22:58 +1300 Subject: [PATCH 1/3] add ci checks and fixed lint errors --- .github/workflows/ci.yml | 48 ++++++++++++++++++++++++++++++++++++++++ flag.go | 1 - wrapper/lambda_test.go | 7 ++++-- wrapper/wrapper.go | 16 +++++++------- wrapper/wrapper_test.go | 2 +- 5 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9d2877f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,48 @@ +name: CI + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + - name: Run tests + run: go test -v -race -coverprofile=coverage.out ./... + + - name: Upload coverage + uses: codecov/codecov-action@v4 + with: + file: ./coverage.out + fail_ci_if_error: false + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v2.7.2 diff --git a/flag.go b/flag.go index a4544cc..f696c88 100644 --- a/flag.go +++ b/flag.go @@ -34,7 +34,6 @@ func parseFuncName(args []string) (string, bool, error) { if s[1] == '-' { numMinuses++ if len(s) == 2 { // "--" terminates the flags - args = args[1:] return "", false, nil } } diff --git a/wrapper/lambda_test.go b/wrapper/lambda_test.go index cb88b37..42d7b43 100644 --- a/wrapper/lambda_test.go +++ b/wrapper/lambda_test.go @@ -221,6 +221,9 @@ func TestNewCobrLambdaHandler_EmptyArgs(t *testing.T) { } func TestNewCobrLambdaHandler_ContextPropagation(t *testing.T) { + type contextKey string + const testKey contextKey = "test-key" + // Create a command that checks context receivedCtx := false cmd := &cobra.Command{ @@ -228,7 +231,7 @@ func TestNewCobrLambdaHandler_ContextPropagation(t *testing.T) { Run: func(cmd *cobra.Command, args []string) { ctx := cmd.Context() if ctx != nil { - if val := ctx.Value("test-key"); val == "test-value" { + if val := ctx.Value(testKey); val == "test-value" { receivedCtx = true cmd.Println("Context received correctly") } @@ -247,7 +250,7 @@ func TestNewCobrLambdaHandler_ContextPropagation(t *testing.T) { } // Create context with value - ctx := context.WithValue(context.Background(), "test-key", "test-value") + ctx := context.WithValue(context.Background(), testKey, "test-value") result, err := handler(ctx, eventJSON) if err != nil { diff --git a/wrapper/wrapper.go b/wrapper/wrapper.go index 5fcc3b1..2c7f041 100644 --- a/wrapper/wrapper.go +++ b/wrapper/wrapper.go @@ -48,8 +48,8 @@ func (w *CobraLambda) Execute(args []string) (*OutputCapture, error) { stderrReader, stderrWriter, err := os.Pipe() if err != nil { - stdoutWriter.Close() - stdoutReader.Close() + _ = stdoutWriter.Close() + _ = stdoutReader.Close() return nil, err } @@ -69,7 +69,7 @@ func (w *CobraLambda) Execute(args []string) (*OutputCapture, error) { go func() { defer wg.Done() mw := io.MultiWriter(sharedBuffer, w.originalStdout) - io.Copy(mw, stdoutReader) + _, _ = io.Copy(mw, stdoutReader) done <- true }() @@ -77,7 +77,7 @@ func (w *CobraLambda) Execute(args []string) (*OutputCapture, error) { go func() { defer wg.Done() mw := io.MultiWriter(sharedBuffer, w.originalStderr) - io.Copy(mw, stderrReader) + _, _ = io.Copy(mw, stderrReader) done <- true }() @@ -88,14 +88,14 @@ func (w *CobraLambda) Execute(args []string) (*OutputCapture, error) { execErr := w.cmd.Execute() - stdoutWriter.Close() - stderrWriter.Close() + _ = stdoutWriter.Close() + _ = stderrWriter.Close() wg.Wait() close(done) - stdoutReader.Close() - stderrReader.Close() + _ = stdoutReader.Close() + _ = stderrReader.Close() os.Stdout = w.originalStdout os.Stderr = w.originalStderr diff --git a/wrapper/wrapper_test.go b/wrapper/wrapper_test.go index 29cd61a..5d94650 100644 --- a/wrapper/wrapper_test.go +++ b/wrapper/wrapper_test.go @@ -25,7 +25,7 @@ func TestCobraWrapper_Execute(t *testing.T) { // Write to os.Stdout fmt.Println("Hello from os.Stdout!") - fmt.Fprintf(os.Stdout, "Additional stdout output\n") + _, _ = fmt.Fprintf(os.Stdout, "Additional stdout output\n") // Write to os.Stderr fmt.Fprintln(os.Stderr, "Error message to stderr") From 19555103eb145cde747fe30a7188bd41efa0b1b9 Mon Sep 17 00:00:00 2001 From: jay <38236622+JayJamieson@users.noreply.github.com> Date: Tue, 9 Dec 2025 21:27:16 +1300 Subject: [PATCH 2/3] add ci checks and fixed lint errors --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d2877f..90cbd6a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,9 +17,9 @@ jobs: uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v5 + uses: actions/setup-go@v6 with: - go-version-file: 'go.mod' + go-version-file: "go.mod" - name: Run tests run: go test -v -race -coverprofile=coverage.out ./... @@ -38,11 +38,11 @@ jobs: uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v5 + uses: actions/setup-go@v6 with: - go-version-file: 'go.mod' + go-version-file: "go.mod" - name: Run golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v9 with: - version: v2.7.2 + version: v2.6 From 435cf734ba7ceafef6f52c9a5e8520cc75faf7fe Mon Sep 17 00:00:00 2001 From: jay <38236622+JayJamieson@users.noreply.github.com> Date: Tue, 9 Dec 2025 21:34:23 +1300 Subject: [PATCH 3/3] add status badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index bbc72ec..85514e0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # cobra-lambda +[![CI](https://github.com/JayJamieson/cobra-lambda/actions/workflows/ci.yml/badge.svg)](https://github.com/JayJamieson/cobra-lambda/actions/workflows/ci.yml) + Run your [Cobra](https://github.com/spf13/cobra) CLI applications in AWS Lambda and invoke them remotely as if they were running locally on your machine. ## What is cobra-lambda?