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