Skip to content

Commit f0dce97

Browse files
committed
Initial commit
0 parents  commit f0dce97

42 files changed

Lines changed: 5263 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
14+
services:
15+
postgres:
16+
image: postgres:16
17+
env:
18+
POSTGRES_USER: postgres
19+
POSTGRES_PASSWORD: postgres
20+
POSTGRES_DB: postgres
21+
options: >-
22+
--health-cmd "pg_isready -U postgres"
23+
--health-interval 10s
24+
--health-timeout 5s
25+
--health-retries 5
26+
ports:
27+
- 5432:5432
28+
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v4
32+
33+
- name: Set up Go
34+
uses: actions/setup-go@v5
35+
with:
36+
go-version: "1.25"
37+
38+
- name: Download dependencies
39+
run: go mod download
40+
41+
- name: Verify dependencies
42+
run: go mod verify
43+
44+
- name: Run tests with coverage
45+
env:
46+
DB_HOST: localhost
47+
DB_PORT: 5432
48+
DB_USER: postgres
49+
DB_PASSWORD: postgres
50+
DB_NAME: postgres
51+
run: |
52+
go test -v -race -coverprofile=coverage.out $(go list ./... | grep -v -e '/tmp/' -e '/build/')
53+
54+
- name: Check coverage percentage
55+
run: |
56+
COVERAGE=$(go tool cover -func=coverage.out | tail -1 | awk '{print $3}' | sed 's/%//')
57+
echo "Coverage: $COVERAGE%"
58+
echo "Note: Current threshold is 60%. Target is 85%+ as crypto and db packages get full integration tests."
59+
if (( $(echo "$COVERAGE < 60.0" | bc -l) )); then
60+
echo "❌ Coverage $COVERAGE% is below 60% threshold"
61+
exit 1
62+
else
63+
echo "✅ Coverage $COVERAGE% meets the 60% threshold"
64+
fi
65+
66+
- name: Generate coverage report
67+
run: go tool cover -html=coverage.out -o coverage.html
68+
69+
- name: Upload coverage reports to Codecov
70+
uses: codecov/codecov-action@v5
71+
continue-on-error: true
72+
with:
73+
token: ${{ secrets.CODECOV_TOKEN }}
74+
slug: hatmaxkit/hatmax
75+
76+
- name: Upload coverage artifacts
77+
uses: actions/upload-artifact@v4
78+
with:
79+
name: coverage-report
80+
path: coverage.html
81+
82+
build:
83+
runs-on: ubuntu-latest
84+
needs: [test]
85+
86+
steps:
87+
- name: Checkout code
88+
uses: actions/checkout@v4
89+
90+
- name: Set up Go
91+
uses: actions/setup-go@v5
92+
with:
93+
go-version: "1.25"
94+
95+
- name: Build
96+
run: go build -v ./...
97+
98+
- name: Test build works
99+
run: |
100+
echo "Build successful ✅"
101+
go version

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool
12+
coverage.out
13+
coverage.html
14+
15+
# Go workspace file
16+
go.work
17+
go.work.sum
18+
19+
# env files
20+
.env
21+
.env.local
22+
23+
# IDE
24+
.vscode/
25+
.idea/
26+
*.swp
27+
*.swo
28+
*~
29+
30+
# Build artifacts
31+
build/
32+
dist/
33+
bin/
34+
35+
# OS
36+
.DS_Store
37+
Thumbs.db

