Skip to content

Commit 3835dff

Browse files
committed
fix(ruby): accept both "_" and "." tag separators from ruby/ruby
ruby/ruby switched its release tag separator from "_" (e.g. v3_4_9) to "." (e.g. v4.0.4) starting at Ruby 4.0.0. The regex in find_version_from_git_tags only matched the caller-specified separator, so VERSION=latest and ADDITIONAL_VERSIONS resolution silently skipped every 4.x release. Normalize the tag list with `tr "_" "."` before matching and use "." canonically in the regex. The `separator` parameter is no longer consulted for matching, so drop the now-redundant `"_"` argument from the three ruby call sites.
1 parent 8c47157 commit 3835dff

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

src/ruby/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "ruby",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"name": "Ruby (via rvm)",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/ruby",
66
"description": "Installs Ruby, rvm, rbenv, common Ruby utilities, and needed dependencies.",

src/ruby/install.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,17 @@ find_version_from_git_tags() {
147147
local repository=$2
148148
local prefix=${3:-"tags/v"}
149149
local separator=${4:-"."}
150-
local last_part_optional=${5:-"false"}
150+
local last_part_optional=${5:-"false"}
151151
if [ "$(echo "${requested_version}" | grep -o "." | wc -l)" != "2" ]; then
152-
local escaped_separator=${separator//./\\.}
153152
local last_part
154153
if [ "${last_part_optional}" = "true" ]; then
155-
last_part="(${escaped_separator}[0-9]+)?"
154+
last_part="(\\.[0-9]+)?"
156155
else
157-
last_part="${escaped_separator}[0-9]+"
156+
last_part="\\.[0-9]+"
158157
fi
159-
local regex="${prefix}\\K[0-9]+${escaped_separator}[0-9]+${last_part}$"
160-
local version_list="$(git ls-remote --tags ${repository} | grep -oP "${regex}" | tr -d ' ' | tr "${separator}" "." | sort -rV)"
158+
local regex="${prefix}\\K[0-9]+\\.[0-9]+${last_part}$"
159+
# ruby/ruby switched its tag separator from "_" (v3_4_5) to "." (v4.0.0) at v4.0.0
160+
local version_list="$(git ls-remote --tags ${repository} | tr "_" "." | grep -oP "${regex}" | tr -d ' ' | sort -rV)"
161161
if [ "${requested_version}" = "latest" ] || [ "${requested_version}" = "current" ] || [ "${requested_version}" = "lts" ]; then
162162
declare -g ${variable_name}="$(echo "${version_list}" | head -n 1)"
163163
else
@@ -280,7 +280,7 @@ get_previous_version() {
280280
if [[ $message == "API rate limit exceeded"* ]]; then
281281
echo -e "\nAn attempt to find latest version using GitHub Api Failed... \nReason: ${message}"
282282
echo -e "\nAttempting to find latest version using GitHub tags."
283-
find_prev_version_from_git_tags prev_version "$url" "tags/v" "_"
283+
find_prev_version_from_git_tags prev_version "$url" "tags/v"
284284
declare -g ${variable_name}="${prev_version}"
285285
else
286286
echo -e "\nAttempting to find latest version using GitHub Api."
@@ -299,7 +299,7 @@ get_github_api_repo_url() {
299299
# Figure out correct version of a three part version number is not passed
300300
RUBY_URL="https://github.com/ruby/ruby"
301301
ORIGINAL_RUBY_VERSION=$RUBY_VERSION
302-
find_version_from_git_tags RUBY_VERSION $RUBY_URL "tags/v" "_"
302+
find_version_from_git_tags RUBY_VERSION $RUBY_URL "tags/v"
303303

304304
set_rvm_install_args() {
305305
RUBY_VERSION=$1
@@ -379,7 +379,7 @@ if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then
379379
read -a additional_versions <<< "$ADDITIONAL_VERSIONS"
380380
for version in "${additional_versions[@]}"; do
381381
# Figure out correct version of a three part version number is not passed
382-
find_version_from_git_tags version $RUBY_URL "tags/v" "_"
382+
find_version_from_git_tags version $RUBY_URL "tags/v"
383383
source /usr/local/rvm/scripts/rvm
384384
rvm install ruby ${version}
385385
done

test/ruby/test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ source dev-container-features-test-lib
99
check "ruby version" ruby --version
1010
check "gem version" gem --version
1111

12+
check "ruby version uses dot separator" bash -c "ruby --version | grep -oP '\d+\.\d+\.\d+'"
13+
1214
# Report result
1315
reportResults

0 commit comments

Comments
 (0)