generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
168 lines (132 loc) · 4.57 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
include ./Makefile.Common
RUN_CONFIG?=local/config.yaml
CMD?=
OTEL_VERSION=main
OTEL_STABLE_VERSION=main
VERSION=$(shell git describe --always --match "v[0-9]*" HEAD)
MOD_NAME=github.com/kyma-project/opentelemetry-collector-components
GROUP ?= all
FOR_GROUP_TARGET=for-$(GROUP)-target
FIND_MOD_ARGS=-type f -name "go.mod"
TO_MOD_DIR=dirname {} \; | sort | grep -E '^./'
EX_COMPONENTS=-not -path "./receiver/*" -not -path "./processor/*" -not -path "./exporter/*" -not -path "./extension/*" -not -path "./connector/*"
EX_INTERNAL=-not -path "./internal/*"
EX_CMD=-not -path "./cmd/*"
# NONROOT_MODS includes ./* dirs (excludes . dir)
NONROOT_MODS := $(shell find . $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
RECEIVER_MODS := $(shell find ./receiver/* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
CMD_MODS := $(shell find ./cmd/* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )
OTHER_MODS := $(shell find . $(EX_COMPONENTS) $(EX_INTERNAL) $(EX_CMD) $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) ) $(PWD)
ALL_MODS := $(RECEIVER_MODS) $(CMD_MODS) $(OTHER_MODS)
.DEFAULT_GOAL := all
all-modules:
@echo $(NONROOT_MODS) | tr ' ' '\n' | sort
all-groups:
@echo "receiver: $(RECEIVER_MODS)"
@echo "cmd: $(CMD_MODS)"
@echo "other: $(OTHER_MODS)"
.PHONY: all
all: install-tools all-common gotest
.PHONY: all-common
all-common:
@$(MAKE) $(FOR_GROUP_TARGET) TARGET="common"
.PHONY: gotidy
gotidy:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="tidy"
.PHONY: gomoddownload
gomoddownload:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="moddownload"
.PHONY: gotest
gotest:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="test"
.PHONY: gotest-with-cover
gotest-with-cover:
@$(MAKE) $(FOR_GROUP_TARGET) TARGET="test-with-cover"
$(GOCMD) tool covdata textfmt -i=./coverage/unit -o ./$(GROUP)-coverage.txt
.PHONY: gofmt
gofmt:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="fmt"
.PHONY: golint
golint:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="lint"
.PHONY: golintfix
golintfix:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="lintfix"
.PHONY: for-all
for-all:
@echo "running $${CMD} in root"
@$${CMD}
@set -e; for dir in $(NONROOT_MODS); do \
(cd "$${dir}" && \
echo "running $${CMD} in $${dir}" && \
$${CMD} ); \
done
# Define a delegation target for each module
.PHONY: $(ALL_MODS)
$(ALL_MODS):
@echo "Running target '$(TARGET)' in module '$@' as part of group '$(GROUP)'"
$(MAKE) --no-print-directory -C $@ $(TARGET)
# Trigger each module's delegation target
.PHONY: for-all-target
for-all-target: $(ALL_MODS)
.PHONY: for-receiver-target
for-receiver-target: $(RECEIVER_MODS)
.PHONY: for-cmd-target
for-cmd-target: $(CMD_MODS)
.PHONY: for-other-target
for-other-target: $(OTHER_MODS)
# Debugging target, which helps to quickly determine whether for-all-target is working or not.
.PHONY: all-pwd
all-pwd:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="pwd"
.PHONY: run
run:
cd ./cmd/otelkymacol && GO111MODULE=on $(GOCMD) run --race . --config ../../${RUN_CONFIG} ${RUN_ARGS}
.PHONY: generate
generate: install-tools
cd ./internal/tools && go install go.opentelemetry.io/collector/cmd/mdatagen
$(MAKE) for-all CMD="$(GOCMD) generate ./..."
$(MAKE) gofmt
.PHONY: genotelkymacol
genotelkymacol: $(BUILDER)
$(BUILDER) --skip-compilation --config cmd/otelkymacol/builder-config.yaml
$(MAKE) --no-print-directory -C cmd/otelkymacol fmt
# Build the Collector executable.
.PHONY: otelkymacol
otelkymacol:
cd ./cmd/otelkymacol && GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -trimpath -o ../../bin/otelkymacol_$(GOOS)_$(GOARCH)$(EXTENSION) -tags $(GO_BUILD_TAGS) .
.PHONY: crosslink
crosslink: $(CROSSLINK)
@echo "Executing crosslink"
$(CROSSLINK) --root=$(shell pwd) --prune
.PHONY: clean
clean:
@echo "Removing coverage files"
find . -type f -name 'coverage.txt' -delete
find . -type f -name 'coverage.html' -delete
find . -type f -name 'coverage.out' -delete
.PHONY: checks
checks:
$(MAKE) crosslink
$(MAKE) -j4 gotidy
git diff --exit-code || (echo 'Some files need committing' && git status && exit 1)
.PHONY: check-coverage
check-coverage: $(GO_TEST_COVERAGE) gotest-with-cover
$(GO_TEST_COVERAGE) --config=./.testcoverage.yml
# ( git tag -a $$($$dir | sed s/^.\\///)/$(OCC_VERSION) -m "Release $(OCC_VERSION)" ); \
.PHONY: create-and-push-tags
create-and-push-tags:
@if [ -z "$(OCC_VERSION)" ]; then \
echo "OCC_VERSION is not set"; \
exit 1; \
fi
@if [ -z "$(REMOTE)" ]; then \
echo "REMOTE is not set"; \
exit 1; \
fi
# execute git tag for every item in $(RECEIVER_MODS)
@set -e; for dir in $(RECEIVER_MODS); do \
clean_dir=$$(echo $$dir | sed s/^.\\///); \
git tag -a $$clean_dir/v$(OCC_VERSION) -m "Release $(OCC_VERSION)"; \
git push $(REMOTE) $$clean_dir/v$(OCC_VERSION); \
done