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