-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
88 lines (69 loc) · 1.83 KB
/
Copy pathMakefile
File metadata and controls
88 lines (69 loc) · 1.83 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
-include .env
ifneq ($(wildcard .env),)
export $(shell sed 's/=.*//' .env)
endif
PRJ := $(shell head -n1 go.mod | sed 's/^module //')
# Build with this module's go.mod even if a parent go.work omits this repo.
export GOWORK=off
BINDIR=dist
DISTFILE=adm
BUILD_VERSION ?= `git describe --tags 2>/dev/null || echo v0.1.0`
LDFLAGS := -ldflags "-X main.version=$(VERSION) -X main.gitCommit=$(COMMIT)"
DESTDIR?=/usr/local
ifdef TAGS
TAGS_ARGS = -tags ${TAGS}
endif
.PHONY: all
all: build
.PHONY: build
build:
$(foreach dir,$(wildcard cmd/*), echo "$(dir) building..."; go build $(FLAGS) -o $(BINDIR)/ ./$(dir);)
.PHONY: docker-build
docker-build: # set token into GITHUB_TOKEN environment variable
docker build -f Dockerfile -t local:$(PRJ) --secret id=github_token,env=GITHUB_TOKEN .
.PHONY: test
test:
go tool ginkgo ./...
.PHONY: run
run: build
./$(BINDIR)/$(APP)
.PHONY: run-log
run-log: tidy build
SLOG_LEVEL=debug ./$(BINDIR)/$(APP)
.PHONY: run-race
run-race: tidy
go run -race $(LDFLAGS) ./cmd/$(APP)
# Code quality checks
.PHONY: lint
lint:
go tool golangci-lint run ./...
# Code quality checks with autofix
.PHONY: lint-fix
lint-fix:
go tool golangci-lint run -v --fix ./...
.PHONY: tidy
tidy:
go mod tidy
.PHONY: install
install: build
@echo "Installing..."
@install -DZs dist/${DISTFILE} -m 755 -t ${DESTDIR}/bin
@install -D dist/adm.1.gz -t ${DESTDIR}/share/man/man1
@echo "Done"
.PHONY: install-config
install-config:
@install -DZ res/admrc -m 644 -T ${DESTDIR}/etc/adm/admrc
@install -d -m 755 ${DESTDIR}/etc/adm/peruser
.PHONY: install-pam
install-pam:
@install -DZ res/pam -m 644 -T ${DESTDIR}/etc/pam.d/adm
.PHONY: install-systemd
install-systemd:
@install -DZ res/systemd-service -m 644 -T ${DESTDIR}/lib/systemd/system/adm.service
.PHONY: sloc
sloc:
cloc * >sloc.stats
.PHONY: clean
clean:
go clean
rm -rf $(BINDIR)