From 301c71541baf18e4b85a177873ab1ace67bbfe13 Mon Sep 17 00:00:00 2001 From: yashranjan1 Date: Mon, 28 Jul 2025 16:25:49 +0530 Subject: [PATCH 1/5] init ci --- .github/workflows/ci.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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..c144c1f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,35 @@ +name: Go Build, Test, and Format + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build-test-format: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.24.4' + + - name: Build + run: go build ./... + + - name: Run Tests + run: go test ./... + + - name: Check gofmt + run: | + UNFORMATTED=$(gofmt -l .) + if [ -n "$UNFORMATTED" ]; then + echo "The following files need to be formatted:" + echo "$UNFORMATTED" + exit 1 + fi From ad877de053c228c238664ec34ff0db85302b5034 Mon Sep 17 00:00:00 2001 From: yashranjan1 Date: Mon, 28 Jul 2025 16:34:53 +0530 Subject: [PATCH 2/5] changes: - ci runs on linux, macos and windows - ci runs on a pr to all version branches as well as main - ci formats and commits code --- .github/workflows/ci.yml | 47 +++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c144c1f..27c6c07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,13 +2,21 @@ name: Go Build, Test, and Format on: push: - branches: [main] + branches: + - main + - 'v[0-9]+.[0-9]+.[0-9]+' pull_request: - branches: [main] + branches: + - main + - 'v[0-9]+.[0-9]+.[0-9]+' jobs: - build-test-format: - runs-on: ubuntu-latest + build-test: + name: Build and Test on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] steps: - name: Checkout code @@ -25,11 +33,30 @@ jobs: - name: Run Tests run: go test ./... - - name: Check gofmt + format: + name: Format on Linux + runs-on: ubuntu-latest + if: github.event_name == 'push' # only format on push events (not PRs from forks) + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.24.4' + + - name: Auto-format code with gofmt and commit changes run: | - UNFORMATTED=$(gofmt -l .) - if [ -n "$UNFORMATTED" ]; then - echo "The following files need to be formatted:" - echo "$UNFORMATTED" - exit 1 + gofmt -w . + if [ -n "$(git status --porcelain)" ]; then + echo "Code was not formatted. Applying gofmt and committing changes..." + git config user.name "github-actions" + git config user.email "github-actions@github.com" + git add . + git commit -m "chore: auto-format Go code via gofmt" + git push + else + echo "Code already properly formatted." fi From a2af7460811688e87c596442f8c974421cb1135b Mon Sep 17 00:00:00 2001 From: yashranjan1 Date: Mon, 28 Jul 2025 16:42:29 +0530 Subject: [PATCH 3/5] removed a useless function and test --- internal/log/logger.go | 5 ----- internal/log/logger_test.go | 12 ------------ 2 files changed, 17 deletions(-) diff --git a/internal/log/logger.go b/internal/log/logger.go index 322b3c8..d51c54b 100644 --- a/internal/log/logger.go +++ b/internal/log/logger.go @@ -103,11 +103,6 @@ func Fatal(msg string, args ...any) { os.Exit(1) } -// Request ID utilities -func GenerateRequestID() string { - return fmt.Sprintf("req_%d", time.Now().UnixNano()) -} - type contextKey string const requestIDKey contextKey = "request_id" diff --git a/internal/log/logger_test.go b/internal/log/logger_test.go index d4648e5..884fe22 100644 --- a/internal/log/logger_test.go +++ b/internal/log/logger_test.go @@ -47,18 +47,6 @@ func TestInitialize(t *testing.T) { } func TestRequestIDFunctions(t *testing.T) { - t.Run("generates unique request IDs", func(t *testing.T) { - id1 := GenerateRequestID() - id2 := GenerateRequestID() - - if id1 == id2 { - t.Error("IDs should be unique") - } - if !strings.HasPrefix(id1, "req_") { - t.Error("ID should have req_ prefix") - } - }) - t.Run("context request ID functions", func(t *testing.T) { ctx := ContextWithRequestID(context.Background(), "test123") retrieved := RequestIDFromContext(ctx) From ac088886c0709ee6a393c7ae6116969963490ea5 Mon Sep 17 00:00:00 2001 From: yashranjan1 Date: Mon, 28 Jul 2025 16:43:37 +0530 Subject: [PATCH 4/5] removed useless imports --- internal/log/logger.go | 2 -- internal/log/logger_test.go | 1 - 2 files changed, 3 deletions(-) diff --git a/internal/log/logger.go b/internal/log/logger.go index d51c54b..3e3f820 100644 --- a/internal/log/logger.go +++ b/internal/log/logger.go @@ -3,11 +3,9 @@ package log import ( "context" - "fmt" "log/slog" "os" "sync" - "time" "gopkg.in/natefinch/lumberjack.v2" ) diff --git a/internal/log/logger_test.go b/internal/log/logger_test.go index 884fe22..33db4ad 100644 --- a/internal/log/logger_test.go +++ b/internal/log/logger_test.go @@ -4,7 +4,6 @@ import ( "context" "log/slog" "os" - "strings" "testing" ) From b1d89e3a2e49ae0457e0df97889b00726e017bcd Mon Sep 17 00:00:00 2001 From: yashranjan1 Date: Mon, 28 Jul 2025 16:46:41 +0530 Subject: [PATCH 5/5] renamed a ci step --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 27c6c07..a98bfa8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: run: go test ./... format: - name: Format on Linux + name: Format runs-on: ubuntu-latest if: github.event_name == 'push' # only format on push events (not PRs from forks)