[macOS] Pre-cache Ruby binaries (#2085)

* precache ruby binaries

* remove github_feed_token and minor change

* do not install ruby binaries from toolset

* remove toolcache file
This commit is contained in:
Dibir Magomedsaygitov
2020-11-27 10:53:17 +03:00
committed by GitHub
parent 38b0a6005d
commit 75d141eb67
14 changed files with 319 additions and 331 deletions

View File

@@ -4,3 +4,40 @@ source ~/utils/utils.sh
echo Installing Ruby...
brew install ruby
#if High Sierra - skip installation from toolset
if is_HighSierra; then
exit 0
fi
echo "Install Ruby from toolset..."
PACKAGE_TAR_NAMES=$(curl -s "https://api.github.com/repos/ruby/ruby-builder/releases/latest" | jq -r '.assets[].name')
TOOLSET_VERSIONS=$(get_toolset_value '.toolcache[] | select(.name | contains("Ruby")) | .versions[]')
RUBY_PATH="$AGENT_TOOLSDIRECTORY/Ruby"
echo "Check if Ruby hostedtoolcache folder exists..."
if [ ! -d $RUBY_PATH ]; then
mkdir -p $RUBY_PATH
fi
for TOOLSET_VERSION in ${TOOLSET_VERSIONS[@]}; do
PACKAGE_TAR_NAME=$(echo "$PACKAGE_TAR_NAMES" | grep "^ruby-${TOOLSET_VERSION}-macos-latest.tar.gz$" | sort -V | tail -1)
RUBY_VERSION=$(echo "$PACKAGE_TAR_NAME" | cut -d'-' -f 2)
RUBY_VERSION_PATH="$RUBY_PATH/$RUBY_VERSION"
echo "Create Ruby $RUBY_VERSION directory..."
mkdir -p $RUBY_VERSION_PATH
echo "Downloading tar archive $PACKAGE_TAR_NAME"
DOWNLOAD_URL="https://github.com/ruby/ruby-builder/releases/download/toolcache/${PACKAGE_TAR_NAME}"
download_with_retries $DOWNLOAD_URL "/tmp" $PACKAGE_TAR_NAME
echo "Expand '$PACKAGE_TAR_NAME' to the '$RUBY_VERSION_PATH' folder"
tar xf "/tmp/$PACKAGE_TAR_NAME" -C $RUBY_VERSION_PATH
COMPLETE_FILE_PATH="$RUBY_VERSION_PATH/x64.complete"
if [ ! -f $COMPLETE_FILE_PATH ]; then
echo "Create complete file"
touch $COMPLETE_FILE_PATH
fi
done

View File

@@ -1,38 +0,0 @@
#!/bin/bash -e -o pipefail
# Download hosted tool cache with npm
NPM_FEED="npm.pkg.github.com"
TOOLSET_PATH="$HOME/image-generation/toolcache.json"
echo "Installing npm-toolcache..."
PACKAGE_LIST=($(jq -r 'keys | .[]' $TOOLSET_PATH))
# Execute in /tmp folder to avoid node_modules creation in $HOME
pushd /tmp
# GitHub Package Registry doesn't support downloading public packages without auth so we have to authorize
# Put the .npmrc to /tmp directory on the image to make sure that it will deleted after image generation
echo "Configure auth for github package registry"
echo "@actions:registry=https://${NPM_FEED}/" >> ".npmrc"
echo "//${NPM_FEED}/:_authToken=${GITHUB_FEED_TOKEN}" >> ".npmrc"
echo "Install packages..."
for PACKAGE_NAME in ${PACKAGE_LIST[@]}; do
PACKAGE_VERSIONS=($(jq -r ".[\"$PACKAGE_NAME\"] | .[]" $TOOLSET_PATH))
for PACKAGE_VERSION in ${PACKAGE_VERSIONS[@]}; do
echo "Install ${PACKAGE_NAME}@${PACKAGE_VERSION}"
npm install ${PACKAGE_NAME}@${PACKAGE_VERSION}
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "${PACKAGE_NAME}@${PACKAGE_VERSION} installation failure; Error:${exit_code}"
exit 1
fi
done;
done;
rm -f ".npmrc"
popd

View File

@@ -11,7 +11,6 @@
"output_folder": null,
"vm_username": null,
"vm_password": null,
"github_feed_token": null,
"xcode_install_user": null,
"xcode_install_password": null,
"image_os": "macos1013"
@@ -87,11 +86,6 @@
"source": "./toolsets/toolset-10.13.json",
"destination": "~/image-generation/toolset.json"
},
{
"type": "file",
"source": "./toolsets/toolcache-10.13.json",
"destination": "~/image-generation/toolcache.json"
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}",

View File

