Skip to content

Commit f5bf542

Browse files
rdimitrovdomdomegg
andauthored
Add helpful targets via Makefile (#211)
## Motivation and Context <!-- Why is this change needed? What problem does it solve? --> The following PR: * Adds a Makefile with the most common project-related commands * Updates the CI workflow to leverage that (people testing locally will use the same commands as the CI) * Switches to using the official Golangci-lint action instead of downloading it via curl * Bumps the golangci version (supersedes #144) * Fixes any formatting/linting issues found * Updates the README to reference the new make targets * Runs the schema validation scripts as part of the CI **Next:** * If you are okay I can file a follow up PR afterwards where I can tidy up the CI workflows a bit, it feels there's some overlap. ## How Has This Been Tested? <!-- Have you tested this in a real application? Which scenarios were tested? --> Locally by running the make targets ## Breaking Changes <!-- Will users need to update their code or configurations? --> ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [x] My code follows the repository's style guidelines - [x] New and existing tests pass locally - [ ] I have added appropriate error handling - [ ] I have added or updated documentation as needed ## Additional context <!-- Add any other context, implementation notes, or design decisions --> --------- Signed-off-by: Radoslav Dimitrov <[email protected]> Co-authored-by: Adam Jones <[email protected]>
1 parent 5acd000 commit f5bf542

File tree

7 files changed

+195
-221
lines changed

7 files changed

+195
-221
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,17 @@ name: CI Pipeline
22

33
on:
44
push:
5-
branches: [ main, develop ]
5+
branches: [ main ]
66
pull_request:
7-
branches: [ main, develop ]
7+
branches: [ main ]
88

99
env:
1010
GO_VERSION: '1.23.x'
1111

1212
jobs:
13-
# Lint and Format Check
14-
lint:
15-
name: Lint and Format
16-
runs-on: ubuntu-latest
17-
steps:
18-
- name: Checkout code
19-
uses: actions/checkout@v4
20-
21-
- name: Set up Go
22-
uses: actions/setup-go@v5
23-
with:
24-
go-version: ${{ env.GO_VERSION }}
25-
26-
- name: Install golangci-lint
27-
run: |
28-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.3.1
29-
30-
- name: Run golangci-lint
31-
run: golangci-lint run --timeout=5m
32-
33-
- name: Check Go formatting
34-
run: |
35-
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
36-
echo "The following files are not properly formatted:"
37-
gofmt -s -l .
38-
exit 1
39-
fi
40-
41-
# Build check
42-
build:
43-
name: Build Check
13+
# Build, Lint, and Validate
14+
build-lint-validate:
15+
name: Build, Lint, and Validate
4416
runs-on: ubuntu-latest
4517
steps:
4618
- name: Checkout code
@@ -64,20 +36,28 @@ jobs:
6436
- name: Download dependencies
6537
run: go mod download
6638

67-
- name: Build application
39+
- name: Install golangci-lint
6840
run: |
69-
go build -v ./cmd/...
41+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.3.1
42+
43+
- name: Run lint
44+
run: make lint
45+
46+
- name: Validate schemas and examples
47+
run: make validate
48+
49+
- name: Build application
50+
run: make build
7051

7152
- name: Check for vulnerabilities
7253
run: |
7354
go install golang.org/x/vuln/cmd/govulncheck@latest
7455
govulncheck ./...
7556
76-
# Unit Tests
77-
unit-tests:
78-
name: Unit Tests
57+
# All Tests
58+
tests:
59+
name: Tests
7960
runs-on: ubuntu-latest
80-
needs: [lint, build]
8161
steps:
8262
- name: Checkout code
8363
uses: actions/checkout@v4
@@ -100,9 +80,8 @@ jobs:
10080
- name: Download dependencies
10181
run: go mod download
10282

103-
- name: Run unit tests
104-
run: |
105-
go test -v -race -coverprofile=coverage.out -covermode=atomic ./internal/...
83+
- name: Run all tests
84+
run: make test-all
10685

10786
- name: Upload coverage to Codecov
10887
uses: codecov/codecov-action@v4
@@ -111,54 +90,3 @@ jobs:
11190
flags: unittests
11291
name: codecov-unit
11392
fail_ci_if_error: false
114-
115-
# Integration Tests
116-
integration-tests:
117-
name: Integration Tests
118-
runs-on: ubuntu-latest
119-
needs: [lint, build]
120-
steps:
121-
- name: Checkout code
122-
uses: actions/checkout@v4
123-
124-
- name: Set up Go
125-
uses: actions/setup-go@v5
126-
with:
127-
go-version: ${{ env.GO_VERSION }}
128-
129-
- name: Cache Go modules
130-
uses: actions/cache@v4
131-
with:
132-
path: |
133-
~/.cache/go-build
134-
~/go/pkg/mod
135-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
136-
restore-keys: |
137-
${{ runner.os }}-go-
138-
139-
- name: Download dependencies
140-
run: go mod download
141-
142-
- name: Run integration tests
143-
run: |
144-
chmod +x ./tests/integration/run.sh
145-
./tests/integration/run.sh
146-
147-
# Overall status check
148-
test-summary:
149-
name: Test Summary
150-
runs-on: ubuntu-latest
151-
needs: [unit-tests, integration-tests]
152-
if: always()
153-
steps:
154-
- name: Check test results
155-
run: |
156-
if [[ "${{ needs.unit-tests.result }}" == "success" && "${{ needs.integration-tests.result }}" == "success" ]]; then
157-
echo "✅ All tests passed!"
158-
exit 0
159-
else
160-
echo "❌ Some tests failed:"
161-
echo " Unit tests: ${{ needs.unit-tests.result }}"
162-
echo " Integration tests: ${{ needs.integration-tests.result }}"
163-
exit 1
164-
fi

.github/workflows/integration-tests.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

.github/workflows/unit-tests.yml

Lines changed: 0 additions & 63 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ cmd/registry/registry
88
validate-examples
99
validate-schemas
1010
.idea/
11+
coverage.out
12+
coverage.html

.golangci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ linters:
8383
- return
8484
nestif:
8585
min-complexity: 8
86+
revive:
87+
rules:
88+
- name: use-any
89+
severity: error
90+
disabled: false
8691
exclusions:
8792
generated: lax
8893
presets:
@@ -122,4 +127,4 @@ formatters:
122127
paths:
123128
- third_party$
124129
- builtin$
125-
- examples$
130+
- examples$

Makefile

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
.PHONY: help build test test-unit test-integration test-endpoints test-publish test-all lint lint-fix validate validate-schemas validate-examples check dev-local dev-compose clean publisher
2+
3+
# Default target
4+
help: ## Show this help message
5+
@echo "Available targets:"
6+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " %-20s %s\n", $$1, $$2}'
7+
8+
# Build targets
9+
build: ## Build the registry application
10+
go build ./cmd/registry
11+
12+
publisher: ## Build the publisher tool
13+
cd tools/publisher && ./build.sh
14+
15+
# Test targets
16+
test-unit: ## Run unit tests with coverage
17+
go test -v -race -coverprofile=coverage.out -covermode=atomic ./internal/...
18+
go tool cover -html=coverage.out -o coverage.html
19+
@echo "Coverage report generated: coverage.html"
20+
21+
test: ## Run unit tests (use 'make test-all' to run all tests)
22+
@echo "⚠️ Running unit tests only. Use 'make test-all' to run both unit and integration tests."
23+
@$(MAKE) test-unit
24+
25+
test-integration: ## Run integration tests
26+
./tests/integration/run.sh
27+
28+
test-endpoints: ## Test API endpoints (requires running server)
29+
./scripts/test_endpoints.sh
30+
31+
test-publish: ## Test publish endpoint (requires BEARER_TOKEN env var)
32+
./scripts/test_publish.sh
33+
34+
test-all: test-unit test-integration ## Run all tests (unit and integration)
35+
36+
# Validation targets
37+
validate-schemas: ## Validate JSON schemas
38+
./tools/validate-schemas.sh
39+
40+
validate-examples: ## Validate examples against schemas
41+
./tools/validate-examples.sh
42+
43+
validate: validate-schemas validate-examples ## Run all validation checks
44+
45+
# Lint targets
46+
lint: ## Run linter (includes formatting)
47+
golangci-lint run --timeout=5m
48+
49+
lint-fix: ## Run linter with auto-fix (includes formatting)
50+
golangci-lint run --fix --timeout=5m
51+
52+
# Combined targets
53+
check: lint validate test-all ## Run all checks (lint, validate, unit tests)
54+
@echo "All checks passed!"
55+
56+
# Development targets
57+
dev-compose: ## Start development environment with Docker Compose (builds image automatically)
58+
docker compose up --build
59+
60+
dev-local: ## Run registry locally (requires MongoDB)
61+
go run cmd/registry/main.go
62+
63+
# Cleanup
64+
clean: ## Clean build artifacts and coverage files
65+
rm -f registry
66+
rm -f coverage.out coverage.html
67+
cd tools/publisher && rm -f publisher
68+
69+
70+
.DEFAULT_GOAL := help

0 commit comments

Comments
 (0)