-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
140 lines (119 loc) · 4.56 KB
/
Makefile
File metadata and controls
140 lines (119 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
.PHONY: build release test test-unit clean install uninstall help bump bump-major bump-minor bump-patch version-current
# Default target - build the project
all: build
# Display available targets
help:
@echo "Available make targets:"
@echo " build - Build the note binary"
@echo " release - Build release binary with version from current git tag"
@echo " test - Run all tests (unit, integration, completion, setup)"
@echo " test-unit - Run Go unit tests only"
@echo " integration-test - Run integration tests"
@echo " completion-test - Run completion functionality tests"
@echo " setup-test - Run setup/config integration tests"
@echo " install - Install note system-wide (requires sudo)"
@echo " uninstall - Remove note from system"
@echo " clean - Clean build artifacts"
@echo " dev - Build and show help"
@echo " fmt - Format Go code"
@echo " vet - Run go vet"
@echo ""
@echo "Version management:"
@echo " version-current - Show current version from git tags"
@echo " bump - Bump patch version (default, same as bump-patch)"
@echo " bump-major - Bump major version (X.0.0) and create git tag"
@echo " bump-minor - Bump minor version (x.X.0) and create git tag"
@echo " bump-patch - Bump patch version (x.x.X) and create git tag"
# Build variables
BINARY_NAME=note
INSTALL_PATH=/usr/local/bin
# Build the application
build:
go build -o $(BINARY_NAME)
# Build release with version information
release:
@CURRENT_TAG=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \
VERSION=$${CURRENT_TAG#v}; \
echo "Building release version: $$VERSION"; \
go build -ldflags "-X 'main.Version=$$VERSION' -X 'main.CommitSHA=$(shell git rev-parse --short HEAD)' -X 'main.BuildDate=$(shell date -u +'%Y-%m-%d_%H:%M:%SUTC')'" -o $(BINARY_NAME)
# Version management targets
version-current:
@git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"
# Default bump command (patch version)
bump: bump-patch
bump-major:
@echo "Bumping MAJOR version..."
@CURRENT=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \
CURRENT=$${CURRENT#v}; \
MAJOR=$$(echo $$CURRENT | cut -d. -f1); \
NEW_VERSION="v$$((MAJOR + 1)).0.0"; \
echo "Current version: v$$CURRENT"; \
echo "New version: $$NEW_VERSION"; \
git tag -a $$NEW_VERSION -m "Release $$NEW_VERSION"; \
echo "Created tag $$NEW_VERSION"
bump-minor:
@echo "Bumping MINOR version..."
@CURRENT=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \
CURRENT=$${CURRENT#v}; \
MAJOR=$$(echo $$CURRENT | cut -d. -f1); \
MINOR=$$(echo $$CURRENT | cut -d. -f2); \
NEW_VERSION="v$$MAJOR.$$((MINOR + 1)).0"; \
echo "Current version: v$$CURRENT"; \
echo "New version: $$NEW_VERSION"; \
git tag -a $$NEW_VERSION -m "Release $$NEW_VERSION"; \
echo "Created tag $$NEW_VERSION"
bump-patch:
@echo "Bumping PATCH version..."
@CURRENT=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \
CURRENT=$${CURRENT#v}; \
MAJOR=$$(echo $$CURRENT | cut -d. -f1); \
MINOR=$$(echo $$CURRENT | cut -d. -f2); \
PATCH=$$(echo $$CURRENT | cut -d. -f3); \
NEW_VERSION="v$$MAJOR.$$MINOR.$$((PATCH + 1))"; \
echo "Current version: v$$CURRENT"; \
echo "New version: $$NEW_VERSION"; \
git tag -a $$NEW_VERSION -m "Release $$NEW_VERSION"; \
echo "Created tag $$NEW_VERSION"
# Run all tests (unit, integration, completion, setup)
test: test-unit integration-test completion-test setup-test
# Run unit tests only
test-unit:
go test -v ./...
# Run integration tests
integration-test: build
./scripts/integration_test.sh
# Run completion tests
completion-test: build
./scripts/completion_test.sh
# Run setup integration tests
setup-test: build
./scripts/setup_integration_test.sh
# Clean build artifacts
clean:
go clean
rm -f $(BINARY_NAME)
# Install the binary system-wide (requires sudo)
install: build
sudo cp $(BINARY_NAME) $(INSTALL_PATH)/
@echo "Installing bash completions..."
@if [ -d /etc/bash_completion.d ]; then \
sudo cp completions/bash/note /etc/bash_completion.d/; \
echo "Bash completions installed to /etc/bash_completion.d/"; \
else \
echo "Bash completion directory not found. Please manually source completions/bash/note"; \
fi
@echo "note installed to $(INSTALL_PATH)/$(BINARY_NAME)"
# Uninstall the binary
uninstall:
sudo rm -f $(INSTALL_PATH)/$(BINARY_NAME)
sudo rm -f /etc/bash_completion.d/note
@echo "note uninstalled"
# Development - build and run with example
dev: build
./$(BINARY_NAME) --help
# Format the code
fmt:
go fmt ./...
# Run go vet
vet:
go vet ./...