diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a98bfa8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,62 @@ +name: Go Build, Test, and Format + +on: + push: + branches: + - main + - 'v[0-9]+.[0-9]+.[0-9]+' + pull_request: + branches: + - main + - 'v[0-9]+.[0-9]+.[0-9]+' + +jobs: + 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 + 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 ./... + + format: + name: Format + 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: | + 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 diff --git a/internal/log/logger.go b/internal/log/logger.go index 322b3c8..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" ) @@ -103,11 +101,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..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" ) @@ -47,18 +46,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)