-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
143 lines (114 loc) · 3.41 KB
/
Makefile
File metadata and controls
143 lines (114 loc) · 3.41 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
# Variables
GOLANGCI_LINT := $(shell which golangci-lint)
PKGS := $(shell go list ./...)
BUILD_DIR := build
CMD_UNDO_DIR = ./cmd/git-undo
CMD_BACK_DIR = ./cmd/git-back
UNDO_MAIN_FILE := $(CMD_UNDO_DIR)/main.go
BACK_MAIN_FILE := $(CMD_BACK_DIR)/main.go
UNDO_BINARY_NAME := git-undo
BACK_BINARY_NAME := git-back
INSTALL_DIR := $(shell go env GOPATH)/bin
# VERSION will be set when manually building from source
# pseudo_version will return the same format as the Go does.
VERSION := $(shell ./scripts/src/pseudo_version.sh 2>/dev/null || echo "")
# Only add the flag when VERSION isn't empty
LDFLAGS := $(if $(strip $(VERSION)),-X "main.version=$(VERSION)")
# Default target
all: build
# Build both binaries
.PHONY: build
build: build-undo build-back
# Build the git-undo binary
.PHONY: build-undo
build-undo:
@mkdir -p $(BUILD_DIR)
@go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(UNDO_BINARY_NAME) $(UNDO_MAIN_FILE)
# Build the git-back binary
.PHONY: build-back
build-back:
@mkdir -p $(BUILD_DIR)
@go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BACK_BINARY_NAME) $(BACK_MAIN_FILE)
# Run the git-undo binary
.PHONY: run
run: build-undo
./$(BUILD_DIR)/$(UNDO_BINARY_NAME)
# Run the git-back binary
.PHONY: run-back
run-back: build-back
./$(BUILD_DIR)/$(BACK_BINARY_NAME)
# Run tests
.PHONY: test
test:
@go test -v ./...
# Run integration tests in dev mode (test current changes)
.PHONY: integration-test-dev
integration-test-dev:
@./scripts/run-integration.sh --dev
# Run integration tests in production mode (test real user experience)
.PHONY: integration-test-prod
integration-test-prod:
@./scripts/run-integration.sh --prod
# Run integration tests (alias for dev mode)
.PHONY: integration-test
integration-test: integration-test-dev
# Run all tests (unit + integration dev)
.PHONY: test-all
test-all: test integration-test-dev
# Tidy: format and vet the code
.PHONY: tidy
tidy:
@go fmt $(PKGS)
@go vet $(PKGS)
@go mod tidy
# Install golangci-lint only if it's not already installed
.PHONY: lint-install
lint-install:
@if ! [ -x "$(GOLANGCI_LINT)" ]; then \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
fi
# Lint the code using golangci-lint
# todo reuse var if possible
.PHONY: lint
lint: lint-install
$(shell which golangci-lint) run
# Check shell scripts using shellcheck
.PHONY: sc
sc:
@echo "Running shellcheck on all shell scripts..."
@find scripts/ -name "*.sh" -o -name "*.bash" -o -name "*.zsh" | xargs shellcheck || true
# Install both binaries globally with custom version info
.PHONY: binary-install
binary-install: binary-install-undo binary-install-back
# Install git-undo binary globally
.PHONY: binary-install-undo
binary-install-undo:
@echo "Installing git-undo with version: $(VERSION)"
@go install -ldflags "$(LDFLAGS)" $(CMD_UNDO_DIR)
# Install git-back binary globally
.PHONY: binary-install-back
binary-install-back:
@echo "Installing git-back with version: $(VERSION)"
@go install -ldflags "$(LDFLAGS)" $(CMD_BACK_DIR)
# Install with support for verbose flag
.PHONY: install
install:
./install.sh
# Install with verbose output
.PHONY: install-verbose
install-verbose:
./install.sh --verbose
.PHONY: uninstall
uninstall:
./uninstall.sh
# Uninstall both binaries
.PHONY: binary-uninstall
binary-uninstall:
rm -f $(INSTALL_DIR)/$(UNDO_BINARY_NAME)
rm -f $(INSTALL_DIR)/$(BACK_BINARY_NAME)
.PHONY: buildscripts
buildscripts:
@./scripts/build.sh
.PHONY: update
update:
./update.sh