Skip to content

Commit 71dffe1

Browse files
[macOS] Update Ruby installer script due to #13050 (#13052)
* [macOS] Update Ruby installer script due to #13050 * Nit: extend version filter just in case * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 98a1416 commit 71dffe1

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

images/macos/scripts/build/install-ruby.sh

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,49 @@ source ~/utils/utils.sh
88

99
arch=$(get_arch)
1010
DEFAULT_RUBY_VERSION=$(get_toolset_value '.ruby.default')
11+
RUBY_PATH=$AGENT_TOOLSDIRECTORY/Ruby
12+
TOOLSET_VERSIONS=$(get_toolset_value '.toolcache[] | select(.name | contains("Ruby")) | .arch.'$arch'.versions[]')
13+
1114
echo "Installing Ruby..."
1215
brew_smart_install "ruby@${DEFAULT_RUBY_VERSION}"
16+
17+
echo "Set Ruby ${DEFAULT_RUBY_VERSION} as default"
1318
if [[ $arch == "arm64" ]]; then
1419
export PATH=/opt/homebrew/opt/ruby@${DEFAULT_RUBY_VERSION}/bin:$PATH
15-
ruby_suffix="macos-13-arm64"
1620
else
1721
export PATH=/usr/local/opt/ruby@${DEFAULT_RUBY_VERSION}/bin:$PATH
18-
ruby_suffix="macos-latest"
1922
fi
2023

24+
echo "Setting up gem environment"
2125
GEM_PATH=$(gem env|awk '/EXECUTABLE DIRECTORY/ {print $4}')
2226
echo "GEM_PATH=$GEM_PATH" >> $HOME/.bashrc
27+
2328
if [[ $arch == "arm64" ]]; then
2429
echo 'export PATH="$GEM_PATH:/opt/homebrew/opt/ruby@'${DEFAULT_RUBY_VERSION}'/bin:$PATH"' >> $HOME/.bashrc
2530
else
2631
echo 'export PATH="$GEM_PATH:/usr/local/opt/ruby@'${DEFAULT_RUBY_VERSION}'/bin:$PATH"' >> $HOME/.bashrc
2732
fi
2833

29-
echo "Install Ruby from toolset..."
30-
[ -n "$API_PAT" ] && authString=(-H "Authorization: token ${API_PAT}")
31-
PACKAGE_TAR_NAMES=$(curl "${authString[@]}" -fsSL "https://api.github.com/repos/ruby/ruby-builder/releases/latest" | jq -r '.assets[].name')
32-
TOOLSET_VERSIONS=$(get_toolset_value '.toolcache[] | select(.name | contains("Ruby")) | .arch.'$arch'.versions[]')
33-
RUBY_PATH=$AGENT_TOOLSDIRECTORY/Ruby
34-
35-
echo "Check if Ruby hostedtoolcache folder exists..."
34+
echo "Check if Ruby hostedtoolcache folder exists"
3635
if [[ ! -d $RUBY_PATH ]]; then
37-
mkdir -p $RUBY_PATH
36+
mkdir -p "$RUBY_PATH"
3837
fi
39-
echo "ruby path - $RUBY_PATH"
4038

4139
for toolset_version in ${TOOLSET_VERSIONS[@]}; do
42-
package_tar_name=$(echo "$PACKAGE_TAR_NAMES" | grep "^ruby-${toolset_version}-${ruby_suffix}.tar.gz$" | egrep -v "rc|preview" | sort -V | tail -1)
40+
echo "Installing Ruby version: $toolset_version..."
41+
download_url=$(resolve_github_release_asset_url "ruby/ruby-builder" "contains(\"darwin-$arch.tar.gz\")" "ruby-$toolset_version" "$API_PAT")
42+
package_tar_name="${download_url##*/}"
4343
ruby_version=$(echo "$package_tar_name" | cut -d'-' -f 2)
4444
ruby_version_path="$RUBY_PATH/$ruby_version"
4545

46-
echo "Create Ruby $ruby_version directory..."
47-
mkdir -p $ruby_version_path
46+
echo "Create Ruby $ruby_version directory"
47+
mkdir -p "$ruby_version_path"
4848

4949
echo "Downloading tar archive $package_tar_name"
50-
archive_path=$(download_with_retry "https://github.com/ruby/ruby-builder/releases/download/toolcache/${package_tar_name}")
50+
archive_path=$(download_with_retry "$download_url")
5151

5252
echo "Expand $package_tar_name to the $ruby_version_path folder"
53-
tar xf $archive_path -C $ruby_version_path
53+
tar xf "$archive_path" -C "$ruby_version_path"
5454
complete_file_path=$ruby_version_path/$arch.complete
5555
if [[ ! -f $complete_file_path ]]; then
5656
echo "Create complete file"

0 commit comments

Comments
 (0)