Commit ab337951 authored by Hunter Loftis's avatar Hunter Loftis

Merge pull request #267 from heroku/detect-errors

Detect errors
parents bfb75db6 63d16e58
......@@ -19,6 +19,9 @@ mkdir -p "$BUILD_DIR/.heroku/node/"
cd $BUILD_DIR
export PATH="$BUILD_DIR/.heroku/node/bin":$PATH
LOG_FILE='/tmp/node-build-log.txt'
echo "" > "$LOG_FILE"
### Load dependencies
source $BP_DIR/lib/output.sh
......@@ -33,7 +36,9 @@ source $BP_DIR/lib/dependencies.sh
handle_failure() {
header "Build failed"
failure_message | indent
warn_untracked_dependencies "$LOG_FILE"
warn_angular_resolution "$LOG_FILE"
failure_message | output "$LOG_FILE"
}
trap 'handle_failure' ERR
......@@ -57,8 +62,8 @@ create_env() {
}
header "Creating runtime environment"
create_env # can't indent the whole thing because piping causes subshells; no exporting possible
list_node_config | indent
create_env # can't pipe the whole thing because piping causes subshells, preventing exports
list_node_config | output "$LOG_FILE"
install_bins() {
local node_engine=$(read_json "$BUILD_DIR/package.json" ".engines.node")
......@@ -86,7 +91,7 @@ install_bins() {
}
header "Installing binaries"
install_bins | indent
install_bins | output "$LOG_FILE"
restore_cache() {
local cache_status="$(get_cache_status)"
......@@ -106,7 +111,7 @@ restore_cache() {
}
header "Restoring cache"
restore_cache | indent
restore_cache | output "$LOG_FILE"
build_dependencies() {
if $PREBUILD; then
......@@ -118,11 +123,11 @@ build_dependencies() {
}
header "Building dependencies"
build_dependencies | indent
build_dependencies | output "$LOG_FILE"
cache_build() {
local cache_directories=$(get_cache_directories)
echo "Clearing previous node cache"
clear_cache
if [ "$cache_directories" == "" ]; then
......@@ -136,7 +141,7 @@ cache_build() {
}
header "Caching build"
cache_build | indent
cache_build | output "$LOG_FILE"
summarize_build() {
cd $BUILD_DIR
......@@ -144,4 +149,4 @@ summarize_build() {
}
header "Build succeeded!"
summarize_build | indent
summarize_build | output "$LOG_FILE"
......@@ -67,3 +67,21 @@ warn_old_npm() {
warning "This version of npm ($npm_version) has several known issues - consider upgrading to the latest release ($latest_npm)" "https://devcenter.heroku.com/articles/nodejs-support#specifying-an-npm-version"
fi
}
warn_untracked_dependencies() {
local log_file="$1"
if grep -qi 'gulp: not found' "$log_file"; then
warning "Gulp may not be tracked in package.json" "https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies"
elif grep -qi 'grunt: not found' "$log_file"; then
warning "Grunt may not be tracked in package.json" "https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies"
elif grep -qi 'bower: not found' "$log_file"; then
warning "Bower may not be tracked in package.json" "https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies"
fi
}
warn_angular_resolution() {
local log_file="$1"
if grep -qi 'Unable to find suitable version for angular' "$log_file"; then
warning "Bower may need a resolution hint for angular" "https://github.com/bower/bower/issues/1746"
fi
}
......@@ -5,11 +5,13 @@ info() {
# sed -l basically makes sed replace and buffer through stdin to stdout
# so you get updates while the command runs and dont wait for the end
# e.g. npm install | indent
indent() {
c='s/^/ /'
output() {
local logfile="$1"
local c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";; # mac/bsd sed: -l buffers on line boundaries
*) sed -u "$c";; # unix/gnu sed: -u unbuffered (arbitrary) chunks of data
Darwin) tee -a "$logfile" | sed -l "$c";; # mac/bsd sed: -l buffers on line boundaries
*) tee -a "$logfile" | sed -u "$c";; # unix/gnu sed: -u unbuffered (arbitrary) chunks of data
esac
}
......
{
"name": "bower-angular-resolution",
"version": "0.0.0",
"homepage": "https://github.com/heroku/heroku-buildpack-nodejs",
"authors": [
"Hunter Loftis <hunter@hunterloftis.com>"
],
"description": "",
"main": "",
"moduleType": [],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"angular": "1.0.7",
"angular-ui-router": "0.2.15"
}
}
{
"name": "node-buildpack-test-app",
"version": "0.0.1",
"description": "node buildpack integration test app",
"repository": {
"type": "git",
"url": "http://github.com/example/example.git"
},
"dependencies": {
"bower": "1.5.3"
},
"engines": {
"node": "4.1.1"
},
"scripts": {
"postinstall": "bower install --allow-root"
}
}
A fake README, to keep npm from polluting stderr.
\ No newline at end of file
{
"name": "node-buildpack-test-app",
"version": "1.0.0",
"description": "node buildpack integration test app",
"repository" : {
"type" : "git",
"url" : "http://github.com/example/example.git"
},
"dependencies": {
},
"engines": {
"node": "4.1.1"
},
"scripts": {
"postinstall": "grunt build"
}
}
#!/usr/bin/env bash
# See README.md for info on running these tests.
testBowerAngularResolution() {
compile "bower-angular-resolution"
assertCaptured "Bower may need a resolution hint for angular"
assertCapturedError
}
testUntrackedDependencies() {
compile "missing-grunt"
assertCaptured "Grunt may not be tracked in package.json"
assertCapturedError
}
testBadJson() {
compile "bad-json"
assertCaptured "Build failed"
assertCaptured "We're sorry this build is failing"
assertNotCaptured "Installing binaries"
assertCapturedError 1 "Unable to parse"
}
testBuildWithUserCacheDirectoriesCamel() {
cache=$(mktmpdir)
......@@ -151,14 +171,6 @@ testDetectWithoutPackageJson() {
assertCapturedError 1 ""
}
testBadJson() {
compile "bad-json"
assertCaptured "Build failed"
assertCaptured "We're sorry this build is failing"
assertNotCaptured "Installing binaries"
assertCapturedError 1 "Unable to parse"
}
testIoJs() {
compile "iojs"
assertCaptured "engines.iojs (package.json): 1.0."
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment