Michael Klement | ae908cb | 2014-12-03 01:47:54 -0500 | [diff] [blame] | 1 | # Since we rely on paths relative to the makefile location, abort if make isn't being run from there. |
Jordan Harband | b9df3fc | 2014-12-17 01:30:29 -0800 | [diff] [blame^] | 2 | $(if $(findstring /,$(MAKEFILE_LIST)),$(error Please only invoke this makefile from the directory it resides in)) |
Michael Klement | ac912af | 2014-10-03 01:29:04 -0400 | [diff] [blame] | 3 | # Note: With Travis CI: |
| 4 | # - the path to urchin is passed via the command line. |
Michael Klement | ae908cb | 2014-12-03 01:47:54 -0500 | [diff] [blame] | 5 | # - the other utilities are NOT needed, so we skip the test for their existence. |
Michael Klement | ac912af | 2014-10-03 01:29:04 -0400 | [diff] [blame] | 6 | URCHIN := urchin |
| 7 | ifeq ($(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 Klement | ae908cb | 2014-12-03 01:47:54 -0500 | [diff] [blame] | 9 | # 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 Klement | ac912af | 2014-10-03 01:29:04 -0400 | [diff] [blame] | 12 | # 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))) |
| 16 | endif |
| 17 | # The files that need updating when incrementing the version number. |
| 18 | VERSIONED_FILES := nvm.sh install.sh README.markdown package.json |
| 19 | # Define all shells to test with. Can be overridden with `make SHELLS=... <target>`. |
Jordan Harband | afba4e0 | 2014-11-15 10:56:01 -0600 | [diff] [blame] | 20 | SHELLS := sh bash dash zsh # ksh (#574) |
Michael Klement | ac912af | 2014-10-03 01:29:04 -0400 | [diff] [blame] | 21 | # Generate 'test-<shell>' target names from specified shells. |
| 22 | # The embedded shell names are extracted on demand inside the recipes. |
| 23 | SHELL_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 Klement | 781f72c | 2014-10-31 09:07:21 -0400 | [diff] [blame] | 26 | TEST_SUITE := $(shell find ./test/* -type d -prune -exec basename {} \;) |
| 27 | |
Koen Punt | 52a384a | 2014-03-22 18:37:41 +0100 | [diff] [blame] | 28 | |
Michael Klement | ac912af | 2014-10-03 01:29:04 -0400 | [diff] [blame] | 29 | # 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 Punt | 52a384a | 2014-03-22 18:37:41 +0100 | [diff] [blame] | 33 | |
Michael Klement | ac912af | 2014-10-03 01:29:04 -0400 | [diff] [blame] | 34 | # Lists all targets defined in this makefile. |
| 35 | .PHONY: list |
| 36 | list: |
| 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 Punt | 52a384a | 2014-03-22 18:37:41 +0100 | [diff] [blame] | 38 | |
Michael Klement | ac912af | 2014-10-03 01:29:04 -0400 | [diff] [blame] | 39 | # 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 Klement | ae908cb | 2014-12-03 01:47:54 -0500 | [diff] [blame] | 45 | [ -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 Punt | 52a384a | 2014-03-22 18:37:41 +0100 | [diff] [blame] | 47 | |
Michael Klement | ac912af | 2014-10-03 01:29:04 -0400 | [diff] [blame] | 48 | # All-tests target: invokes the specified test suites for ALL shells defined in $(SHELLS). |
| 49 | .PHONY: test |
| 50 | test: $(SHELL_TARGETS) |
Jordan Harband | d950c1a | 2014-03-22 13:10:18 -0700 | [diff] [blame] | 51 | |
Michael Klement | ac912af | 2014-10-03 01:29:04 -0400 | [diff] [blame] | 52 | .PHONY: _ensure-tag |
| 53 | _ensure-tag: |
Koen Punt | b952be6 | 2014-07-10 10:51:36 +0200 | [diff] [blame] | 54 | ifndef TAG |
Michael Klement | ac912af | 2014-10-03 01:29:04 -0400 | [diff] [blame] | 55 | $(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 Punt | b952be6 | 2014-07-10 10:51:36 +0200 | [diff] [blame] | 56 | endif |
| 57 | |
Michael Klement | ac912af | 2014-10-03 01:29:04 -0400 | [diff] [blame] | 58 | # 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 Harband | a3de7f3 | 2014-07-17 00:25:14 -0700 | [diff] [blame] | 62 | |
Michael Klement | ac912af | 2014-10-03 01:29:04 -0400 | [diff] [blame] | 63 | # Makes a release; invoke with `make TAG=<versionOrIncrementSpec> release`. |
| 64 | .PHONY: release |
| 65 | release: _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" |