-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
140 lines (110 loc) · 3.53 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
app := krawler
version := 0.1.0
oci_image := quay.io/maxgio92/$(app)
bins := go golangci-lint gofumpt aws
DISTROS ?= amazonlinux amazonlinux2 amazonlinux2022 amazonlinux2023 archlinux centos debian fedora opensuse oracle ubuntu
RESULTS_DIR := e2e/results
BUCKET_NAME := krawler-kernel-releases
define declare_binpaths
$(1) = $(shell command -v 2>/dev/null $(1))
endef
define gen_run_targets
.PHONY: run/$(1)
run/$(1): clean build
@rm -rf $(RESULTS_DIR)/$(1) 2>/dev/null || true
@mkdir -p $(RESULTS_DIR)/$(1)
@echo -n "$(1) with default configuration: "
@./$(app) list $(1) \
-o json \
> $(RESULTS_DIR)/$(1)/index.json 2> $(RESULTS_DIR)/$(1)/krawler.log
@echo "$$$$(jq length $(RESULTS_DIR)/$(1)/index.json) releases found."
endef
$(foreach bin,$(bins),\
$(eval $(call declare_binpaths,$(bin)))\
)
define gen_e2e_targets
.PHONY: e2e/$(1)
e2e/$(1): run/$(1)
@echo -n "$(1) with custom configuration (full): "
@./$(app) list $(1) \
-c testdata/$(1).yaml \
-o json \
> $(RESULTS_DIR)/$(1)/index_custom.json 2> $(RESULTS_DIR)/$(1)/krawler_custom.log
@echo "$$$$(jq length $(RESULTS_DIR)/$(1)/index_custom.json) releases found."
@echo -n "$(1) with custom configuration (no repositories): "
@./$(app) list $(1) \
-c testdata/$(1)-norepos.yaml \
-o json \
> $(RESULTS_DIR)/$(1)/index_custom_norepos.json 2> $(RESULTS_DIR)/$(1)/krawler_custom_norepos.log
@echo "$$$$(jq length $(RESULTS_DIR)/$(1)/index_custom_norepos.json) releases found."
@{ DEFAULT=$$$$(jq length $(RESULTS_DIR)/$(1)/index.json) \
CUSTOM=$$$$(jq length $(RESULTS_DIR)/$(1)/index_custom.json) \
CUSTOM_NOREPOS=$$$$(jq length $(RESULTS_DIR)/$(1)/index_custom_norepos.json); \
[[ $$$$DEFAULT == $$$$CUSTOM ]] && \
[[ $$$$CUSTOM == $$$$CUSTOM_NOREPOS ]] && \
echo "$(1) OK"; \
} \
|| { echo "$(1) KO"; exit 1; }
endef
define gen_publish_targets
.PHONY: publish/$(1)
publish/$(1): run/$(1)
$(aws) s3 sync $(RESULTS_DIR)/$(1)/ s3://$(BUCKET_NAME)/$(1)/
endef
$(foreach distro,$(DISTROS),\
$(eval $(call gen_run_targets,$(distro)))\
$(eval $(call gen_e2e_targets,$(distro)))\
$(eval $(call gen_publish_targets,$(distro)))\
)
.PHONY: build
build:
@$(go) build .
.PHONY: test
test:
@go test -v -cover -gcflags=-l ./...
.PHONY: lint
lint: golangci-lint
@$(golangci-lint) run ./...
.PHONY: golangci-lint
golangci-lint:
@$(go) install github.com/golangci/golangci-lint/cmd/[email protected]
.PHONY: gofumpt
gofumpt:
@$(go) install mvdan.cc/[email protected]
.PHONY: oci/build
oci/build:
@docker build . -t $(oci_image):$(version) -f Dockerfile
.PHONY: oci/push
oci/push: oci/build
@docker push $(oci_image):$(version)
.PHONY: clean
clean:
@rm -f $(app)
.PHONY: help
help: list
.PHONY: list
list:
@LC_ALL=C $(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'
.PHONY: run
run: clean build $(patsubst %,run/%,$(DISTROS))
.PHONY: e2e
e2e: clean build $(patsubst %,e2e/%,$(DISTROS))
.PHONY: publish
publish: $(patsubst %,publish/%,$(DISTROS))
PACKAGE_NAME := github.com/maxgio92/$(app)
GOLANG_CROSS_VERSION ?= v1.19.4
.PHONY: release
release:
@if [ ! -f ".release-env" ]; then \
echo "\033[91m.release-env is required for release\033[0m";\
exit 1;\
fi
docker run \
--rm \
-e CGO_ENABLED=1 \
--env-file .release-env \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --rm-dist