Makefile

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# Variables
2+
LIB_NAME = hatmax
3+
MODULE_NAME = github.com/hatmaxkit/hatmax
4+
5+
# Default target
6+
all: test
7+
8+
# Help target
9+
help:
10+
@echo "Available targets:"
11+
@echo ""
12+
@echo "Testing:"
13+
@echo " test - Run all tests"
14+
@echo " test-v - Run tests with verbose output"
15+
@echo " test-short - Run tests in short mode"
16+
@echo " test-coverage - Run tests with coverage report"
17+
@echo " test-coverage-profile - Generate coverage profile"
18+
@echo " test-coverage-html - Generate HTML coverage report"
19+
@echo " test-coverage-func - Show function-level coverage"
20+
@echo " test-coverage-check - Check coverage meets 85% threshold"
21+
@echo " test-coverage-100 - Check coverage is 100%"
22+
@echo " test-coverage-summary - Display coverage table by package"
23+
@echo ""
24+
@echo "Quality Checks:"
25+
@echo " lint - Run golangci-lint"
26+
@echo " format - Format code"
27+
@echo " vet - Run go vet"
28+
@echo " check - Run all quality checks (fmt, vet, test, test-coverage-check, lint)"
29+
@echo " ci - Run CI pipeline (strict, 100% coverage)"
30+
@echo ""
31+
@echo "Utilities:"
32+
@echo " clean - Clean coverage files and test cache"
33+
@echo " tidy - Run go mod tidy"
34+
@echo " download - Download dependencies"
35+
36+
# Run linter
37+
lint:
38+
@echo "Running linter and fixing issues..."
39+
@golangci-lint run --fix
40+
41+
# Format code
42+
format:
43+
@echo "Formatting code..."
44+
@gofmt -w .
45+
46+
# Run tests
47+
test:
48+
@go test ./...
49+
50+
# Run tests with verbose output
51+
test-v:
52+
@go test -v ./...
53+
54+
# Run tests in short mode
55+
test-short:
56+
@go test -short ./...
57+
58+
# Run tests with coverage
59+
test-coverage:
60+
@go test -cover ./...
61+
62+
# Generate coverage profile and show percentage
63+
test-coverage-profile:
64+
@go test -coverprofile=coverage.out ./...
65+
@go tool cover -func=coverage.out | tail -1
66+
67+
# Generate HTML coverage report
68+
test-coverage-html: test-coverage-profile
69+
@go tool cover -html=coverage.out -o coverage.html
70+
@echo "Coverage report generated: coverage.html"
71+
72+
# Show function-level coverage
73+
test-coverage-func: test-coverage-profile
74+
@go tool cover -func=coverage.out
75+
76+
# Check coverage percentage and fail if below threshold (85%)
77+
test-coverage-check: test-coverage-profile
78+
@COVERAGE=$$(go tool cover -func=coverage.out | tail -1 | awk '{print $$3}' | sed 's/%//'); \
79+
echo "Current coverage: $$COVERAGE%"; \
80+
if [ $$(awk -v cov="$$COVERAGE" 'BEGIN {print (cov < 85)}') -eq 1 ]; then \
81+
echo "❌ Coverage $$COVERAGE% is below 85% threshold"; \
82+
exit 1; \
83+
else \
84+
echo "✅ Coverage $$COVERAGE% meets the 85% threshold"; \
85+
fi
86+
87+
# Check coverage percentage and fail if not 100%
88+
test-coverage-100: test-coverage-profile
89+
@COVERAGE=$$(go tool cover -func=coverage.out | tail -1 | awk '{print $$3}' | sed 's/%//'); \
90+
echo "Current coverage: $$COVERAGE%"; \
91+
if [ "$$COVERAGE" != "100.0" ]; then \
92+
echo "❌ Coverage $$COVERAGE% is not 100%"; \
93+
go tool cover -func=coverage.out | grep -v "100.0%"; \
94+
exit 1; \
95+
else \
96+
echo "🎉 Perfect! 100% test coverage achieved!"; \
97+
fi
98+
99+
# Display coverage summary table by package
100+
test-coverage-summary:
101+
@echo "🧪 Running coverage tests by package..."
102+
@echo ""
103+
@echo "Coverage by package:"
104+
@echo "┌────────────────────────────────────────────────────────┬──────────┐"
105+
@echo "│ Package │ Coverage │"
106+
@echo "├────────────────────────────────────────────────────────┼──────────┤"
107+
@for pkg in $$(go list ./... | grep -v -e "/tmp/" -e "/build/"); do \
108+
pkgname=$$(echo $$pkg | sed 's|$(MODULE_NAME)||' | sed 's|^/||'); \
109+
if [ -z "$$pkgname" ]; then pkgname="."; fi; \
110+
result=$$(go test -cover $$pkg 2>&1); \
111+
cov=$$(echo "$$result" | grep -oE '[0-9]+\.[0-9]+% of statements' | grep -v '^0\.0%' | tail -1 | grep -oE '[0-9]+\.[0-9]+%'); \
112+
if [ -z "$$cov" ]; then \
113+
if echo "$$result" | grep -qE '\[no test files\]|no test files'; then \
114+
cov="no tests"; \
115+
elif echo "$$result" | grep -q "FAIL"; then \
116+
cov="FAIL"; \
117+
else \
118+
cov="0.0%"; \
119+
fi; \
120+
fi; \
121+
printf "│ %-54s │ %8s │\n" "$$pkgname" "$$cov"; \
122+
done
123+
@echo "└────────────────────────────────────────────────────────┴──────────┘"
124+
125+
# Run go vet
126+
vet:
127+
@go vet ./...
128+
129+
# Run all quality checks
130+
check: format vet test test-coverage-check lint
131+
@echo "✅ All quality checks passed!"
132+
133+
# CI pipeline - strict checks including 100% coverage
134+
ci: format vet test test-coverage-100 lint
135+
@echo "🚀 CI pipeline passed!"
136+
137+
# Clean coverage files and test cache
138+
clean:
139+
@echo "Cleaning up..."
140+
@go clean -testcache
141+
@rm -f coverage.out coverage.html
142+
@echo "Clean complete."
143+
144+
# Run go mod tidy
145+
tidy:
146+
@echo "Running go mod tidy..."
147+
@go mod tidy
148+
149+
# Download dependencies
150+
download:
151+
@echo "Downloading dependencies..."
152+
@go mod download
153+
154+
# Phony targets
155+
.PHONY: all test test-v test-short test-coverage test-coverage-profile test-coverage-html test-coverage-func test-coverage-check test-coverage-100 test-coverage-summary vet check ci lint format help clean tidy download

0 commit comments

Comments
 (0)