-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
74 lines (59 loc) · 1.58 KB
/
Makefile
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
.PHONY: \
clean \
build \
distribution-tarball \
test \
test-container \
coverage \
coverage-html
# Build constants
VERSION ?= 0.10
PKGNAME ?= rhc-worker-script
GO_SOURCES := $(wildcard src/*.go)
GO_VERSION ?= 1.21
BUILDFLAGS ?=
LDFLAGS ?=
ifeq ($(shell find . -name vendor), ./vendor)
BUILDFLAGS += -mod=vendor
endif
ifdef KEEP_TEST_CONTAINER
_CONTAINER_RM =
else
_CONTAINER_RM = --rm
endif
# -----------------------------------------------------------------------------
all: clean .pre-commit build
.pre-commit:
pre-commit install --install-hooks
touch $@
clean:
@rm -rf build/
@find . -name '.pre-commit' -exec rm -fr {} +
@find . -name 'coverage.out' -exec rm -rf {} +
build: $(GO_SOURCES)
mkdir -p build
CGO_ENABLED=0 go build $(BUILDFLAGS) -ldflags "$(LDFLAGS)" -o build/rhc-script-worker $^
distribution-tarball:
go mod vendor
tar --create \
--gzip \
--file /tmp/$(PKGNAME)-$(VERSION).tar.gz \
--exclude=.git \
--exclude=.vscode \
--exclude=.github \
--exclude=.gitignore \
--exclude=.copr \
--exclude=development \
--transform s/^\./$(PKGNAME)-$(VERSION)/ \
. && mv /tmp/$(PKGNAME)-$(VERSION).tar.gz .
rm -rf ./vendor
# NOTE: We could also add -race option to add detection for race conditions,
# however that significantly increases time execution
test:
go test -coverprofile=coverage.out ./...
test-container:
podman run --replace --name go-test-container $(_CONTAINER_RM) -v $(shell pwd):/app:Z -w /app docker.io/golang:$(GO_VERSION) make test
coverage: test
go tool cover -func=coverage.out
coverage-html: test
go tool cover -html=coverage.out