Skip to content

Commit 04afbbd

Browse files
committed
Fix unbound variable error
``` remote: -----> App not compatible with buildpack: https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/ruby.tgz remote: /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/bin/detect: line 12: BUILD_DIR: unbound variable remote: /tmp/codon/tmp/buildpacks/50d5eddf222a9b7326028041d4e6509f915ccf2c/bin/detect: line 12: output::error: command not found ```
1 parent 3803bb3 commit 04afbbd

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

bin/detect

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,26 @@
33
set -euo pipefail
44

55
APP_DIR=$1
6+
BIN_DIR=$(cd "$(dirname "$0")" || exit; pwd) # absolute path
67

78
if [ -f "$APP_DIR/Gemfile" ]; then
89
echo "Ruby"
910
exit 0
1011
fi
1112

13+
14+
# shellcheck source=bin/support/bash_functions.sh
15+
source "$BIN_DIR/support/bash_functions.sh"
16+
1217
output::error <<EOF
1318
Error: Your app is configured to use the Ruby buildpack,
14-
but we couldn't find any supported Ruby project files ('Gemfile.lock').
19+
but we couldn't find any supported Ruby project files ('Gemfile' and 'Gemfile.lock').
1520
16-
A Ruby app on Heroku must have a 'Gemfile.lock' in the root directory of its source code.
21+
A Ruby app on Heroku must have a 'Gemfile' and 'Gemfile.lock' in the root directory of its source code.
1722
1823
Currently the root directory of your app contains:
1924
20-
$(ls -1A --indicator-style=slash "${BUILD_DIR}" || true)
25+
$(ls -1A --indicator-style=slash "${APP_DIR}" || true)
2126
2227
If your app already has a package manager file, check that it:
2328

bin/support/bash_functions.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

33
set -euo pipefail
44

5+
ANSI_BLUE='\033[1;34m'
6+
ANSI_RED='\033[1;31m'
7+
ANSI_YELLOW='\033[1;33m'
8+
ANSI_RESET='\033[0m'
9+
10+
# Output a styled multi-line error message to stderr.
11+
#
12+
# Usage:
13+
# ```
14+
# output::error <<-EOF
15+
# Error: The error summary.
16+
#
17+
# Detailed description.
18+
# EOF
19+
# ```
20+
function output::error() {
21+
local line
22+
echo >&2
23+
while IFS= read -r line; do
24+
echo -e "${ANSI_RED} ! ${line}${ANSI_RESET}" >&2
25+
done
26+
echo >&2
27+
}
28+
529
curl_retry_on_18() {
630
local ec=18;
731
local attempts=0;

spec/hatchet/bugs_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,16 @@
2525
end
2626
end
2727
end
28+
29+
it "detect fails when no Gemfile is present" do
30+
Hatchet::Runner.new("default_ruby", allow_failure: true).tap do |app|
31+
app.before_deploy do
32+
FileUtils.rm("Gemfile")
33+
end
34+
app.deploy do |app|
35+
expect(app.output).to include("A Ruby app on Heroku must have a 'Gemfile' and 'Gemfile.lock' in the root directory of its source code.")
36+
expect(app).not_to be_deployed
37+
end
38+
end
39+
end
2840
end

0 commit comments

Comments
 (0)