Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 58 additions & 75 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,116 +1,99 @@
# Gitmit Makefile
BINARY_NAME := gitmit

# Variables
BINARY_NAME=gitmit
VERSION=$(shell git describe --tags --always --dirty)
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS=-ldflags "-X main.version=${VERSION} -X main.buildTime=${BUILD_TIME}"
ifeq ($(OS),Windows_NT)
EXE_NAME := $(BINARY_NAME).exe
INSTALL_DIR := $(USERPROFILE)\bin
else
EXE_NAME := $(BINARY_NAME)
INSTALL_DIR := /usr/local/bin
endif

VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
BUILD_TIME := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS := -ldflags "-X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME)"

BIN_DIR := bin
BIN_PATH := $(BIN_DIR)/$(EXE_NAME)

# Default target
.PHONY: all
all: clean test build
all: test build

.PHONY: prepare
prepare:
mkdir -p $(BIN_DIR)

# Build the binary
.PHONY: build
build:
@echo "Building ${BINARY_NAME}..."
go build ${LDFLAGS} -o ${BINARY_NAME}
build: prepare
@echo "Building $(BINARY_NAME)..."
go build $(LDFLAGS) -o $(BIN_PATH) .

# Build for multiple platforms
.PHONY: build-all
build-all: clean
build-all:
@echo "Building for multiple platforms..."
GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o dist/${BINARY_NAME}-linux-amd64
GOOS=darwin GOARCH=amd64 go build ${LDFLAGS} -o dist/${BINARY_NAME}-darwin-amd64
GOOS=darwin GOARCH=arm64 go build ${LDFLAGS} -o dist/${BINARY_NAME}-darwin-arm64
GOOS=windows GOARCH=amd64 go build ${LDFLAGS} -o dist/${BINARY_NAME}-windows-amd64.exe
mkdir -p dist

GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-linux-amd64 .
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-darwin-amd64 .
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-darwin-arm64 .
GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-windows-amd64.exe .

# Run tests
.PHONY: test
test:
@echo "Running tests..."
go test -v ./...

# Run tests with coverage
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
go test -v -coverprofile=coverage.out ./...
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html

# Run linting
.PHONY: lint
lint:
@echo "Running linter..."
golangci-lint run

# Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
go fmt -s ./...
go fmt -s ./...

# Vet code
.PHONY: vet
vet:
@echo "Vetting code..."
go vet ./...

# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning..."
rm -f ${BINARY_NAME}
rm -rf dist/
rm -f coverage.out coverage.html
.PHONY: lint
lint:
golangci-lint run

# Install dependencies
.PHONY: deps
deps:
@echo "Installing dependencies..."
go mod download
go mod tidy

# Install the binary
.PHONY: install
install: build
@echo "Installing ${BINARY_NAME}..."
sudo mv ${BINARY_NAME} /usr/local/bin/

# Uninstall the binary
.PHONY: uninstall
uninstall:
@echo "Uninstalling ${BINARY_NAME}..."
sudo rm -f /usr/local/bin/${BINARY_NAME}
.PHONY: clean
clean:
rm -rf $(BIN_DIR)
rm -rf dist
rm -f coverage.out coverage.html

# Run the application
.PHONY: run
run: build
./${BINARY_NAME}
./$(BIN_PATH)

.PHONY: install
install:
go install .

# Development setup
.PHONY: dev-setup
dev-setup:
@echo "Setting up development environment..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go mod download

# Help
.PHONY: help
help:
@echo "Available targets:"
@echo " all - Clean, test, and build"
@echo " build - Build the binary"
@echo " build-all - Build for multiple platforms"
@echo " test - Run tests"
@echo " test-coverage- Run tests with coverage report"
@echo " lint - Run linter"
@echo " fmt - Format code"
@echo " vet - Vet code"
@echo " clean - Clean build artifacts"
@echo " deps - Install dependencies"
@echo " install - Install binary to /usr/local/bin"
@echo " uninstall - Remove binary from /usr/local/bin"
@echo " run - Build and run the application"
@echo " dev-setup - Set up development environment"
@echo " help - Show this help message"
@echo "Targets:"
@echo " build"
@echo " build-all"
@echo " test"
@echo " test-coverage"
@echo " fmt"
@echo " vet"
@echo " lint"
@echo " deps"
@echo " clean"
@echo " run"
@echo " install"
@echo " dev-setup"
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
)

var (
version = "1.0.1"
version = "1.0.6"
// Global flags
interactiveFlag bool
suggestionsFlag bool
Expand Down Expand Up @@ -40,7 +40,7 @@
rootCmd.PersistentFlags().BoolVarP(&suggestionsFlag, "suggestions", "s", false, "Show multiple ranked suggestions")
}

func Execute() error {

Check failure on line 43 in cmd/root.go

View workflow job for this annotation

GitHub Actions / Build and Test

exported function Execute should have comment or be unexported
// ✅ Added: if no subcommand provided, fallback to "propose"
if len(os.Args) == 1 {
return proposeCmd.RunE(rootCmd, nil)
Expand Down
Loading