-
Notifications
You must be signed in to change notification settings - Fork 35
/
Makefile
131 lines (103 loc) · 4.32 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
GO := GO111MODULE=on go
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
GOHOSTOS ?= $(shell $(GO) env GOHOSTOS)
GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH)
ifeq (arm, $(GOHOSTARCH))
GOHOSTARM ?= $(shell GOARM= $(GO) env GOARM)
GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)v$(GOHOSTARM)
else
GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)
endif
PROMU := $(FIRST_GOPATH)/bin/promu
PROMU_VERSION ?= 0.13.0
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
# this is the what ends up in the RPM "Version" field and embedded in the --version CLI flag
VERSION ?= $(shell .ci/get_version_from_git.sh)
# if you want to release to OBS, this must be a remotely available Git reference
REVISION ?= $(shell git rev-parse --abbrev-ref HEAD)
# we only use this to comply with RPM changelog conventions at SUSE
AUTHOR ?= shap-staff@suse.de
# you can customize any of the following to build forks
OBS_PROJECT ?= devel:sap:monitoring:factory
REPOSITORY ?= clusterlabs/ha_cluster_exporter
# the Go archs we crosscompile to
ARCHS ?= amd64 arm64 ppc64le s390x
default: clean mod-tidy generate fmt vet-check test build
promu-prepare:
sed "s/{{.Version}}/$(VERSION)/" .promu.yml >.promu.release.yml
mkdir -p build/bin
# from https://github.com/prometheus/prometheus/blob/main/Makefile.common
$(PROMU):
$(eval PROMU_TMP := $(shell mktemp -d))
curl -s -L $(PROMU_URL) | tar -xvzf - -C $(PROMU_TMP)
mkdir -p $(FIRST_GOPATH)/bin
cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu
rm -r $(PROMU_TMP)
build:
$(MAKE) clean
$(MAKE) promu-prepare $(PROMU)
$(MAKE) amd64
build-all:
$(MAKE) clean
$(MAKE) promu-prepare $(PROMU)
$(MAKE) $(ARCHS)
$(ARCHS):
GOOS=linux GOARCH=$@ $(PROMU) build --config .promu.release.yml --prefix=build/bin ha_cluster_exporter-$@
install:
$(GO) install
static-checks: vet-check fmt-check
vet-check:
$(GO) vet ./...
fmt:
$(GO) fmt ./...
mod-tidy:
$(GO) mod tidy
fmt-check:
.ci/go_lint.sh
generate:
$(GO) generate ./...
test:
$(GO) test -v ./...
checks: static-checks test
coverage:
@mkdir -p build
$(GO) test -cover -coverprofile=build/coverage ./...
$(GO) tool cover -html=build/coverage
clean:
$(GO) clean
rm -rf build
rm -f .promu.release.yml
exporter-obs-workdir: build/obs/prometheus-ha_cluster_exporter
build/obs/prometheus-ha_cluster_exporter:
@mkdir -p $@
osc checkout $(OBS_PROJECT) prometheus-ha_cluster_exporter -o $@
rm -f $@/*.tar.gz
cp -rv packaging/obs/prometheus-ha_cluster_exporter/* $@/
# we interpolate environment variables in OBS _service file so that we control what is downloaded by the tar_scm source service
sed -i 's~%%VERSION%%~$(VERSION)~' $@/_service
sed -i 's~%%REVISION%%~$(REVISION)~' $@/_service
sed -i 's~%%REPOSITORY%%~$(REPOSITORY)~' $@/_service
go mod vendor
tar --sort=name --mtime='UTC 1970-01-01' -c vendor | gzip -n > $@/vendor.tar.gz
cd $@; osc service manualrun
exporter-obs-changelog: exporter-obs-workdir
.ci/gh_release_to_obs_changeset.py $(REPOSITORY) -a $(AUTHOR) -t $(REVISION) -f build/obs/prometheus-ha_cluster_exporter/prometheus-ha_cluster_exporter.changes
exporter-obs-commit: exporter-obs-workdir
cd build/obs/prometheus-ha_cluster_exporter; osc addremove
cd build/obs/prometheus-ha_cluster_exporter; osc commit -m "Update from git rev $(REVISION)"
dashboards-obs-workdir: build/obs/grafana-ha-cluster-dashboards
build/obs/grafana-ha-cluster-dashboards:
@mkdir -p $@
osc checkout $(OBS_PROJECT) grafana-ha-cluster-dashboards -o $@
rm -f $@/*.tar.gz
cp -rv packaging/obs/grafana-ha-cluster-dashboards/* $@/
# we interpolate environment variables in OBS _service file so that we control what is downloaded by the tar_scm source service
sed -i 's~%%REVISION%%~$(REVISION)~' $@/_service
sed -i 's~%%REPOSITORY%%~$(REPOSITORY)~' $@/_service
cd $@; osc service manualrun
dashboards-obs-commit: dashboards-obs-workdir
cd build/obs/grafana-ha-cluster-dashboards; osc addremove
cd build/obs/grafana-ha-cluster-dashboards; osc commit -m "Update from git rev $(REVISION)"
.PHONY: $(ARCHS) build build-all checks clean coverage dashboards-obs-commit dashboards-obs-workdir default download \
exporter-obs-changelog exporter-obs-commit exporter-obs-workdir fmt fmt-check generate install mod-tidy \
static-checks test vet-check