-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
48 lines (36 loc) · 1.49 KB
/
Makefile
File metadata and controls
48 lines (36 loc) · 1.49 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
# Alex Mackay 2026
# Build folder (CLI)
BUILD_FOLDER = build
COVERAGE_BUILD_FOLDER ?= $(BUILD_FOLDER)/coverage
UNIT_COVERAGE_OUT ?= $(COVERAGE_BUILD_FOLDER)/ut_cov.out
BIN ?= $(BUILD_FOLDER)/agent-cli
# Packages
PKG ?= github.com/ATMackay/agent
CONSTANTS_PKG ?= $(PKG)/constants
# Git based version
VERSION_TAG ?= $(shell git describe --tags)
GIT_COMMIT ?= $(shell git rev-parse HEAD)
BUILD_DATE ?= $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
COMMIT_DATE ?= $(shell TZ=UTC git show -s --format=%cd --date=format:%Y-%m-%dT%H:%M:%SZ HEAD)
ifndef DIRTY
DIRTY := $(shell if [ -n "$$(git status --porcelain 2>/dev/null)" ]; then echo true; else echo false; fi)
endif
LDFLAGS := -s -w \
-X '$(CONSTANTS_PKG).Version=$(VERSION_TAG)' \
-X '$(CONSTANTS_PKG).CommitDate=$(COMMIT_DATE)' \
-X '$(CONSTANTS_PKG).GitCommit=$(GIT_COMMIT)' \
-X '$(CONSTANTS_PKG).BuildDate=$(BUILD_DATE)' \
-X '$(CONSTANTS_PKG).Dirty=$(DIRTY)'
build:
@mkdir -p build
@echo ">> building $(BIN) (version=$(VERSION_TAG) commit=$(GIT_COMMIT) dirty=$(DIRTY))"
GO111MODULE=on go build -ldflags "$(LDFLAGS)" -o $(BIN)
@echo "Agent server successfully built. To run the application execute './$(BIN) run'"
install: build
mv $(BIN) $(GOBIN)
run: build
@./$(BUILD_FOLDER)/agent-cli run documentor --repo https://github.com/ATMackay/agent
test:
@mkdir -p $(COVERAGE_BUILD_FOLDER)
@go test -cover -coverprofile $(UNIT_COVERAGE_OUT) -v ./...
.PHONY: build install run test