A Transparent and Verifiable Way to Sync the AT Protocol's PLC Directory
1.PHONY: all build install test clean fmt lint help version bump-patch bump-minor bump-major release
2
3# Binary name
4BINARY_NAME=plcbundle
5INSTALL_PATH=$(GOPATH)/bin
6
7# Version information
8VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
9GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
10BUILD_DATE := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
11
12# Go commands
13GOCMD=go
14GOBUILD=$(GOCMD) build
15GOINSTALL=$(GOCMD) install
16GOCLEAN=$(GOCMD) clean
17GOTEST=$(GOCMD) test
18GOGET=$(GOCMD) get
19GOFMT=$(GOCMD) fmt
20GOMOD=$(GOCMD) mod
21
22# Build flags
23LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.gitCommit=$(GIT_COMMIT) -X main.buildDate=$(BUILD_DATE)"
24
25# Default target
26all: build
27
28# Build the CLI tool with version info
29build:
30 @echo "Building $(BINARY_NAME) $(VERSION)..."
31 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) ./cmd/plcbundle
32
33# Install the CLI tool globally
34install:
35 @echo "Installing $(BINARY_NAME) $(VERSION)..."
36 $(GOINSTALL) $(LDFLAGS) ./cmd/plcbundle
37
38# Run tests
39test:
40 @echo "Running tests..."
41 $(GOTEST) -v ./...
42
43# Run tests with coverage
44test-coverage:
45 @echo "Running tests with coverage..."
46 $(GOTEST) -v -cover ./...
47
48# Clean build artifacts
49clean:
50 @echo "Cleaning..."
51 $(GOCLEAN)
52 rm -f $(BINARY_NAME)
53
54# Format code
55fmt:
56 @echo "Formatting code..."
57 $(GOFMT) ./...
58
59# Download dependencies
60deps:
61 @echo "Downloading dependencies..."
62 $(GOMOD) download
63 $(GOMOD) tidy
64
65# Verify dependencies
66verify:
67 @echo "Verifying dependencies..."
68 $(GOMOD) verify
69
70# Show current version
71version:
72 @echo "Current version: $(VERSION)"
73 @echo "Git commit: $(GIT_COMMIT)"
74 @echo "Build date: $(BUILD_DATE)"
75
76# Bump patch version (0.1.0 -> 0.1.1)
77bump-patch:
78 @echo "Bumping patch version..."
79 @./scripts/bump-version.sh patch
80
81# Bump minor version (0.1.0 -> 0.2.0)
82bump-minor:
83 @echo "Bumping minor version..."
84 @./scripts/bump-version.sh minor
85
86# Bump major version (0.1.0 -> 1.0.0)
87bump-major:
88 @echo "Bumping major version..."
89 @./scripts/bump-version.sh major
90
91# Create a release (tags and pushes)
92release:
93 @echo "Creating release for version $(VERSION)..."
94 @./scripts/release.sh
95
96# Show help
97help:
98 @echo "Available targets:"
99 @echo " make build - Build the CLI tool"
100 @echo " make install - Install CLI tool globally"
101 @echo " make test - Run tests"
102 @echo " make test-coverage - Run tests with coverage"
103 @echo " make clean - Clean build artifacts"
104 @echo " make fmt - Format code"
105 @echo " make deps - Download dependencies"
106 @echo " make verify - Verify dependencies"
107 @echo " make version - Show current version"
108 @echo " make bump-patch - Bump patch version (0.1.0 -> 0.1.1)"
109 @echo " make bump-minor - Bump minor version (0.1.0 -> 0.2.0)"
110 @echo " make bump-major - Bump major version (0.1.0 -> 1.0.0)"
111 @echo " make release - Create and push release tag"
112 @echo " make help - Show this help"