forked from fluxcd-community/helm-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
151 lines (127 loc) · 5.46 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
# ====================================================================================
# Setup Project
FLUX2_VERSION ?= v0.33.0
# set the shell to bash always
SHELL := /bin/bash
# ====================================================================================
# Setup directories and paths
# a working directory that holds all temporary or working items generated
# during the build. The items will be discarded on a clean build and they
# will never be cached.
ifeq ($(origin WORK_DIR), undefined)
WORK_DIR := $(ROOT_DIR).work
endif
# ====================================================================================
# Colors
BLACK := $(shell printf "\033[30m")
BLACK_BOLD := $(shell printf "\033[30;1m")
RED := $(shell printf "\033[31m")
RED_BOLD := $(shell printf "\033[31;1m")
GREEN := $(shell printf "\033[32m")
GREEN_BOLD := $(shell printf "\033[32;1m")
YELLOW := $(shell printf "\033[33m")
YELLOW_BOLD := $(shell printf "\033[33;1m")
BLUE := $(shell printf "\033[34m")
BLUE_BOLD := $(shell printf "\033[34;1m")
MAGENTA := $(shell printf "\033[35m")
MAGENTA_BOLD := $(shell printf "\033[35;1m")
CYAN := $(shell printf "\033[36m")
CYAN_BOLD := $(shell printf "\033[36;1m")
WHITE := $(shell printf "\033[37m")
WHITE_BOLD := $(shell printf "\033[37;1m")
CNone := $(shell printf "\033[0m")
# ====================================================================================
# Logger
TIME_LONG = `date +%Y-%m-%d' '%H:%M:%S`
TIME_SHORT = `date +%H:%M:%S`
TIME = $(TIME_SHORT)
INFO = echo ${TIME} ${BLUE}[ .. ]${CNone}
WARN = echo ${TIME} ${YELLOW}[WARN]${CNone}
ERR = echo ${TIME} ${RED}[FAIL]${CNone}
OK = echo ${TIME} ${GREEN}[ OK ]${CNone}
FAIL = (echo ${TIME} ${RED}[FAIL]${CNone} && false)
# ====================================================================================
# Commands
all: fetch generate update.appversion helmdocs unittests check-diff
fetch:
@$(INFO) Fetch Flux2 GitRepo
@mkdir -p ${WORK_DIR}
@if [ ! -d "${WORK_DIR}/flux2" ]; then \
cd ${WORK_DIR} && git clone "https://github.com/fluxcd/flux2.git"; \
fi
@cd ${WORK_DIR}/flux2 && git fetch origin && git checkout $(FLUX2_VERSION)
@$(OK) Fetch Flux2 GitRepo
helmdocs:
helm-docs --chart-search-root=charts --template-files=../_readme_templates.gotmpl
update.chartversion:
@if [ "$(chartyamlpath)" = "" ]; then \
echo "Error: Please specify the path to the Chart.ymal: eg. chartyamlpath=./charts/flux2/Chart.yaml"; \
$(FAIL) \
fi
@RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)' ; \
base=$$(git show main:$(chartyamlpath) | grep "version:" | cut -c10-) ; \
MAJOR=`echo $${base} | sed -e "s#$${RE}#\1#"` ; \
MINOR=`echo $${base} | sed -e "s#$${RE}#\2#"` ; \
PATCH=`echo $${base} | sed -e "s#$${RE}#\3#"` ; \
$(INFO) "Old Chart version: $${MAJOR}.$${MINOR}.$${PATCH} in $(chartyamlpath)" ; \
case '$(semvertype)' in \
major) \
let MAJOR+=1 \
let MINOR=0 \
let PATCH=0 \
;; \
minor) \
let MINOR+=1 \
let PATCH=0 \
;; \
patch) \
let PATCH+=1 \
;; \
*) \
echo "Error: Please specify one of the following bump types: semvertype=(major|minor|patch)"; \
$(FAIL) ; exit 1 ;\
esac; \
sed -s -i "s/^\(version:\).*/\1 $${MAJOR}.$${MINOR}.$${PATCH}/" $(chartyamlpath) || $(FAIL); \
$(OK) New Chart version: $${MAJOR}.$${MINOR}.$${PATCH};
@make update.appversion
update.appversion:
@for file in $$(ls -1 ./charts/ | tr '\n' ' '); do \
chartversion=$$(cat ./charts/$${file}/Chart.yaml | grep -E '^version: ' | cut -c10-) ; \
chartname=$$(cat ./charts/$${file}/Chart.yaml | grep -E '^name: ' | cut -c7-) ; \
$(INFO) Update chartname and chartversion string in test snapshots for $${file}.; \
sed -s -i "s/^\([[:space:]]\+helm\.sh\/chart:\).*/\1 $${chartname}-$${chartversion}/" ./charts/$${file}/tests/__snapshot__/*.yaml.snap ; \
sed -s -i "s/^\([[:space:]]\+app\.kubernetes\.io\/version:\).*/\1 $(subst v,,${FLUX2_VERSION})/" ./charts/$${file}/tests/__snapshot__/*.yaml.snap ; \
$(INFO) Update appVersion in ./charts/$${file}/Chart.yaml ;\
sed -s -i "s/^\(appVersion:\).*/\1 $(subst v,,${FLUX2_VERSION})/" ./charts/$${file}/Chart.yaml ; \
$(OK) "Version strings updated" ; \
done
generate: fetch
@$(INFO) Generating CRDs
@./hack/generate.sh
@$(OK) Generating CRDs
unittests:
@helm unittest --helm3 --file tests/*.yaml --file 'tests/**/*.yaml' charts/flux2-multi-tenancy/
@helm unittest --helm3 --file tests/*.yaml --file 'tests/**/*.yaml' charts/flux2/
@helm unittest --helm3 --file tests/*.yaml --file 'tests/**/*.yaml' charts/flux2-sync/
@helm unittest --helm3 --file tests/*.yaml --file 'tests/**/*.yaml' charts/flux2-notification/
check-diff:
@$(INFO) checking that branch is clean
@if git status --porcelain | grep . ; \
then $(FAIL); \
else $(OK) branch is clean; \
fi
reviewable: update.appversion helmdocs unittests check-diff
.PHONY: all fetch helmdocs update.chartversion update.appversion generate unittests check-diff reviewable
define FLUXCHART_MAKE_HELP
Targets:
generate Generate a new chart files from flux version specified at start of Makefile.
helmdocs Update README.md files in chart directories.
unittests Run helm unittest against the charts.
update.appversion Update version strings in testfiles and Chart.yaml.
update.chartversion Bump Semver chart version.
reviewable Run to see if everything fits.
endef
export FLUXCHART_MAKE_HELP
.PHONY: help
help:
@echo "$$FLUXCHART_MAKE_HELP"