summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@chef.io>2020-04-06 20:12:18 -0400
committerGitHub <noreply@github.com>2020-04-06 20:12:18 -0400
commit63ebafb4c79c0f9bae6b31d7ae115f9f4762f380 (patch)
treecc7523f63cef3606a1be9f6aa1a9d339bdb01de3
parentebfae0330b8ee7c25ea8a5bc8da9832406b9dcdd (diff)
parent36d254fe1e2c2d0a274854ce627add1f622459b7 (diff)
downloadchef-63ebafb4c79c0f9bae6b31d7ae115f9f4762f380.tar.gz
Merge pull request #9604 from chef/btm/15-fix-win-func-test
15 backport: Improved Ruby download/install for functional tests
-rw-r--r--scripts/bk_tests/bk_win_functional.ps183
1 files changed, 74 insertions, 9 deletions
diff --git a/scripts/bk_tests/bk_win_functional.ps1 b/scripts/bk_tests/bk_win_functional.ps1
index 12bb72c9ba..9a9d50a63b 100644
--- a/scripts/bk_tests/bk_win_functional.ps1
+++ b/scripts/bk_tests/bk_win_functional.ps1
@@ -1,3 +1,76 @@
+# The filename of the Ruby installer
+$RubyFilename = "rubyinstaller-devkit-2.6.5-1-x64.exe"
+
+# The sha256 of the Ruby installer (capitalized?)
+$RubySHA256 = "BD2050496A149C7258ED4E2E44103756CA3A05C7328A939F0FDC97AE9616A96D"
+
+# Where on disk to download Ruby to
+$RubyPath = "$env:temp\$RubyFilename"
+
+# Where to download Ruby from:
+$RubyS3Path = "s3://public-cd-buildkite-cache/$RubyFilename"
+
+Function DownloadRuby
+{
+ $RandDigits = Get-Random
+ echo "Downloading Ruby + DevKit"
+
+ aws s3 cp "$RubyS3Path" "$RubyPath.$RandDigits" | Out-Null # Out-Null is a hack to wait for the process to complete
+
+ if ($LASTEXITCODE -ne 0) {
+ echo "aws s3 download failed: $LASTEXITCODE"
+ exit $LASTEXITCODE
+ }
+
+ $FileHash = (Get-FileHash "$RubyPath.$RandDigits" -Algorithm SHA256).Hash
+ If ($FileHash -eq $RubySHA256) {
+ echo "Downloaded SHA256 matches: $FileHash"
+ } Else {
+ echo "Downloaded file hash $FileHash does not match desired $RubySHA256"
+ exit 1
+ }
+
+ # On a shared filesystem, sometimes a good file appears while we are downloading
+ If (Test-Path $RubyPath) {
+ $FileHash = (Get-FileHash "$RubyPath" -Algorithm SHA256).Hash
+ If ($FileHash -eq $RubySHA256) {
+ echo "A matching file appeared while downloading, using it."
+ Remove-Item "$RubyPath.$RandDigits" -Force
+ Return
+ } Else {
+ echo "Existing file does not match, bad hash: $FileHash"
+ Remove-Item $RubyPath -Force
+ }
+ }
+
+ echo "Moving file installer into place"
+ Rename-Item -Path "$RubyPath.$RandDigits" -NewName $RubyFilename
+}
+
+Function InstallRuby
+{
+ If (Test-Path $RubyPath) {
+ echo "$RubyPath already exists"
+
+ $FileHash = (Get-FileHash "$RubyPath" -Algorithm SHA256).Hash
+ If ($FileHash -eq $RubySHA256) {
+ echo "Found matching Ruby + DevKit on disk"
+ } Else {
+ echo "SHA256 hash mismatch, re-downloading"
+ DownloadRuby
+ }
+ } Else {
+ echo "No Ruby found at $RubyPath, downloading"
+ DownloadRuby
+ }
+
+ echo "Installing Ruby + DevKit"
+ Start-Process $RubyPath -ArgumentList '/verysilent /dir=C:\\ruby26' -Wait
+
+ echo "Cleaning up installation"
+ Remove-Item $RubyPath -Force -ErrorAction SilentlyContinue
+}
+
echo "--- system details"
$Properties = 'Caption', 'CSName', 'Version', 'BuildType', 'OSArchitecture'
Get-CimInstance Win32_OperatingSystem | Select-Object $Properties | Format-Table -AutoSize
@@ -8,15 +81,7 @@ Remove-Item -Path C:\ProgramData\chocolatey\bin\choco.exe -ErrorAction SilentlyC
echo "--- install ruby + devkit"
$ErrorActionPreference = 'Stop'
-echo "Downloading Ruby + DevKit"
-aws s3 cp s3://public-cd-buildkite-cache/rubyinstaller-devkit-2.6.5-1-x64.exe $env:temp/rubyinstaller-devkit-2.6.5-1-x64.exe
-
-echo "Installing Ruby + DevKit"
-Start-Process $env:temp\rubyinstaller-devkit-2.6.5-1-x64.exe -ArgumentList '/verysilent /dir=C:\\ruby26' -Wait
-
-echo "Cleaning up installation"
-Remove-Item $env:temp\rubyinstaller-devkit-2.6.5-1-x64.exe -Force
-echo "Closing out the layer (this can take awhile)"
+InstallRuby
# Set-Item -Path Env:Path -Value to include ruby26
$Env:Path+=";C:\ruby26\bin"