-
Notifications
You must be signed in to change notification settings - Fork 18
/
Makefile
98 lines (83 loc) · 3.18 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
# kudos:
# - https://medium.com/@exustash/three-good-practices-for-better-ci-cd-makefiles-5b93452e4cc3
# - https://le-gall.bzh/post/makefile-based-ci-chain-for-go/
# - https://makefiletutorial.com/
# - https://www.cl.cam.ac.uk/teaching/0910/UnixTools/make.pdf
#
#SHELL := /usr/bin/bash # set default shell
#.SHELLFLAGS = -c # Run commands in a -c flag
.NOTPARALLEL: ; # wait for this target to finish
.EXPORT_ALL_VARIABLES: ; # send all vars to shell
.PHONY: all # All targets are accessible for user
.DEFAULT: help # Running Make will run the help target
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
ifeq ($(BRANCH), HEAD)
BRANCH := ${CI_BUILD_REF_NAME}
endif
# help: @ List available tasks of the project
help:
@grep -E '[a-zA-Z\.\-]+:.*?@ .*$$' $(MAKEFILE_LIST)| tr -d '#' | awk 'BEGIN {FS = ":.*?@ "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
## test section
# All tests are called on "." if possible.
# If this is not possible a special loop is used
# to sum up all error codes.
# test: @ Run all defined tests
test: test-tab test-codespell test-shellcheck test-yamllint test-jsonlint test-salt
@echo "All tests Done!"
# test-tab: @ Run linting to find files containing tabspaces
test-tab:
@for file in $(shell find . -regextype egrep -regex '.*\.(sls|yml|yaml)' ! -path "**/venv/*"); do\
grep -q -P '\t' $${file} ;\
if [ "$$?" -eq 0 ]; then\
err_add=1 ;\
echo "Tab found in $${file}" ;\
grep -H -n -P '\t' $${file} ;\
else \
err_add=0 ;\
fi;\
err=$$((err_add + err)) ;\
done; exit $$err
# test-codespell: @ Run spell check
test-codespell:
codespell -H -f -s -I .codespell.ignore.words -S $(shell cat .codespell.ignore.files) -C 4 -q 6
# test-shellcheck: @ Run linting on all shell scripts
test-shellcheck:
for file in $(shell find . -name '*.sh' ! -path "**/venv/*"); do\
echo $${file} ;\
shellcheck -s bash -x $${file};\
err=$$(($$? + err)) ;\
done; exit $$err
# test-yamllint: @ Run linting on all yaml files
test-yamllint:
# yamllint -c .yamllint.yaml -s .
yamllint -c .yamllint.yaml .
# test-jsonlint: @ Run linting on all json files
test-jsonlint:
for file in $(shell find . -name '*.json' ! -path "**/venv/*"); do\
echo $${file} ;\
jq << $${file} >/dev/null;\
err=$$(($$? + err)) ;\
done; exit $$err
# test-mlc: @ Run markup link checker
test-mlc:
mkdir -p aws/.terraform # make sure ingore-path exists
mlc --throttle 1000
# test-salt: @ Run Salt Unit Tests
test-salt:
cp pillar.example example/pillar/hana.sls
cp example/salt/top.sls .
echo "==========================================="
echo " Using primary host "
echo "==========================================="
cp ci/grains_hana01 grains
cp ci/minion minion
salt-call state.show_highstate --local --file-root=./ --config-dir=. --pillar-root=example/pillar --retcode-passthrough -l debug
echo
echo "==========================================="
echo " Using secondary host "
echo "==========================================="
cp ci/grains_hana02 grains
cp ci/minion minion
salt-call state.show_highstate --local --file-root=./ --config-dir=. --pillar-root=example/pillar --retcode-passthrough -l debug
# all: @ Runs everything
all: test