blob: dbad8d837882cb1dd0a1e6371a5d0a569d000d93 [file] [log] [blame]
Michael Klementae908cb2014-12-03 01:47:54 -05001 # Since we rely on paths relative to the makefile location, abort if make isn't being run from there.
Jordan Harbandb9df3fc2014-12-17 01:30:29 -08002$(if $(findstring /,$(MAKEFILE_LIST)),$(error Please only invoke this makefile from the directory it resides in))
Michael Klementac912af2014-10-03 01:29:04 -04003 # Note: With Travis CI:
4 # - the path to urchin is passed via the command line.
Michael Klementae908cb2014-12-03 01:47:54 -05005 # - the other utilities are NOT needed, so we skip the test for their existence.
Michael Klementac912af2014-10-03 01:29:04 -04006URCHIN := urchin
7ifeq ($(findstring /,$(URCHIN)),) # urchin path was NOT passed in.
8 # Add the local npm packages' bin folder to the PATH, so that `make` can find them, when invoked directly.
Michael Klementae908cb2014-12-03 01:47:54 -05009 # Note that rather than using `$(npm bin)` the 'node_modules/.bin' path component is hard-coded, so that invocation works even from an environment
10 # where npm is (temporarily) unavailable due to having deactivated an nvm instance loaded into the calling shell in order to avoid interference with tests.
11 export PATH := $(shell printf '%s' "$$PWD/node_modules/.bin:$$PATH")
Michael Klementac912af2014-10-03 01:29:04 -040012 # The list of all supporting utilities, installed with `npm install`.
13 UTILS := $(URCHIN) replace semver
14 # Make sure that all required utilities can be located.
15 UTIL_CHECK := $(or $(shell PATH="$(PATH)" which $(UTILS) >/dev/null && echo 'ok'),$(error Did you forget to run `npm install` after cloning the repo? At least one of the required supporting utilities not found: $(UTILS)))
16endif
17 # The files that need updating when incrementing the version number.
18VERSIONED_FILES := nvm.sh install.sh README.markdown package.json
19 # Define all shells to test with. Can be overridden with `make SHELLS=... <target>`.
Jordan Harbandafba4e02014-11-15 10:56:01 -060020SHELLS := sh bash dash zsh # ksh (#574)
Michael Klementac912af2014-10-03 01:29:04 -040021 # Generate 'test-<shell>' target names from specified shells.
22 # The embedded shell names are extracted on demand inside the recipes.
23SHELL_TARGETS := $(addprefix test-,$(SHELLS))
24 # Define the default test suite(s). This can be overridden with `make TEST_SUITE=<...> <target>`.
25 # Test suites are the names of subfolders of './test'.
Michael Klement781f72c2014-10-31 09:07:21 -040026TEST_SUITE := $(shell find ./test/* -type d -prune -exec basename {} \;)
27
Koen Punt52a384a2014-03-22 18:37:41 +010028
Michael Klementac912af2014-10-03 01:29:04 -040029# Default target (by virtue of being the first non '.'-prefixed in the file).
30.PHONY: _no-target-specified
31_no-target-specified:
32 $(error Please specify the target to make - `make list` shows targets. Alternatively, use `npm test` to run the default tests; `npm run` shows all tests)
Koen Punt52a384a2014-03-22 18:37:41 +010033
Michael Klementac912af2014-10-03 01:29:04 -040034# Lists all targets defined in this makefile.
35.PHONY: list
36list:
37 @$(MAKE) -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
Koen Punt52a384a2014-03-22 18:37:41 +010038
Michael Klementac912af2014-10-03 01:29:04 -040039# Set of test-<shell> targets; each runs the specified test suites for a single shell.
40# Note that preexisting NVM_* variables are unset to avoid interfering with tests, except when running the Travis tests (where NVM_DIR must be passed in and the env. is assumed to be pristine).
41.PHONY: $(SHELL_TARGETS)
42$(SHELL_TARGETS):
43 @shell='$@'; shell=$${shell##*-}; which "$$shell" >/dev/null || { printf '\033[0;31m%s\033[0m\n' "WARNING: Cannot test with shell '$$shell': not found." >&2; exit 0; } && \
44 printf '\n\033[0;34m%s\033[0m\n' "Running tests in $$shell"; \
Michael Klementae908cb2014-12-03 01:47:54 -050045 [ -z "$$TRAVIS_BUILD_DIR" ] && for v in $$(set | awk -F'=' '$$1 ~ "^NVM_" { print $$1 }'); do unset $$v; done && unset v; \
46 for suite in $(TEST_SUITE); do $(URCHIN) -f -s $$shell test/$$suite || exit; done
Koen Punt52a384a2014-03-22 18:37:41 +010047
Michael Klementac912af2014-10-03 01:29:04 -040048# All-tests target: invokes the specified test suites for ALL shells defined in $(SHELLS).
49.PHONY: test
50test: $(SHELL_TARGETS)
Jordan Harbandd950c1a2014-03-22 13:10:18 -070051
Michael Klementac912af2014-10-03 01:29:04 -040052.PHONY: _ensure-tag
53_ensure-tag:
Koen Puntb952be62014-07-10 10:51:36 +020054ifndef TAG
Michael Klementac912af2014-10-03 01:29:04 -040055 $(error Please invoke with `make TAG=<new-version> release`, where <new-version> is either an increment specifier (patch, minor, major, prepatch, preminor, premajor, prerelease), or an explicit major.minor.patch version number)
Koen Puntb952be62014-07-10 10:51:36 +020056endif
57
Michael Klementac912af2014-10-03 01:29:04 -040058# Ensures that the git workspace is clean.
59.PHONY: _ensure-clean
60_ensure-clean:
61 @[ -z "$$(git status --porcelain --untracked-files=no || echo err)" ] || { echo "Workspace is not clean; please commit changes first." >&2; exit 2; }
Jordan Harbanda3de7f32014-07-17 00:25:14 -070062
Michael Klementac912af2014-10-03 01:29:04 -040063# Makes a release; invoke with `make TAG=<versionOrIncrementSpec> release`.
64.PHONY: release
65release: _ensure-tag _ensure-clean
66 @old_ver=`git describe --abbrev=0 --tags --match 'v[0-9]*.[0-9]*.[0-9]*'` || { echo "Failed to determine current version." >&2; exit 1; }; old_ver=$${old_ver#v}; \
67 new_ver=`echo "$(TAG)" | sed 's/^v//'`; new_ver=$${new_ver:-patch}; \
68 if printf "$$new_ver" | grep -q '^[0-9]'; then \
69 semver "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be major.minor.patch' >&2; exit 2; }; \
70 semver -r "> $$old_ver" "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be HIGHER than current one.' >&2; exit 2; } \
71 else \
72 new_ver=`semver -i "$$new_ver" "$$old_ver"` || { echo 'Invalid version-increment specifier: $(TAG)' >&2; exit 2; } \
73 fi; \
74 printf "=== Bumping version **$$old_ver** to **$$new_ver** before committing and tagging:\n=== TYPE 'proceed' TO PROCEED, anything else to abort: " && read response && [ "$$response" = 'proceed' ] || { echo 'Aborted.' >&2; exit 2; }; \
75 replace "$$old_ver" "$$new_ver" -- $(VERSIONED_FILES) && \
76 git commit -m "v$$new_ver" $(VERSIONED_FILES) && \
77 git tag -a -m "v$$new_ver" "v$$new_ver"