Skip to content

Commit 16c1947

Browse files
committed
Support building with version prefix
Commonly in CI pipelines and other scripts, users may want to install the latest from a specific series, e.g. `3.4` or `jruby-10.0`. ```bash $ bin/ruby-build 3.4 /tmp/3.4 ... Downloading ruby-3.4.9.tar.gz... $ bin/ruby-build 4.0 /tmp/4.0 ... Downloading ruby-4.0.2.tar.gz... ```
1 parent aa270b3 commit 16c1947

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

bin/ruby-build

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,22 @@ list_maintained_versions() {
14011401
} | extract_latest_versions | sort_versions | uniq
14021402
}
14031403

1404+
resolve_version() {
1405+
prefix="${1}"
1406+
{ for DEFINITION_DIR in "${RUBY_BUILD_DEFINITIONS[@]}"; do
1407+
if [[ -d "$DEFINITION_DIR" ]]; then
1408+
pushd "$DEFINITION_DIR" > /dev/null || return 1
1409+
for f in "${prefix}"*; do
1410+
echo "${f}" | \
1411+
grep "^${prefix}\." | \
1412+
grep -v -e '-rc[0-9]*$' -e '-preview[0-9]*$' -e '-dev$'
1413+
done
1414+
popd > /dev/null || return 1
1415+
fi
1416+
done
1417+
} | extract_latest_versions | tail -n 1
1418+
}
1419+
14041420
extract_latest_versions() {
14051421
# sort in this function looks redundunt but it is necessary
14061422
# rbx-3.99 appears latest unless the sort
@@ -1543,6 +1559,16 @@ if [[ ! -f "$DEFINITION_PATH" && ! -p "$DEFINITION_PATH" ]]; then
15431559
done
15441560
fi
15451561

1562+
if [ ! -f "$DEFINITION_PATH" ]; then
1563+
fully_qualified_version=$(resolve_version "$DEFINITION_PATH")
1564+
for DEFINITION_DIR in "${RUBY_BUILD_DEFINITIONS[@]}"; do
1565+
if [ -f "${DEFINITION_DIR}/${fully_qualified_version}" ]; then
1566+
DEFINITION_PATH="${DEFINITION_DIR}/${fully_qualified_version}"
1567+
break
1568+
fi
1569+
done
1570+
fi
1571+
15461572
if [ ! -f "$DEFINITION_PATH" ]; then
15471573
echo "ruby-build: definition not found: ${DEFINITION_PATH}" >&2
15481574
exit 2

test/definitions.bats

100644100755
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ NUM_DEFINITIONS="$(ls "$BATS_TEST_DIRNAME"/../share/ruby-build | wc -l)"
6060
assert_success ""
6161
}
6262

63+
@test "installing definition by prefix" {
64+
export RUBY_BUILD_DEFINITIONS="${TMP}/definitions"
65+
mkdir -p "${TMP}/definitions"
66+
67+
echo false > "${TMP}/definitions/1.8.6"
68+
echo false > "${TMP}/definitions/1.9.3"
69+
echo true > "${TMP}/definitions/1.9.10"
70+
echo false > "${TMP}/definitions/1.90.0"
71+
echo false > "${TMP}/definitions/2.0.0"
72+
73+
run bin/ruby-build "1.9" "${TMP}/install"
74+
assert_success ""
75+
}
76+
6377
@test "installing nonexistent definition" {
6478
run ruby-build "nonexistent" "${TMP}/install"
6579
assert [ "$status" -eq 2 ]

0 commit comments

Comments
 (0)