blob: 8eb30e8445ed37d65ba992189ccbc044a7c8d4c4 [file] [log] [blame]
Filip Pytloun2754da82016-04-14 14:11:52 +02001DESTDIR=/
2SALTENVDIR=/usr/share/salt-formulas/env
3RECLASSDIR=/usr/share/salt-formulas/reclass
Filip Pytloun954dbd62017-02-02 13:02:03 +01004FORMULANAME=$(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?=""
Filip Pytloun2754da82016-04-14 14:11:52 +020027
28all:
29 @echo "make install - Install into DESTDIR"
30 @echo "make test - Run tests"
Filip Pytloun954dbd62017-02-02 13:02:03 +010031 @echo "make kitchen - Run Kitchen CI tests (create, converge, verify)"
Filip Pytloun2754da82016-04-14 14:11:52 +020032 @echo "make clean - Cleanup after tests run"
Filip Pytloun954dbd62017-02-02 13:02:03 +010033 @echo "make release-major - Generate new major release"
34 @echo "make release-minor - Generate new minor release"
35 @echo "make changelog - Show changes since last release"
Filip Pytloun2754da82016-04-14 14:11:52 +020036
37install:
38 # Formula
39 [ -d $(DESTDIR)/$(SALTENVDIR) ] || mkdir -p $(DESTDIR)/$(SALTENVDIR)
40 cp -a $(FORMULANAME) $(DESTDIR)/$(SALTENVDIR)/
41 [ ! -d _modules ] || cp -a _modules $(DESTDIR)/$(SALTENVDIR)/
42 [ ! -d _states ] || cp -a _states $(DESTDIR)/$(SALTENVDIR)/ || true
Ales Komarekef0eea32018-02-14 15:47:13 +010043 [ ! -d _engines ] || cp -a _engines $(DESTDIR)/$(SALTENVDIR)/ || true
Filip Pytloun954dbd62017-02-02 13:02:03 +010044 [ ! -d _grains ] || cp -a _grains $(DESTDIR)/$(SALTENVDIR)/ || true
Filip Pytloun2754da82016-04-14 14:11:52 +020045 # Metadata
46 [ -d $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME) ] || mkdir -p $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME)
47 cp -a metadata/service/* $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME)
48
49test:
50 [ ! -d tests ] || (cd tests; ./run_tests.sh)
51
Filip Pytloun954dbd62017-02-02 13:02:03 +010052release-major: check-changes
53 @echo "Current version is $(VERSION), new version is $(NEW_MAJOR_VERSION)"
54 @[ $(VERSION_MAJOR) != $(NEW_MAJOR_VERSION) ] || (echo "Major version $(NEW_MAJOR_VERSION) already released, nothing to do. Do you want release-minor?" && exit 1)
55 echo "$(NEW_MAJOR_VERSION)" > VERSION
56 sed -i 's,version: .*,version: "$(NEW_MAJOR_VERSION)",g' metadata.yml
57 [ ! -f debian/changelog ] || dch -v $(NEW_MAJOR_VERSION) -m --force-distribution -D `dpkg-parsechangelog -S Distribution` "New version"
58 make genchangelog-$(NEW_MAJOR_VERSION)
59 (git add -u; git commit -m "Version $(NEW_MAJOR_VERSION)")
60 git tag -s -m $(NEW_MAJOR_VERSION) $(NEW_MAJOR_VERSION)
61
62release-minor: check-changes
63 @echo "Current version is $(VERSION), new version is $(VERSION_MAJOR).$(NEW_MINOR_VERSION)"
64 echo "$(VERSION_MAJOR).$(NEW_MINOR_VERSION)" > VERSION
65 sed -i 's,version: .*,version: "$(VERSION_MAJOR).$(NEW_MINOR_VERSION)",g' metadata.yml
66 [ ! -f debian/changelog ] || dch -v $(VERSION_MAJOR).$(NEW_MINOR_VERSION) -m --force-distribution -D `dpkg-parsechangelog -S Distribution` "New version"
67 make genchangelog-$(VERSION_MAJOR).$(NEW_MINOR_VERSION)
68 (git add -u; git commit -m "Version $(VERSION_MAJOR).$(NEW_MINOR_VERSION)")
69 git tag -s -m $(NEW_MAJOR_VERSION) $(VERSION_MAJOR).$(NEW_MINOR_VERSION)
70
71check-changes:
72 @git log --pretty=oneline --decorate $(VERSION)..HEAD | grep -Eqc '.*' || (echo "No new changes since version $(VERSION)"; exit 1)
73
74changelog:
75 git log --pretty=short --invert-grep --grep="Merge pull request" --decorate $(VERSION)..HEAD
76
77genchangelog: genchangelog-$(VERSION_MAJOR).$(NEW_MINOR_VERSION)
78
79genchangelog-%:
80 $(eval NEW_VERSION := $(patsubst genchangelog-%,%,$@))
81 (echo "=========\nChangelog\n=========\n"; \
82 (echo $(NEW_VERSION);git tag) | sort -r | grep -E '^[0-9\.]+' | while read i; do \
83 cur=$$i; \
84 test $$i = $(NEW_VERSION) && i=HEAD; \
85 prev=`(echo $(NEW_VERSION);git tag)|sort|grep -E '^[0-9\.]+'|grep -B1 "$$cur\$$"|head -1`; \
86 echo "Version $$cur\n=============================\n"; \
87 git log --pretty=short --invert-grep --grep="Merge pull request" --decorate $$prev..$$i; \
88 echo; \
89 done) > CHANGELOG.rst
90
91kitchen-check:
92 @[ -e $(KITCHEN_LOCAL_YAML) ] || (echo "Kitchen tests not available, there's no $(KITCHEN_LOCAL_YAML)." && exit 1)
93
94kitchen: kitchen-check kitchen-create kitchen-converge kitchen-verify kitchen-list
95
96kitchen-create: kitchen-check
97 kitchen create ${KITCHEN_OPTS} ${KITCHEN_OPTS_CREATE}
98 [ "$(shell echo $(KITCHEN_LOCAL_YAML)|grep -Eo docker)" = "docker" ] || sleep 120
99
100kitchen-converge: kitchen-check
101 kitchen converge ${KITCHEN_OPTS} ${KITCHEN_OPTS_CONVERGE} &&\
102 kitchen converge ${KITCHEN_OPTS} ${KITCHEN_OPTS_CONVERGE}
103
104kitchen-verify: kitchen-check
105 [ ! -d tests/integration ] || kitchen verify -t tests/integration ${KITCHEN_OPTS} ${KITCHEN_OPTS_VERIFY}
106 [ -d tests/integration ] || kitchen verify ${KITCHEN_OPTS} ${KITCHEN_OPTS_VERIFY}
107
108kitchen-test: kitchen-check
109 [ ! -d tests/integration ] || kitchen test -t tests/integration ${KITCHEN_OPTS} ${KITCHEN_OPTS_TEST}
110 [ -d tests/integration ] || kitchen test ${KITCHEN_OPTS} ${KITCHEN_OPTS_TEST}
111
112kitchen-list: kitchen-check
113 kitchen list
114
Filip Pytloun2754da82016-04-14 14:11:52 +0200115clean:
Filip Pytloun954dbd62017-02-02 13:02:03 +0100116 [ ! -x "$(shell which kitchen)" ] || kitchen destroy
117 [ ! -d .kitchen ] || rm -rf .kitchen
Filip Pytloun2754da82016-04-14 14:11:52 +0200118 [ ! -d tests/build ] || rm -rf tests/build
119 [ ! -d build ] || rm -rf build