Skip to content

Commit

Permalink
feat: Better build, add lint, fix the help rule, adds the right version
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Jul 25, 2024
1 parent 57bc7a0 commit 2df1ea5
Showing 1 changed file with 45 additions and 9 deletions.
54 changes: 45 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,65 @@ GOCOMMAND := go
GOBUILD := $(GOCOMMAND) build
GOCLEAN := $(GOCOMMAND) clean
GOTEST := $(GOCOMMAND) test
GOLINT := $(shell command -v golangci-lint 2>/dev/null)

EXECUTABLE := ikscc
INSTALL_PATH := /usr/local/bin
INSTALL := $(INSTALL_PATH)/$(EXECUTABLE)

PROJECT_CHANGESET := $(shell git rev-parse --verify HEAD 2>/dev/null)


define assert-command
@$(if $(shell command -v $1 2>/dev/null),,$(error $(1) command not found))
endef

BINARY := ./bin/ikscc

.PHONY: help
help:
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make <target>\n\nTargets:\n"} /^[a-z0-9//_-]+:.*?##/ { printf " %-15s %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make <target>\n\nTargets:\n"} /^[a-z0-9\/_-]+:.*?##/ { printf " %-15s %s\n", $$1, $$2 }' $(MAKEFILE_LIST)


.PHONY: lint
lint: ## Lint
$(call assert-command,$(GOLINT))
@$(GOLINT) --verbose run ./...


./bin/$(EXECUTABLE):
ifdef PROJECT_VERSION
@$(GOBUILD) -v -ldflags="-X github.com/jjuarez/iks-ctx-cleaner/cmd.Version='v$(PROJECT_VERSION)'" -o ./bin/$(EXECUTABLE) main.go
else
@$(GOBUILD) -v -ldflags="-X github.com/jjuarez/iks-ctx-cleaner/cmd.Version='nightly:$(PROJECT_CHANGESET)'" -o ./bin/$(EXECUTABLE) main.go
endif


.PHONY: build
build: ## Builds the binary
@$(GOBUILD) -o $(BINARY) -v main.go
build: ./bin/$(EXECUTABLE) ## Builds the binary

.PHONY: run
run: build ## Runs the latest binary
@$(BINARY)

.PHONY: test
test: ## Testing all the things
@$(GOTEST) -v ./...


.PHONY: clean
clean: ## Clean the generated products
@$(GOCLEAN)
@rm -fr $(BINARY) ./dist/*
@rm -fr ./bin/$(EXECUTABLE) ./dist/*


$(INSTALL):
@install -m 0755 ./bin/$(EXECUTABLE) $(INSTALL_PATH)

.PHONY: build install
install: $(INSTALL) ## Installs the program in the system


.PHONY: uninstall
uninstall: ## Uninstalls the program from the system
@rm -f $(INSTALL)


.PHONY: all
all: clean build test
all: lint build test install

0 comments on commit 2df1ea5

Please sign in to comment.