Merge pull request #541 from mklement0/fix_make_file
Makefile enhanced to error out with instructions if invoked without a target.master
commit
fc17aaafb1
|
@ -9,6 +9,7 @@ test/bak
|
||||||
.urchin_stdout
|
.urchin_stdout
|
||||||
|
|
||||||
node_modules/
|
node_modules/
|
||||||
|
npm-debug.log
|
||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
current
|
current
|
||||||
|
|
|
@ -7,7 +7,7 @@ before_script:
|
||||||
- '[ -z "$WITHOUT_CURL" ] || wget -O /tmp/urchin https://raw.githubusercontent.com/scraperwiki/urchin/master/urchin'
|
- '[ -z "$WITHOUT_CURL" ] || wget -O /tmp/urchin https://raw.githubusercontent.com/scraperwiki/urchin/master/urchin'
|
||||||
- chmod +x /tmp/urchin
|
- chmod +x /tmp/urchin
|
||||||
script:
|
script:
|
||||||
- NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin $SHELL
|
- NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin test-$SHELL
|
||||||
env:
|
env:
|
||||||
- SHELL=sh TEST_SUITE=install_script
|
- SHELL=sh TEST_SUITE=install_script
|
||||||
- SHELL=dash TEST_SUITE=install_script
|
- SHELL=dash TEST_SUITE=install_script
|
||||||
|
|
80
Makefile
80
Makefile
|
@ -1,26 +1,72 @@
|
||||||
URCHIN=`which urchin`
|
# Note: With Travis CI:
|
||||||
SHELLS=sh bash dash ksh zsh
|
# - the path to urchin is passed via the command line.
|
||||||
TEST_SUITE=fast
|
# - the other utilties are NOT needed, so we skip the test for their existence.
|
||||||
|
URCHIN := urchin
|
||||||
|
ifeq ($(findstring /,$(URCHIN)),) # urchin path was NOT passed in.
|
||||||
|
# Add the local npm packages' bin folder to the PATH, so that `make` can find them, when invoked directly.
|
||||||
|
export PATH := $(shell printf '%s' "$$(npm bin):$$PATH")
|
||||||
|
# The list of all supporting utilities, installed with `npm install`.
|
||||||
|
UTILS := $(URCHIN) replace semver
|
||||||
|
# Make sure that all required utilities can be located.
|
||||||
|
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)))
|
||||||
|
endif
|
||||||
|
# The files that need updating when incrementing the version number.
|
||||||
|
VERSIONED_FILES := nvm.sh install.sh README.markdown package.json
|
||||||
|
# Define all shells to test with. Can be overridden with `make SHELLS=... <target>`.
|
||||||
|
SHELLS := sh bash dash ksh zsh
|
||||||
|
# Generate 'test-<shell>' target names from specified shells.
|
||||||
|
# The embedded shell names are extracted on demand inside the recipes.
|
||||||
|
SHELL_TARGETS := $(addprefix test-,$(SHELLS))
|
||||||
|
# Define the default test suite(s). This can be overridden with `make TEST_SUITE=<...> <target>`.
|
||||||
|
# Test suites are the names of subfolders of './test'.
|
||||||
|
TEST_SUITE := $(shell find ./test -type d -mindepth 1 -maxdepth 1 -exec basename {} +)
|
||||||
|
|
||||||
.PHONY: $(SHELLS) test verify-tag release
|
# Default target (by virtue of being the first non '.'-prefixed in the file).
|
||||||
|
.PHONY: _no-target-specified
|
||||||
|
_no-target-specified:
|
||||||
|
$(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)
|
||||||
|
|
||||||
$(SHELLS):
|
# Lists all targets defined in this makefile.
|
||||||
@printf '\n\033[0;34m%s\033[0m\n' "Running tests in $@"
|
.PHONY: list
|
||||||
@$@ $(URCHIN) -f test/$(TEST_SUITE)
|
list:
|
||||||
|
@$(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
|
||||||
|
|
||||||
test: $(SHELLS)
|
# Set of test-<shell> targets; each runs the specified test suites for a single shell.
|
||||||
@$(URCHIN) -f test/slow
|
# 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).
|
||||||
|
.PHONY: $(SHELL_TARGETS)
|
||||||
|
$(SHELL_TARGETS):
|
||||||
|
@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; } && \
|
||||||
|
printf '\n\033[0;34m%s\033[0m\n' "Running tests in $$shell"; \
|
||||||
|
[ -z "$$TRAVIS_BUILD_DIR" ] && for v in $$(export -p | awk -F'[ =]' '$$2 ~ "^NVM_" { print $$2 }'); do unset $$v; done && unset v; \
|
||||||
|
for suite in $(TEST_SUITE); do $$shell $(URCHIN) -f test/$$suite || exit; done
|
||||||
|
|
||||||
default: test
|
# All-tests target: invokes the specified test suites for ALL shells defined in $(SHELLS).
|
||||||
|
.PHONY: test
|
||||||
|
test: $(SHELL_TARGETS)
|
||||||
|
|
||||||
verify-tag:
|
.PHONY: _ensure-tag
|
||||||
|
_ensure-tag:
|
||||||
ifndef TAG
|
ifndef TAG
|
||||||
$(error TAG is undefined)
|
$(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)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
release: verify-tag
|
# Ensures that the git workspace is clean.
|
||||||
@ OLD_TAG=`git describe --abbrev=0 --tags` && \
|
.PHONY: _ensure-clean
|
||||||
replace "$${OLD_TAG/v/}" "$(TAG)" -- nvm.sh install.sh README.markdown package.json && \
|
_ensure-clean:
|
||||||
git commit -m "v$(TAG)" nvm.sh install.sh README.markdown package.json && \
|
@[ -z "$$(git status --porcelain --untracked-files=no || echo err)" ] || { echo "Workspace is not clean; please commit changes first." >&2; exit 2; }
|
||||||
git tag "v$(TAG)"
|
|
||||||
|
|
||||||
|
# Makes a release; invoke with `make TAG=<versionOrIncrementSpec> release`.
|
||||||
|
.PHONY: release
|
||||||
|
release: _ensure-tag _ensure-clean
|
||||||
|
@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}; \
|
||||||
|
new_ver=`echo "$(TAG)" | sed 's/^v//'`; new_ver=$${new_ver:-patch}; \
|
||||||
|
if printf "$$new_ver" | grep -q '^[0-9]'; then \
|
||||||
|
semver "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be major.minor.patch' >&2; exit 2; }; \
|
||||||
|
semver -r "> $$old_ver" "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be HIGHER than current one.' >&2; exit 2; } \
|
||||||
|
else \
|
||||||
|
new_ver=`semver -i "$$new_ver" "$$old_ver"` || { echo 'Invalid version-increment specifier: $(TAG)' >&2; exit 2; } \
|
||||||
|
fi; \
|
||||||
|
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; }; \
|
||||||
|
replace "$$old_ver" "$$new_ver" -- $(VERSIONED_FILES) && \
|
||||||
|
git commit -m "v$$new_ver" $(VERSIONED_FILES) && \
|
||||||
|
git tag -a -m "v$$new_ver" "v$$new_ver"
|
||||||
|
|
15
package.json
15
package.json
|
@ -6,12 +6,12 @@
|
||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "urchin test",
|
"test": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make test-$shell",
|
||||||
"test/fast": "urchin -f test/fast",
|
"test/fast": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=fast test-$shell",
|
||||||
"test/slow": "urchin -f test/slow",
|
"test/slow": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=slow test-$shell",
|
||||||
"test/install_script": "urchin -f test/install_script",
|
"test/install_script": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=install_script test-$shell",
|
||||||
"test/installation": "urchin -f test/installation",
|
"test/installation": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation test-$shell",
|
||||||
"test/sourcing": "urchin -f test/sourcing"
|
"test/sourcing": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=sourcing test-$shell"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -30,7 +30,8 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/creationix/nvm",
|
"homepage": "https://github.com/creationix/nvm",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"replace": "~0.3.0",
|
||||||
|
"semver": "~4.1.0",
|
||||||
"urchin": "~0.0.2"
|
"urchin": "~0.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue