This repository was archived by the owner on Sep 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
147 lines (123 loc) · 4.56 KB
/
Copy pathMakefile
File metadata and controls
147 lines (123 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Makefile for protoc-gen-go-triple project
# This makefile is for ci test and local development
VERSION ?= latest
GO = go
GO_PATH = $(shell $(GO) env GOPATH)
GO_OS = $(shell $(GO) env GOOS)
ifeq ($(GO_OS), darwin)
GO_OS = mac
endif
GO_BUILD = $(GO) build
GO_GET = $(GO) get
GO_TEST = $(GO) test
GO_BUILD_FLAGS = -v
GO_BUILD_LDFLAGS = -X main.version=$(VERSION)
SHELL = /bin/bash
# Uncomment to enable strict mode for all recipes (verify CI tolerance first)
# .SHELLFLAGS := -eu -o pipefail -c
# goimports version (compatible with older local Go toolchains)
GOIMPORTS_VERSION ?= v0.1.5
# GolangCI-Lint version to install locally (v1.x to match config)
GOLANGCI_LINT_VERSION ?= v1.64.4
.PHONY: help
help: ## Show this help message
@echo 'Usage: make [target]'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.PHONY: prepare
prepare: ## Prepare development environment
@echo "Preparing development environment..."
@go mod download
@$(GO) install golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION)
.PHONY: deps
deps: prepare ## Install dependencies
@echo "Installing dependencies..."
@go mod tidy -v
@go mod download
.PHONY: fmt
fmt: ## Format code
@echo "Formatting code..."
@$(GO) fmt ./...
@if [ ! -x "$(GO_PATH)/bin/goimports" ]; then \
$(GO) install golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION); \
fi
@"$(GO_PATH)/bin/goimports" -w -local github.com/dubbogo/protoc-gen-go-triple/v3 .
.PHONY: test
test: ## Run tests
@echo "Running tests..."
@$(GO_TEST) -v -race -coverprofile=coverage.txt -covermode=atomic ./...
.PHONY: test-short
test-short: ## Run tests without race detection
@echo "Running tests (short mode)..."
@$(GO_TEST) -v ./...
.PHONY: build
build: ## Build the project
@echo "Building project..."
@$(GO) build $(GO_BUILD_FLAGS) -ldflags="$(GO_BUILD_LDFLAGS)" ./...
.PHONY: install
install: ## Install the protoc plugin
@echo "Installing protoc-gen-go-triple..."
@$(GO) install -v -ldflags="$(GO_BUILD_LDFLAGS)" ./...
.PHONY: clean
clean: ## Clean build artifacts
@echo "Cleaning build artifacts..."
@rm -rf coverage.txt
@rm -rf license-header-checker*
@go clean -cache -testcache
.PHONY: verify
verify: clean fmt test ## Verify code quality (fmt + test)
## Note: CI no longer enforces gofmt/goimports; keep fmt for local use only
.PHONY: lint
lint: ## Run golangci-lint
@echo "Running golangci-lint..."
@if ! command -v golangci-lint >/dev/null 2>&1; then \
$(MAKE) lint-install; \
fi
@golangci-lint run ./...
.PHONY: lint-install
lint-install: ## Install golangci-lint
@echo "Installing golangci-lint..."
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
sh -s -- -b $$(go env GOPATH)/bin $(GOLANGCI_LINT_VERSION)
.PHONY: lint-version
lint-version: ## Show installed golangci-lint version
@which golangci-lint >/dev/null 2>&1 && golangci-lint --version | head -n1 || echo "golangci-lint not installed"
.PHONY: lint-upgrade
lint-upgrade: ## Force install requested golangci-lint version
@echo "Upgrading golangci-lint to $(GOLANGCI_LINT_VERSION)..."
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
sh -s -- -b $$(go env GOPATH)/bin $(GOLANGCI_LINT_VERSION)
.PHONY: all
all: clean prepare deps fmt lint test build ## Run all checks and build
.PHONY: ci
ci: verify lint ## Run CI checks (verify + lint)
.PHONY: coverage
coverage: test ## Generate coverage report
@echo "Generating coverage report..."
@go tool cover -html=coverage.txt -o coverage.html
@echo "Coverage report generated: coverage.html"
.PHONY: proto-test
proto-test: ## Test protoc plugin with sample proto files
@echo "Testing protoc plugin..."
@if [ -d "test" ]; then \
cd test && ./test.sh; \
else \
echo "Test directory not found"; \
fi