Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- Fix "BUILD_DIR: unbound variable" error when deploying without a Gemfile with `heroku/ruby` buildpack [#1663](https://github.com/heroku/heroku-buildpack-ruby/pull/1663)

## [v328] - 2025-11-17

Expand Down
10 changes: 7 additions & 3 deletions bin/detect
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@
set -euo pipefail

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

if [ -f "$APP_DIR/Gemfile" ]; then
echo "Ruby"
exit 0
fi

# shellcheck source=bin/support/bash_functions.sh
source "$BIN_DIR/support/bash_functions.sh"

output::error <<EOF
Error: Your app is configured to use the Ruby buildpack,
but we couldn't find any supported Ruby project files ('Gemfile.lock').
but we couldn't find any supported Ruby project files ('Gemfile' and 'Gemfile.lock').

A Ruby app on Heroku must have a 'Gemfile.lock' in the root directory of its source code.
A Ruby app on Heroku must have a 'Gemfile' and 'Gemfile.lock' in the root directory of its source code.

Currently the root directory of your app contains:

$(ls -1A --indicator-style=slash "${BUILD_DIR}" || true)
$(ls -1A --indicator-style=slash "${APP_DIR}" || true)

If your app already has a package manager file, check that it:

Expand Down
26 changes: 24 additions & 2 deletions bin/support/bash_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,36 @@

set -euo pipefail

ANSI_RED='\033[1;31m'
ANSI_RESET='\033[0m'

# Output a styled multi-line error message to stderr.
#
# Usage:
# ```
# output::error <<-EOF
# Error: The error summary.
#
# Detailed description.
# EOF
# ```
function output::error() {
local line
echo >&2
while IFS= read -r line; do
echo -e "${ANSI_RED} ! ${line}${ANSI_RESET}" >&2
done
echo >&2
}

curl_retry_on_18() {
local ec=18;
local attempts=0;
while (( ec == 18 && attempts++ < 3 )); do
curl "$@" # -C - would return code 33 if unsupported by server
ec=$?
done
return $ec
return "$ec"
}

which_java()
Expand All @@ -28,7 +50,7 @@ detect_needs_java()

if which_java; then
build_data::kv_string "java_origin" "previously_installed"
return $skip_java_install
return "$skip_java_install"
fi

grep "(jruby " "$gemfile_lock" --quiet &> /dev/null
Expand Down
12 changes: 12 additions & 0 deletions spec/hatchet/bugs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@
end
end
end

it "detect fails when no Gemfile is present" do
Hatchet::Runner.new("default_ruby", allow_failure: true).tap do |app|
app.before_deploy do
FileUtils.rm("Gemfile")
end
app.deploy do |app|
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.")
expect(app).not_to be_deployed
end
end
end
end