-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
218 lines (184 loc) · 6.05 KB
/
Makefile
File metadata and controls
218 lines (184 loc) · 6.05 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
.PHONY: all build install test clean fmt lint help version bump-patch bump-minor bump-major release release-build
.PHONY: docker-build docker-buildx docker-push docker-run docker-clean docker-shell compose-up compose-down compose-logs
# Binary name
BINARY_NAME=plcbundle
INSTALL_PATH=$(GOPATH)/bin
# Docker configuration
DOCKER_IMAGE=plcbundle
DOCKER_TAG=$(VERSION)
DOCKER_REGISTRY?=atscan
DOCKER_FULL_IMAGE=$(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY)/,)$(DOCKER_IMAGE):$(DOCKER_TAG)
DOCKER_LATEST=$(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY)/,)$(DOCKER_IMAGE):latest
DOCKER_PLATFORMS?=linux/amd64,linux/arm64
# Version information
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Go commands
GOCMD=go
GOBUILD=$(GOCMD) build
GOINSTALL=$(GOCMD) install
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOFMT=$(GOCMD) fmt
GOMOD=$(GOCMD) mod
# Test runner - auto-detect gotestsum
GOTESTSUM := $(shell command -v gotestsum 2> /dev/null)
# Build flags
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.gitCommit=$(GIT_COMMIT) -X main.buildDate=$(BUILD_DATE)"
# Default target
all: build
# Build the CLI tool with version info
build:
@echo "Building $(BINARY_NAME) $(VERSION)..."
$(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) ./cmd/plcbundle
# Install the CLI tool globally
install:
@echo "Installing $(BINARY_NAME) ..."
$(GOINSTALL) $(LDFLAGS) ./cmd/plcbundle
# Run tests
test:
ifdef GOTESTSUM
@gotestsum -- ./...
else
@echo "Running tests (install gotestsum for better output: go install gotest.tools/gotestsum@latest)"
@$(GOTEST) -v ./...
endif
# Run tests with coverage
test-coverage:
ifdef GOTESTSUM
@gotestsum --format testname -- -cover ./...
else
@$(GOTEST) -v -cover ./...
endif
# Clean build artifacts
clean:
@echo "Cleaning..."
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -rf dist/
# Format code
fmt:
@echo "Formatting code..."
$(GOFMT) ./...
# Download dependencies
deps:
@echo "Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
# Verify dependencies
verify:
@echo "Verifying dependencies..."
$(GOMOD) verify
# Show current version
version:
@echo "Current version: $(VERSION)"
@echo "Git commit: $(GIT_COMMIT)"
@echo "Build date: $(BUILD_DATE)"
# Bump patch version (0.1.0 -> 0.1.1)
bump-patch:
@echo "Bumping patch version..."
@./scripts/bump-version.sh patch
# Bump minor version (0.1.0 -> 0.2.0)
bump-minor:
@echo "Bumping minor version..."
@./scripts/bump-version.sh minor
# Bump major version (0.1.0 -> 1.0.0)
bump-major:
@echo "Bumping major version..."
@./scripts/bump-version.sh major
# Bump alpha version (0.1.0 -> 0.2.0-alpha.1)
bump-alpha:
@echo "Bumping major version..."
@./scripts/bump-version.sh alpha
# Create release
release:
@echo "Creating release for version $(VERSION)..."
@./scripts/release.sh
# ============================================================================
# Docker Commands
# ============================================================================
# Build Docker image (local)
docker-build:
@echo "Building Docker image $(DOCKER_FULL_IMAGE)..."
docker build \
--build-arg VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg BUILD_DATE="$(BUILD_DATE)" \
-t $(DOCKER_FULL_IMAGE) \
-t $(DOCKER_LATEST) \
.
@echo "✓ Built: $(DOCKER_FULL_IMAGE)"
# Build multi-platform and push
docker-buildx:
@echo "Building multi-platform image $(DOCKER_FULL_IMAGE)..."
docker buildx build \
--platform $(DOCKER_PLATFORMS) \
--build-arg VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg BUILD_DATE="$(BUILD_DATE)" \
--tag $(DOCKER_FULL_IMAGE) \
--tag $(DOCKER_LATEST) \
--push \
.
@echo "✓ Built and pushed: $(DOCKER_FULL_IMAGE) ($(DOCKER_PLATFORMS))"
# Push Docker image
docker-push:
@echo "Pushing Docker image..."
docker push $(DOCKER_FULL_IMAGE)
docker push $(DOCKER_LATEST)
@echo "✓ Pushed: $(DOCKER_FULL_IMAGE)"
# Run Docker container as CLI
docker-run:
@docker run --rm -v $(PWD)/data:/data $(DOCKER_FULL_IMAGE) plcbundle $(CMD)
# Shortcuts
docker-info:
@docker run --rm -v $(PWD)/data:/data $(DOCKER_FULL_IMAGE) plcbundle info
docker-fetch:
@docker run --rm -v $(PWD)/data:/data $(DOCKER_FULL_IMAGE) plcbundle fetch
docker-verify:
@docker run --rm -v $(PWD)/data:/data $(DOCKER_FULL_IMAGE) plcbundle verify
# Run as server
docker-serve:
docker run --rm -it -p 8080:8080 -v $(PWD)/data:/data $(DOCKER_FULL_IMAGE) plcbundle serve --host 0.0.0.0
# Open shell
docker-shell:
docker run --rm -it -v $(PWD)/data:/data $(DOCKER_FULL_IMAGE) sh
# Clean Docker artifacts
docker-clean:
@echo "Cleaning Docker images..."
docker rmi $(DOCKER_FULL_IMAGE) $(DOCKER_LATEST) 2>/dev/null || true
docker image prune -f
# ============================================================================
# Help
# ============================================================================
help:
@echo "Available targets:"
@echo ""
@echo "Build & Install:"
@echo " make build - Build the CLI tool"
@echo " make install - Install CLI tool globally"
@echo " make clean - Clean build artifacts"
@echo ""
@echo "Development:"
@echo " make test - Run tests"
@echo " make test-coverage - Run tests with coverage"
@echo " make fmt - Format code"
@echo " make deps - Download dependencies"
@echo ""
@echo "Release:"
@echo " make version - Show current version"
@echo " make bump-patch - Bump patch (0.1.0 -> 0.1.1)"
@echo " make bump-minor - Bump minor (0.1.0 -> 0.2.0)"
@echo " make bump-major - Bump major (0.1.0 -> 1.0.0)"
@echo " make release - Push tag to trigger release"
@echo ""
@echo "Docker:"
@echo " make docker-build - Build image (current platform)"
@echo " make docker-buildx - Build multi-platform and push"
@echo " make docker-run - Run CLI (CMD='info')"
@echo " make docker-info - Show bundle info"
@echo " make docker-serve - Run as server"
@echo " make docker-shell - Open shell"
@echo ""