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