blob: d0e6fa4ee10b712d7947e4919d1b864893ae8f86 [file] [log] [blame]
Mykyta Karpindb737652018-02-05 11:11:31 +02001DESTDIR=/
2SALTENVDIR=/usr/share/salt-formulas/env
3RECLASSDIR=/usr/share/salt-formulas/reclass
4FORMULANAME=$(shell grep name: metadata.yml|head -1|cut -d : -f 2|grep -Eo '[a-z0-9\-\_]*')
5VERSION=$(shell grep version: metadata.yml|head -1|cut -d : -f 2|grep -Eo '[a-z0-9\.\-\_]*')
6VERSION_MAJOR := $(shell echo $(VERSION)|cut -d . -f 1-2)
7VERSION_MINOR := $(shell echo $(VERSION)|cut -d . -f 3)
8
9NEW_MAJOR_VERSION ?= $(shell date +%Y.%m|sed 's,\.0,\.,g')
10NEW_MINOR_VERSION ?= $(shell /bin/bash -c 'echo $$[ $(VERSION_MINOR) + 1 ]')
11
12MAKE_PID := $(shell echo $$PPID)
13JOB_FLAG := $(filter -j%, $(subst -j ,-j,$(shell ps T | grep "^\s*$(MAKE_PID).*$(MAKE)")))
14
15ifneq ($(subst -j,,$(JOB_FLAG)),)
16JOBS := $(subst -j,,$(JOB_FLAG))
17else
18JOBS := 1
19endif
20
21KITCHEN_LOCAL_YAML?=.kitchen.yml
22KITCHEN_OPTS?="--concurrency=$(JOBS)"
23KITCHEN_OPTS_CREATE?=""
24KITCHEN_OPTS_CONVERGE?=""
25KITCHEN_OPTS_VERIFY?=""
26KITCHEN_OPTS_TEST?=""
27
28all:
29 @echo "make install - Install into DESTDIR"
30 @echo "make lint - Run lint tests"
31 @echo "make test - Run tests"
32 @echo "make kitchen - Run Kitchen CI tests (create, converge, verify)"
33 @echo "make clean - Cleanup after tests run"
34 @echo "make release-major - Generate new major release"
35 @echo "make release-minor - Generate new minor release"
36 @echo "make changelog - Show changes since last release"
37 @echo "make test-model-validate - Run salt jsonschema validation"
38
39install:
40 # Formula
41 [ -d $(DESTDIR)/$(SALTENVDIR) ] || mkdir -p $(DESTDIR)/$(SALTENVDIR)
42 cp -a $(FORMULANAME) $(DESTDIR)/$(SALTENVDIR)/
43 [ ! -d _modules ] || cp -a _modules $(DESTDIR)/$(SALTENVDIR)/
44 [ ! -d _states ] || cp -a _states $(DESTDIR)/$(SALTENVDIR)/ || true
45 [ ! -d _grains ] || cp -a _grains $(DESTDIR)/$(SALTENVDIR)/ || true
46 # Metadata
47 [ -d $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME) ] || mkdir -p $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME)
48 cp -a metadata/service/* $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME)
49
50lint:
51 [ ! -d tests ] || (cd tests; ./run_tests.sh lint)
52
53test:
54 [ ! -d tests ] || (cd tests; ./run_tests.sh)
55
56test-model-validate:
57 # TODO make it actually fail
58 [ ! -d $(FORMULANAME)/schemas/ ] || (cd tests; ./run_tests.sh model-validate)
59
60release-major: check-changes
61 @echo "Current version is $(VERSION), new version is $(NEW_MAJOR_VERSION)"
62 @[ $(VERSION_MAJOR) != $(NEW_MAJOR_VERSION) ] || (echo "Major version $(NEW_MAJOR_VERSION) already released, nothing to do. Do you want release-minor?" && exit 1)
63 echo "$(NEW_MAJOR_VERSION)" > VERSION
64 sed -i 's,version: .*,version: "$(NEW_MAJOR_VERSION)",g' metadata.yml
65 [ ! -f debian/changelog ] || dch -v $(NEW_MAJOR_VERSION) -m --force-distribution -D `dpkg-parsechangelog -S Distribution` "New version"
66 make genchangelog-$(NEW_MAJOR_VERSION)
67 (git add -u; git commit -m "Version $(NEW_MAJOR_VERSION)")
68 git tag -s -m $(NEW_MAJOR_VERSION) $(NEW_MAJOR_VERSION)
69
70release-minor: check-changes
71 @echo "Current version is $(VERSION), new version is $(VERSION_MAJOR).$(NEW_MINOR_VERSION)"
72 echo "$(VERSION_MAJOR).$(NEW_MINOR_VERSION)" > VERSION
73 sed -i 's,version: .*,version: "$(VERSION_MAJOR).$(NEW_MINOR_VERSION)",g' metadata.yml
74 [ ! -f debian/changelog ] || dch -v $(VERSION_MAJOR).$(NEW_MINOR_VERSION) -m --force-distribution -D `dpkg-parsechangelog -S Distribution` "New version"
75 make genchangelog-$(VERSION_MAJOR).$(NEW_MINOR_VERSION)
76 (git add -u; git commit -m "Version $(VERSION_MAJOR).$(NEW_MINOR_VERSION)")
77 git tag -s -m $(VERSION_MAJOR) $(VERSION_MAJOR).$(NEW_MINOR_VERSION)
78
79check-changes:
80 @git log --pretty=oneline --decorate $(VERSION)..HEAD | grep -Eqc '.*' || (echo "No new changes since version $(VERSION)"; exit 1)
81
82changelog:
83 git log --pretty=short --invert-grep --grep="Merge pull request" --decorate $(VERSION)..HEAD
84
85genchangelog: genchangelog-$(VERSION_MAJOR).$(NEW_MINOR_VERSION)
86
87genchangelog-%:
88 $(eval NEW_VERSION := $(patsubst genchangelog-%,%,$@))
89 (echo "=========\nChangelog\n=========\n"; \
90 (echo $(NEW_VERSION);git tag) | sort -r | grep -E '^[0-9\.]+' | while read i; do \
91 cur=$$i; \
92 test $$i = $(NEW_VERSION) && i=HEAD; \
93 prev=`(echo $(NEW_VERSION);git tag)|sort|grep -E '^[0-9\.]+'|grep -B1 "$$cur\$$"|head -1`; \
94 echo "Version $$cur\n=============================\n"; \
95 git log --pretty=short --invert-grep --grep="Merge pull request" --decorate $$prev..$$i; \
96 echo; \
97 done) > CHANGELOG.rst
98
99kitchen-check:
100 @[ -e $(KITCHEN_LOCAL_YAML) ] || (echo "Kitchen tests not available, there's no $(KITCHEN_LOCAL_YAML)." && exit 1)
101
102kitchen: kitchen-check kitchen-create kitchen-converge kitchen-verify kitchen-list
103
104kitchen-create: kitchen-check
105 kitchen create ${KITCHEN_OPTS} ${KITCHEN_OPTS_CREATE}
106 [ "$(shell echo $(KITCHEN_LOCAL_YAML)|grep -Eo docker)" = "docker" ] || sleep 120
107
108kitchen-converge: kitchen-check
109 kitchen converge ${KITCHEN_OPTS} ${KITCHEN_OPTS_CONVERGE} &&\
110 kitchen converge ${KITCHEN_OPTS} ${KITCHEN_OPTS_CONVERGE}
111
112kitchen-verify: kitchen-check
113 [ ! -d tests/integration ] || kitchen verify -t tests/integration ${KITCHEN_OPTS} ${KITCHEN_OPTS_VERIFY}
114 [ -d tests/integration ] || kitchen verify ${KITCHEN_OPTS} ${KITCHEN_OPTS_VERIFY}
115
116kitchen-test: kitchen-check
117 [ ! -d tests/integration ] || kitchen test -t tests/integration ${KITCHEN_OPTS} ${KITCHEN_OPTS_TEST}
118 [ -d tests/integration ] || kitchen test ${KITCHEN_OPTS} ${KITCHEN_OPTS_TEST}
119
120kitchen-list: kitchen-check
121 kitchen list
122
123clean:
124 [ ! -x "$(shell which kitchen)" ] || kitchen destroy
125 [ ! -d .kitchen ] || rm -rf .kitchen
126 [ ! -d tests/build ] || rm -rf tests/build
127 [ ! -d build ] || rm -rf build