forked from signalfx/splunk-otel-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
122 lines (105 loc) · 4.41 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
# Copyright Splunk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
SHELL := /bin/bash
GO = go
TIMEOUT = 60
PKGS = ./...
BUILD_DIR = ./build
TEST_RESULTS = $(CURDIR)/test-results
# Verbose output
V = 0
Q = $(if $(filter 1,$V),,@)
# ALL_MODULES includes ./* dirs (excludes . and ./build dir).
ALL_MODULES := $(shell find . -type f -name "go.mod" -exec dirname {} \; | sort )
# All directories with go.mod files related to opentelemetry library. Used for building, testing and linting.
ALL_GO_MOD_DIRS := $(filter-out $(BUILD_DIR), $(ALL_MODULES))
# All directories sub-modules. Used for tagging.
SUBMODULES = $(filter-out ., $(ALL_GO_MOD_DIRS))
.DEFAULT_GOAL := goyek
.PHONY: goyek
goyek:
./goyek.sh
# Build and test targets
.PHONY: build
build: # build whole codebase
${call for-all-modules,$(GO) build $(PKGS)}
# Compile all test code.
${call for-all-modules,$(GO) test -vet=off -run xxxxxMatchNothingxxxxx $(PKGS) >/dev/null}
TEST_TARGETS := test-bench test-short test-verbose test-race
.PHONY: $(TEST_TARGETS) test tests
test-bench: ARGS=-run=xxxxxMatchNothingxxxxx -test.benchtime=1ms -bench=.
test-short: ARGS=-short
test-verbose: ARGS=-v
test-race: ARGS=-race
$(TEST_TARGETS): test
test tests:
${call for-all-modules,$(GO) test -timeout $(TIMEOUT)s $(ARGS) $(PKGS)}
# Pre-release targets
.PHONY: add-tag
add-tag: # example usage: make add-tag tag=v1.100.1 commit=<hash>
$Q [ "$(tag)" ] || ( echo ">> 'tag' is not set"; exit 1 )
$Q [ "$(commit)" ] || ( echo ">> 'commit' is not set"; exit 1 )
@echo "Adding tag $(tag)"
$Q git tag -a $(tag) -s -m "Version $(tag)" $(commit)
$Q set -e; for dir in $(SUBMODULES); do \
(echo Adding tag "$${dir:2}/$(tag)" && \
git tag -a "$${dir:2}/$(tag)" -s -m "Version ${dir:2}/$(tag)" $(commit)); \
done
.PHONY: delete-tag
delete-tag: # example usage: make delete-tag tag=v1.100.1
$Q [ "$(tag)" ] || ( echo ">> 'tag' is not set"; exit 1 )
@echo "Deleting tag $(tag)"
$Q git tag -d $(tag)
$Q set -e; for dir in $(SUBMODULES); do \
(echo Deleting tag "$${dir:2}/$(tag)" && \
git tag -d "$${dir:2}/$(tag)" ); \
done
.PHONY: push-tag
push-tag: # example usage: make push-tag remote=origin tag=v1.100.1
$Q [ "$(remote)" ] || ( echo ">> 'remote' is not set"; exit 1 )
$Q [ "$(tag)" ] || ( echo ">> 'tag' is not set"; exit 1 )
@echo "Pushing tag $(tag) to $(remote)"
$Q git push $(remote) $(tag)
$Q set -e; for dir in $(SUBMODULES); do \
(echo Pushing tag "$${dir:2}/$(tag) to $(remote)" && \
git push $(remote) "$${dir:2}/$(tag)"); \
done
# Other targets
DEPENDABOT_PATH=./.github/dependabot.yml
.PHONY: gendependabot
gendependabot: # generate dependabot.yml
@echo "Recreate dependabot.yml file"
@printf "# File generated by \"make gendependabot\"; DO NOT EDIT.\n\n" > ${DEPENDABOT_PATH}
@printf "version: 2\n" >> ${DEPENDABOT_PATH}
@printf "updates:\n" >> ${DEPENDABOT_PATH}
@printf " - package-ecosystem: \"github-actions\"\n directory: \"/\"\n schedule:\n interval: \"daily\"\n" >> ${DEPENDABOT_PATH}
@printf " - package-ecosystem: \"docker\"\n directory: \"/build\"\n schedule:\n interval: \"daily\"\n" >> ${DEPENDABOT_PATH}
@echo "Add entry for \"/\""
@printf " - package-ecosystem: \"gomod\"\n directory: \"/\"\n schedule:\n interval: \"daily\"\n" >> ${DEPENDABOT_PATH}
@set -e; for dir in $(filter-out ., $(ALL_MODULES)); do \
(echo "Add entry for \"$${dir:1}\"" && \
printf " - package-ecosystem: \"gomod\"\n directory: \"$${dir:1}\"\n schedule:\n interval: \"daily\"\n" >> ${DEPENDABOT_PATH} ); \
done
.PHONY: for-all
for-all: # run a command in all modules, example: make for-all cmd="go mod tidy"
$Q [ "$(cmd)" ] || ( echo ">> 'cmd' is not set"; exit 1 )
${call for-all-modules, $(cmd)}
define for-all-modules # run provided command for each module
$Q EXIT=0 ;\
for dir in $(ALL_GO_MOD_DIRS); do \
echo "${1} in $${dir}"; \
(cd "$${dir}" && ${1}) || EXIT=$$?; \
done ;\
exit $$EXIT
endef