@@ -11,7 +11,6 @@
"output_folder": null,
"vm_username": null,
"vm_password": null,
"github_feed_token": null,
"xcode_install_user": null,
"xcode_install_password": null,
"image_os": "macos1014"
@@ -87,11 +86,6 @@
"source": "./toolsets/toolset-10.14.json",
"destination": "~/image-generation/toolset.json"
},
{
"type": "file",
"source": "./toolsets/toolcache-10.14.json",
"destination": "~/image-generation/toolcache.json"
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}",
@@ -187,12 +181,8 @@
"./provision/core/miniconda.sh",
"./provision/core/xcode-sims.sh",
"./provision/core/xcode-postbuild.sh",
"./provision/core/toolcache.sh",
"./provision/core/pypy.sh",
"./provision/core/pipx-packages.sh"
],
"environment_vars": [
"GITHUB_FEED_TOKEN={{user `github_feed_token`}}"
]
},
{

View File

@@ -11,7 +11,6 @@
"output_folder": null,
"vm_username": null,
"vm_password": null,
"github_feed_token": null,
"xcode_install_user": null,
"xcode_install_password": null,
"image_os": "macos1015"
@@ -87,11 +86,6 @@
"source": "./toolsets/toolset-10.15.json",
"destination": "~/image-generation/toolset.json"
},
{
"type": "file",
"source": "./toolsets/toolcache-10.14.json",
"destination": "~/image-generation/toolcache.json"
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}",
@@ -188,12 +182,8 @@
"./provision/core/edge.sh",
"./provision/core/firefox.sh",
"./provision/core/xcode-postbuild.sh",
"./provision/core/toolcache.sh",
"./provision/core/pypy.sh",
"./provision/core/pipx-packages.sh"
],
"environment_vars": [
"GITHUB_FEED_TOKEN={{user `github_feed_token`}}"
]
},
{

View File

@@ -11,7 +11,6 @@
"output_folder": null,
"vm_username": null,
"vm_password": null,
"github_feed_token": null,
"xcode_install_user": null,
"xcode_install_password": null,
"image_os": "macos11"
@@ -87,11 +86,6 @@
"source": "./toolsets/toolset-11.0.json",
"destination": "~/image-generation/toolset.json"
},
{
"type": "file",
"source": "./toolsets/toolcache-11.0.json",
"destination": "~/image-generation/toolcache.json"
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}",
@@ -185,11 +179,7 @@
"./provision/core/chrome.sh",
"./provision/core/edge.sh",
"./provision/core/firefox.sh",
"./provision/core/toolcache.sh",
"./provision/core/pipx-packages.sh"
],
"environment_vars": [
"GITHUB_FEED_TOKEN={{user `github_feed_token`}}"
]
},
{

View File

@@ -5,12 +5,15 @@ $os = Get-OSVersion
Describe "Toolcache" {
$toolcacheDirectory = Join-Path $env:HOME "hostedtoolcache"
$packages = (Get-ToolcachePackages).PSObject.Properties | ForEach-Object {
$packageNameParts = $_.Name.Split("-")
return [PSCustomObject] @{
ToolName = $packageNameParts[1]
Arch = $packageNameParts[4]
Versions = $_.Value
[array]$packages = @()
if ($os.IsHighSierra) {
[array]$packages += (Get-ToolcachePackages).PSObject.Properties | ForEach-Object {
$packageNameParts = $_.Name.Split("-")
return [PSCustomObject] @{
ToolName = $packageNameParts[1]
Arch = $packageNameParts[4]
Versions = $_.Value
}
}
}
@@ -67,7 +70,7 @@ Describe "Toolcache" {
Context "Ruby" {
$rubyDirectory = Join-Path $toolcacheDirectory "Ruby"
$rubyPackage = $packages | Where-Object { $_.ToolName -eq "ruby" } | Select-Object -First 1
$rubyPackage = $packages | Where-Object { $_.ToolName -eq "Ruby" } | Select-Object -First 1
$testCase = @{ RubyDirectory = $rubyDirectory }
It "Toolcache directory exists" -TestCases $testCase {

View File

@@ -1,8 +0,0 @@
{
"@actions/toolcache-python-macos-1013-x64": [
"2.7", "3.5", "3.6", "3.7", "3.8"
],
"@actions/toolcache-ruby-macos-1013-x64": [
"2.4", "2.5", "2.6", "2.7"
]
}

View File

@@ -1,5 +0,0 @@
{
"@actions/toolcache-ruby-macos-1013-x64": [
"2.4", "2.5", "2.6", "2.7"
]
}

View File

@@ -1,5 +0,0 @@
{
"@actions/toolcache-ruby-macos-1013-x64": [
"2.4", "2.5", "2.6", "2.7"
]
}

View File

@@ -210,6 +210,16 @@
"2.7",
"3.6"
]
},
{
"name": "Ruby",
"arch": "x64",
"versions": [
"2.4.*",
"2.5.*",
"2.6.*",
"2.7.*"
]
}
],
"pipx": [

View File

@@ -269,6 +269,16 @@
"1.14.*",
"1.15.*"
]
},
{
"name": "Ruby",
"arch": "x64",
"versions": [
"2.4.*",
"2.5.*",
"2.6.*",
"2.7.*"
]
}
],
"pipx": [

View File

@@ -190,6 +190,16 @@
"1.14.*",
"1.15.*"
]
},
{
"name": "Ruby",
"arch": "x64",
"versions": [
"2.4.*",
"2.5.*",
"2.6.*",
"2.7.*"
]
}
],
"pipx": [

View File

@@ -108,6 +108,16 @@
"versions": [
"1.15.*"
]
},
{
"name": "Ruby",
"arch": "x64",
"versions": [
"2.4.*",
"2.5.*",
"2.6.*",
"2.7.*"
]
}
],
"pipx": [