From fadabf9985973ddbd76af7ccb9fbe3abce0cf438 Mon Sep 17 00:00:00 2001 From: kartik Date: Wed, 1 Apr 2026 13:09:46 +0530 Subject: [PATCH 1/2] infra-update --- .github/pull_request_template.md | 4 +-- Makefile | 54 +++++++++++++++++++++++++++----- README.md | 28 ++++++++--------- codecov.yml | 25 +++++++++++++++ 4 files changed, 87 insertions(+), 24 deletions(-) create mode 100644 codecov.yml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index e9b3f87..594e849 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -12,8 +12,8 @@ -- [ ] Unit tests pass (`go test ./...`) -- [ ] Lint passes (`golangci-lint run ./...`) +- [ ] fmt, vet, lint, test, build passes (make all) +- [ ] New code has tests where appropriate - [ ] Generated code compiles for affected scenarios ## Related Issues diff --git a/Makefile b/Makefile index 7995400..d23e121 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,62 @@ -.PHONY: deps test lint bench vet fmt ci +GOLANGCI_LINT_VERSION := v2.10.1 +.PHONY: all setup deps test test-v vet lint bench build fmt cover clean ci + +all: fmt vet lint test build + +## Install development tools (skips if already present) +setup: + @command -v golangci-lint >/dev/null 2>&1 || { \ + echo "Installing golangci-lint $(GOLANGCI_LINT_VERSION)..."; \ + go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION); \ + } + @command -v goimports >/dev/null 2>&1 || { \ + echo "Installing goimports..."; \ + go install golang.org/x/tools/cmd/goimports@latest; \ + } + +## Download module dependencies deps: go mod download - go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest - go install golang.org/x/tools/cmd/goimports@latest +## Run all tests with race detector test: - go test -race -count=1 -p 1 ./... + go test -race -count=1 ./... -lint: - golangci-lint run +## Run tests with verbose output +test-v: + go test -race -v -count=1 ./... + +## Run go vet +vet: + go vet ./... +## Run golangci-lint +lint: setup + golangci-lint run ./... + +## Run benchmarks bench: go test -bench=. -benchmem ./... -vet: - go vet ./... +## Build all packages +build: + go build ./... +## Format code fmt: gofmt -w . goimports -w . +## Run tests with coverage report +cover: + go test -race ./... -coverprofile=coverage.out + go tool cover -html=coverage.out -o coverage.html + @echo "Coverage report: coverage.html" + +## Remove build artifacts +clean: + rm -f coverage.out coverage.html + +## CI pipeline: vet, lint, test ci: vet lint test diff --git a/README.md b/README.md index b5b317f..24da101 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ Code generation tool that parses Go struct definitions and generates type-safe mapping functions. Zero reflection, zero runtime cost. In `func` mode (default), the generated code has zero dependencies. [![Go Reference](https://pkg.go.dev/badge/github.com/KARTIKrocks/gomapper.svg)](https://pkg.go.dev/github.com/KARTIKrocks/gomapper) -[![CI](https://github.com/KARTIKrocks/gomapper/actions/workflows/ci.yml/badge.svg)](https://github.com/KARTIKrocks/gomapper/actions/workflows/ci.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/KARTIKrocks/gomapper)](https://goreportcard.com/report/github.com/KARTIKrocks/gomapper) [![Go Version](https://img.shields.io/github/go-mod/go-version/KARTIKrocks/gomapper)](go.mod) +[![CI](https://github.com/KARTIKrocks/gomapper/actions/workflows/ci.yml/badge.svg)](https://github.com/KARTIKrocks/gomapper/actions/workflows/ci.yml) [![License](https://img.shields.io/github/license/KARTIKrocks/gomapper)](LICENSE) [![GitHub tag](https://img.shields.io/github/v/tag/KARTIKrocks/gomapper)](https://github.com/KARTIKrocks/gomapper/releases) @@ -39,19 +39,19 @@ This produces a `mapper_gen.go` file with pure mapping functions — no runtime ### Flags -| Flag | Default | Description | -|------|---------|-------------| -| `-src` | | Source type name | -| `-dst` | | Destination type name | -| `-pairs` | | Comma-separated `Src:Dst` pairs | -| `-output` | `mapper_gen.go` | Output file name | -| `-mode` | `func` | `func` (pure functions), `register`, or `both` | -| `-bidirectional` | `false` | Generate both S→D and D→S mappings | -| `-tag` | `map` | Struct tag key for field renaming | -| `-strict` | `false` | Fail if any destination field is unmapped | -| `-ci` | `false` | Case-insensitive field name matching | -| `-nil-safe` | `false` | Generate nil checks for pointer dereferences | -| `-v` | `false` | Verbose output | +| Flag | Default | Description | +| ---------------- | --------------- | ---------------------------------------------- | +| `-src` | | Source type name | +| `-dst` | | Destination type name | +| `-pairs` | | Comma-separated `Src:Dst` pairs | +| `-output` | `mapper_gen.go` | Output file name | +| `-mode` | `func` | `func` (pure functions), `register`, or `both` | +| `-bidirectional` | `false` | Generate both S→D and D→S mappings | +| `-tag` | `map` | Struct tag key for field renaming | +| `-strict` | `false` | Fail if any destination field is unmapped | +| `-ci` | `false` | Case-insensitive field name matching | +| `-nil-safe` | `false` | Generate nil checks for pointer dereferences | +| `-v` | `false` | Verbose output | ### Modes diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..18dce98 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,25 @@ +codecov: + require_ci_to_pass: true + +coverage: + precision: 2 + round: down + range: "70...100" + status: + project: + default: + target: auto + threshold: 5% + patch: + default: + target: auto + threshold: 5% + +comment: + layout: "reach,diff,flags,files" + behavior: default + require_changes: true + +ignore: + - "examples/**" + - "vendor/**" From 3c25e4db1fa27b58569d9241c25a045d963b5d36 Mon Sep 17 00:00:00 2001 From: kartik Date: Wed, 1 Apr 2026 13:17:23 +0530 Subject: [PATCH 2/2] fix coverage ci issue --- integration_test.go | 4 ++-- testdata/advanced/{expected_gen.go => expected_gen.go.golden} | 0 testdata/basic/{expected_gen.go => expected_gen.go.golden} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename testdata/advanced/{expected_gen.go => expected_gen.go.golden} (100%) rename testdata/basic/{expected_gen.go => expected_gen.go.golden} (100%) diff --git a/integration_test.go b/integration_test.go index 285592a..03f441f 100644 --- a/integration_test.go +++ b/integration_test.go @@ -394,7 +394,7 @@ func TestIntegration_ExpectedOutputMatch(t *testing.T) { } gen := readGenerated(t, dir, out) - expected, err := os.ReadFile(filepath.Join(dir, "expected_gen.go")) + expected, err := os.ReadFile(filepath.Join(dir, "expected_gen.go.golden")) if err != nil { t.Fatalf("reading expected output: %v", err) } @@ -731,7 +731,7 @@ func TestIntegration_AdvancedExpectedOutputMatch(t *testing.T) { } gen := readGenerated(t, dir, out) - expected, err := os.ReadFile(filepath.Join(dir, "expected_gen.go")) + expected, err := os.ReadFile(filepath.Join(dir, "expected_gen.go.golden")) if err != nil { t.Fatalf("reading expected output: %v", err) } diff --git a/testdata/advanced/expected_gen.go b/testdata/advanced/expected_gen.go.golden similarity index 100% rename from testdata/advanced/expected_gen.go rename to testdata/advanced/expected_gen.go.golden diff --git a/testdata/basic/expected_gen.go b/testdata/basic/expected_gen.go.golden similarity index 100% rename from testdata/basic/expected_gen.go rename to testdata/basic/expected_gen.go.golden