From e6946e7384dfedb1a439a028167be4d9c22ec22e Mon Sep 17 00:00:00 2001 From: kartik Date: Wed, 1 Apr 2026 11:01:37 +0530 Subject: [PATCH 1/2] infra-update --- .github/ISSUE_TEMPLATE/bug_report.yml | 69 ++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.yml | 38 ++++++++++++ .github/dependabot.yml | 21 +++++++ .github/pull_request_template.md | 21 +++++++ .github/workflows/ci.yml | 58 +++++++++--------- .github/workflows/codeql.yml | 37 ++++++++++++ .golangci.yml | 38 ++++++------ Makefile | 67 +++++++++++++++------ README.md | 6 +- 9 files changed, 287 insertions(+), 68 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml create mode 100644 .github/dependabot.yml create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/codeql.yml diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..d4040c6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,69 @@ +name: Bug Report +description: Report a bug in rabbitwrap +title: "[Bug]: " +labels: ["bug"] +body: + - type: markdown + attributes: + value: | + Thanks for reporting a bug! Please fill out the sections below. + + - type: textarea + id: description + attributes: + label: Description + description: A clear description of the bug. + validations: + required: true + + - type: textarea + id: reproduce + attributes: + label: Steps to Reproduce + description: Minimal steps to reproduce the issue. + placeholder: | + 1. Create a connection with ... + 2. Call Publish() ... + 3. See error ... + validations: + required: true + + - type: textarea + id: expected + attributes: + label: Expected Behavior + description: What you expected to happen. + validations: + required: true + + - type: textarea + id: actual + attributes: + label: Actual Behavior + description: What actually happened. + validations: + required: true + + - type: input + id: go-version + attributes: + label: Go Version + description: Output of `go version`. + placeholder: "go1.22.0 linux/amd64" + validations: + required: true + + - type: input + id: rabbitwrap-version + attributes: + label: rabbitwrap Version + description: The version of rabbitwrap you are using. + placeholder: "v0.1.0" + validations: + required: true + + - type: textarea + id: additional + attributes: + label: Additional Context + description: Any other context, logs, or screenshots. diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..abb2cfb --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,38 @@ +name: Feature Request +description: Suggest a new feature for rabbitwrap +title: "[Feature]: " +labels: ["enhancement"] +body: + - type: markdown + attributes: + value: | + Thanks for suggesting a feature! Please describe it below. + + - type: textarea + id: problem + attributes: + label: Problem + description: What problem does this feature solve? + placeholder: "I'm always frustrated when ..." + validations: + required: true + + - type: textarea + id: solution + attributes: + label: Proposed Solution + description: How would you like this to work? + validations: + required: true + + - type: textarea + id: alternatives + attributes: + label: Alternatives Considered + description: Any alternative solutions or workarounds you've considered. + + - type: textarea + id: additional + attributes: + label: Additional Context + description: Any other context, code examples, or references. diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..0a4eac7 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,21 @@ +version: 2 +updates: + - package-ecosystem: gomod + directory: / + schedule: + interval: weekly + commit-message: + prefix: "deps" + labels: + - dependencies + open-pull-requests-limit: 5 + + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly + commit-message: + prefix: "ci" + labels: + - ci + open-pull-requests-limit: 5 diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..47dbced --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,21 @@ +## Summary + + + +## Motivation + + + +Fixes # + +## Changes + + + +- + +## Checklist + +- [ ] fmt, vet, lint, test, build passes (`make all`) +- [ ] New code has tests where appropriate +- [ ] Breaking changes are documented diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dcdfdb8..7407db4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,47 +11,51 @@ permissions: jobs: test: - name: Test runs-on: ubuntu-latest strategy: matrix: - go-version: ["1.22", "1.23"] + go-version: ["1.22", "1.23", "1.24", "1.25", "1.26"] steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 + - uses: actions/checkout@v6 + - uses: actions/setup-go@v6 with: go-version: ${{ matrix.go-version }} - - run: go test -race -count=1 -coverprofile=coverage.out ./... - - name: Upload coverage - if: matrix.go-version == '1.23' - uses: actions/upload-artifact@v4 + - run: go test -race -count=1 ./... + + coverage: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-go@v6 + with: + go-version: "1.26" + - name: Run tests with coverage + run: go test -race -coverprofile=coverage.out -covermode=atomic ./... + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v6 with: - name: coverage - path: coverage.out + files: coverage.out + fail_ci_if_error: false lint: - name: Lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 + - uses: actions/checkout@v6 + - uses: actions/setup-go@v6 with: - go-version-file: go.mod - - run: go vet ./... - - uses: golangci/golangci-lint-action@v7 + go-version: "1.26" + - uses: golangci/golangci-lint-action@v9 with: - version: latest - - name: staticcheck - run: | - go install honnef.co/go/tools/cmd/staticcheck@latest - staticcheck ./... + version: v2.11 + args: --timeout=5m - build: - name: Build + bench: runs-on: ubuntu-latest + if: github.event_name == 'push' && github.ref == 'refs/heads/main' steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 + - uses: actions/checkout@v6 + - uses: actions/setup-go@v6 with: - go-version-file: go.mod - - run: go build ./... + go-version: "1.26" + - run: go test -bench=. -benchmem ./... + \ No newline at end of file diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..304fbca --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,37 @@ +name: CodeQL + +on: + push: + branches: [main] + pull_request: + branches: [main] + schedule: + - cron: "0 6 * * 1" + +permissions: + security-events: write + contents: read + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Setup Go + uses: actions/setup-go@v6 + with: + go-version: "1.26" + + - name: Initialize CodeQL + uses: github/codeql-action/init@v4 + with: + languages: go + + - name: Build + run: go build ./... + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v4 diff --git a/.golangci.yml b/.golangci.yml index 69f1221..ef390cf 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,36 +1,32 @@ version: "2" linters: - default: standard enable: - errcheck - govet - staticcheck - unused - ineffassign + - misspell - gocritic + - gocyclo - revive + settings: + gocyclo: + min-complexity: 15 + revive: + rules: + - name: exported + disabled: true exclusions: rules: - # Allow unchecked errors in tests for brevity. - - path: _test\.go - linters: - - errcheck - # Allow unused params in tests. - - path: _test\.go - linters: - - revive - text: unused-parameter - # Allow unused ctx in interface implementations. - - linters: - - revive - text: unused-parameter.*ctx - # Allow min/max as parameter names. - linters: - - revive - text: redefines-builtin-id - # Examples prioritize readability over strict error handling. - - path: examples/ - linters: - errcheck - - gocritic + path: _test\.go + - path: examples/ + text: ".*" + +formatters: + enable: + - gofmt + - goimports diff --git a/Makefile b/Makefile index d940d4c..ee5b750 100644 --- a/Makefile +++ b/Makefile @@ -1,36 +1,58 @@ -.PHONY: lint test test-integration build vet staticcheck check docker-up docker-down +GOLANGCI_LINT_VERSION := v2.10.1 -## Run golangci-lint -lint: - golangci-lint run ./... +.PHONY: all setup deps test test-v test-integration vet lint build fmt cover clean ci docker-up docker-down + +all: fmt vet lint test build -## Run staticcheck -staticcheck: - go run honnef.co/go/tools/cmd/staticcheck@latest ./... +## 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; \ + } -## Run unit tests +## Download module dependencies +deps: + go mod download + +## Run all tests with race detector test: go test -race -count=1 ./... -## Run unit tests with coverage -test-cover: - go test -race -count=1 -coverprofile=coverage.out ./... - go tool cover -func=coverage.out - -## Run integration tests (requires RabbitMQ) -test-integration: docker-up - go test -race -count=1 -tags=integration -timeout 120s ./... +## Run tests with verbose output +test-v: + go test -race -v -count=1 ./... ## Run go vet vet: go vet ./... -## Build (verify compilation) +## Run golangci-lint +lint: setup + golangci-lint run ./... + +## Build all packages build: go build ./... -## Run all checks (vet + lint + staticcheck + tests) -check: vet lint staticcheck test +## 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 ## Start RabbitMQ for integration tests docker-up: @@ -39,3 +61,10 @@ docker-up: ## Stop RabbitMQ docker-down: docker compose down + +## Run integration tests (requires RabbitMQ) +test-integration: docker-up + go test -race -count=1 -tags=integration -timeout 120s ./... + +## CI pipeline: vet, lint, test +ci: vet lint test diff --git a/README.md b/README.md index 9656c36..2957666 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ # rabbitwrap [![Go Reference](https://pkg.go.dev/badge/github.com/KARTIKrocks/rabbitwrap.svg)](https://pkg.go.dev/github.com/KARTIKrocks/rabbitwrap) -[![CI](https://github.com/KARTIKrocks/rabbitwrap/actions/workflows/ci.yml/badge.svg)](https://github.com/KARTIKrocks/rabbitwrap/actions/workflows/ci.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/KARTIKrocks/rabbitwrap)](https://goreportcard.com/report/github.com/KARTIKrocks/rabbitwrap) +[![Go Version](https://img.shields.io/github/go-mod/go-version/KARTIKrocks/rabbitwrap)](go.mod) +[![CI](https://github.com/KARTIKrocks/rabbitwrap/actions/workflows/ci.yml/badge.svg)](https://github.com/KARTIKrocks/rabbitwrap/actions/workflows/ci.yml) +[![GitHub tag](https://img.shields.io/github/v/tag/KARTIKrocks/rabbitwrap)](https://github.com/KARTIKrocks/rabbitwrap/releases) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) +[![codecov](https://codecov.io/gh/KARTIKrocks/rabbitwrap/branch/main/graph/badge.svg)](https://codecov.io/gh/KARTIKrocks/rabbitwrap) A production-ready RabbitMQ client wrapper for Go with automatic reconnection, publisher confirms, consumer middleware, and a fluent API. From 2f5776cfec6cc22e32574f9b23f0f7d703a723f3 Mon Sep 17 00:00:00 2001 From: kartik Date: Wed, 1 Apr 2026 11:06:21 +0530 Subject: [PATCH 2/2] add integration test in ci --- .github/workflows/ci.yml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7407db4..a9dd412 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,13 +49,27 @@ jobs: version: v2.11 args: --timeout=5m - bench: + integration: runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/main' + services: + rabbitmq: + image: rabbitmq:3-management-alpine + ports: + - 5672:5672 + env: + RABBITMQ_DEFAULT_USER: guest + RABBITMQ_DEFAULT_PASS: guest + options: >- + --health-cmd "rabbitmq-diagnostics -q check_port_connectivity" + --health-interval 5s + --health-timeout 10s + --health-retries 5 steps: - uses: actions/checkout@v6 - uses: actions/setup-go@v6 with: go-version: "1.26" - - run: go test -bench=. -benchmem ./... - \ No newline at end of file + - name: Run integration tests + run: go test -race -count=1 -tags=integration -timeout 120s ./... + env: + RABBITMQ_URL: amqp://guest:guest@localhost:5672/