forked from SUSE/ha-sap-terraform-deployments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
128 lines (111 loc) · 4.21 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
# 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/env 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-lint test-terraform-format test-terraform-validation
@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 \
--ignore-path \
**/.terraform \
--ignore-links \
./terraform.tvars.example \
../pillar/*/* \
https://github.com/SUSE/ha-sap-terraform-deployments/actions \
https://github.com/SUSE/ha-sap-terraform-deployments/workflows/CI%20tests/badge.svg \
https://www.sap.com/dmc/exp/2014-09-02-hana-hardware/enEN/#/solutions*
# test-salt-lint: @ Run linting on all salt files
test-salt-lint:
for file in $(shell find salt/ -name '*.sls'); do\
echo $${file} ;\
salt-lint $${file};\
err=$$(($$? + err)) ;\
done; exit $$err
# test-terraform-format: @ Run format check on all terraform files
test-terraform-format:
for cloud_provider in aws azure gcp libvirt openstack ; do\
cd $${cloud_provider} >/dev/null ;\
echo $${cloud_provider} ;\
terraform fmt -check=true -diff=true -recursive ;\
err=$$(($$? + err)) ;\
cd - >/dev/null ;\
done; exit $$err
# test-terraform-validation: @ Run validation check on all terraform files
test-terraform-validation:
for cloud_provider in aws azure gcp libvirt openstack ; do\
cd $${cloud_provider} >/dev/null ;\
echo $${cloud_provider} ;\
terraform init 2>&1 >/dev/null;\
terraform validate ;\
err=$$(($$? + err)) ;\
cd - >/dev/null ;\
done; exit $$err
# TODO: evaluate if this can be run without actual credentials
# test-terraform-plan: @ Run terraform in "plan mode" on all terraform cloud providers (disabled by default)
test-terraform-plan:
for cloud_provider in aws azure gcp libvirt openstack ; do\
cd $${cloud_provider} >/dev/null ;\
echo $${cloud_provider} ;\
terraform init 2>&1 >/dev/null;\
terraform plan -var-file=./terraform.tfvars.example -var-file=../.ci/terraform.tfvars.ci ;\
err=$$(($$? + err)) ;\
cd - >/dev/null ;\
done; exit $$err
# all: @ Runs everything
all: test