diff --git a/images/win/Windows2016-Azure.json b/images/win/Windows2016-Azure.json index 47bcdbd46..fcb0ed4ca 100644 --- a/images/win/Windows2016-Azure.json +++ b/images/win/Windows2016-Azure.json @@ -323,12 +323,6 @@ "{{ template_dir }}/scripts/Installers/Download-ToolCache.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Windows2016/Install-Python.ps1" - ] - }, { "type": "powershell", "scripts":[ @@ -357,12 +351,6 @@ "{{ template_dir }}/scripts/Installers/Install-PHP.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Install-Ruby.ps1" - ] - }, { "type": "powershell", "scripts":[ @@ -632,12 +620,6 @@ "{{ template_dir }}/scripts/Installers/Validate-ToolCache.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-Python.ps1" - ] - }, { "type": "powershell", "scripts":[ @@ -676,12 +658,6 @@ "{{ template_dir }}/scripts/Installers/Validate-PHP.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-Ruby.ps1" - ] - }, { "type": "powershell", "scripts":[ diff --git a/images/win/Windows2019-Azure.json b/images/win/Windows2019-Azure.json index e1e91ac59..8f82a6eb2 100644 --- a/images/win/Windows2019-Azure.json +++ b/images/win/Windows2019-Azure.json @@ -298,12 +298,6 @@ "{{ template_dir }}/scripts/Installers/Download-ToolCache.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Windows2019/Install-Python.ps1" - ] - }, { "type": "powershell", "scripts":[ @@ -332,12 +326,6 @@ "{{ template_dir }}/scripts/Installers/Install-PHP.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Install-Ruby.ps1" - ] - }, { "type": "powershell", "scripts":[ @@ -619,12 +607,6 @@ "{{ template_dir }}/scripts/Installers/Validate-ToolCache.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-Python.ps1" - ] - }, { "type": "powershell", "scripts":[ @@ -663,12 +645,6 @@ "{{ template_dir }}/scripts/Installers/Validate-PHP.ps1" ] }, - { - "type": "powershell", - "scripts":[ - "{{ template_dir }}/scripts/Installers/Validate-Ruby.ps1" - ] - }, { "type": "powershell", "scripts":[ diff --git a/images/win/scripts/Installers/Download-ToolCache.ps1 b/images/win/scripts/Installers/Download-ToolCache.ps1 index 591f0f1cc..cc42e97ec 100644 --- a/images/win/scripts/Installers/Download-ToolCache.ps1 +++ b/images/win/scripts/Installers/Download-ToolCache.ps1 @@ -44,6 +44,39 @@ Function NPMFeed-AuthSetup { $npmrcContent | Out-File -FilePath "$($env:TEMP)/.npmrc" -Encoding utf8 } +Function Set-DefaultPythonVersion { + param( + [Parameter(Mandatory=$true)] + [System.Version] $Version, + [System.String] $Arch = "x64" + ) + + $pythonPath = $Env:AGENT_TOOLSDIRECTORY + "/Python/${Version}*/${Arch}" + $pythonDir = Get-Item -Path $pythonPath + + Write-Host "Use Python ${Version} as a system Python" + Add-MachinePathItem -PathItem $pythonDir.FullName + Add-MachinePathItem -PathItem "$($pythonDir.FullName)\Scripts" +} + +Function Set-DefaultRubyVersion { + param( + [Parameter(Mandatory=$true)] + [System.Version] $Version, + [System.String] $Arch = "x64" + ) + $rubyPath = $Env:AGENT_TOOLSDIRECTORY + "/Ruby/${Version}*/${Arch}/bin" + $rubyDir = Get-Item -Path $rubyPath + + Write-Host "Use Ruby ${Version} as a system Ruby" + Add-MachinePathItem -PathItem $rubyDir.FullName + + # Update ruby gem to latest version + gem update --system +} + +Import-Module -Name ImageHelpers -Force + $FeedPrefix = "https://npm.pkg.github.com" $AccessToken = $env:GITHUB_FEED_TOKEN @@ -71,7 +104,5 @@ $ToolVersions.PSObject.Properties | ForEach-Object { } } -#junction point from the previous Python2 directory to the toolcache Python2 -Write-Host "Create symlink to Python2" -$python2Dir = (Get-Item -Path ($ToolsDirectory + '/Python/2.7*/x64')).FullName -cmd.exe /c mklink /d "C:\Python27amd64" "$python2Dir" \ No newline at end of file +Set-DefaultPythonVersion -Version "3.7" +Set-DefaultRubyVersion -Version "2.5" \ No newline at end of file diff --git a/images/win/scripts/Installers/Install-Ruby.ps1 b/images/win/scripts/Installers/Install-Ruby.ps1 deleted file mode 100644 index 546a4591e..000000000 --- a/images/win/scripts/Installers/Install-Ruby.ps1 +++ /dev/null @@ -1,24 +0,0 @@ -################################################################################ -## File: Install-Ruby.ps1 -## Desc: Install Ruby for Windows -################################################################################ - -Import-Module -Name ImageHelpers - -# Ruby versions are already available in the tool cache. - -# Tool cache Ruby Path -$toolcacheRubyPath = 'C:\hostedtoolcache\windows\Ruby\2.5.*' - -# Get Latest Ruby 2.5.x -$latestRubyBinPath2_5 = Get-ChildItem -Path $toolcacheRubyPath | Sort-Object {[System.Version]$_.Name} | Select-Object -Last 1 | ForEach-Object { - Join-Path $_.FullName 'x64\bin' -} - -Add-MachinePathItem $latestRubyBinPath2_5 -$env:Path = Get-MachinePath - -# Update ruby gem to latest version -gem update --system - -exit 0 diff --git a/images/win/scripts/Installers/Validate-Python.ps1 b/images/win/scripts/Installers/Validate-Python.ps1 deleted file mode 100644 index 7e2ee6e46..000000000 --- a/images/win/scripts/Installers/Validate-Python.ps1 +++ /dev/null @@ -1,45 +0,0 @@ -################################################################################ -## File: Validate-Python.ps1 -## Desc: Configure python on path based on what is installed in the tools cache -## Must run after tools cache is downloaded and validated -################################################################################ - -if(Get-Command -Name 'python') -{ - Write-Host "Python $(& python -V 2>&1) on path" -} -else -{ - Write-Host "Python is not on path" - exit 1 -} - -$Python3Version = $(& python -V 2>&1) - -if ($Python3Version -notlike "Python 3.*") -{ - Write-Error "Python 3 is not in the PATH" -} - - -$python2path = $Env:AGENT_TOOLSDIRECTORY + '/Python/2.7*/x64' -$python2Dir = Get-Item -Path $python2path - -$env:Path = $python2Dir.FullName + ";" + $env:Path - -$Python2Version = & $env:comspec "/s /c python --version 2>&1" - -# Adding description of the software to Markdown -$SoftwareName = "Python (64 bit)" - -$Description = @" -#### $Python3Version -_Environment:_ -* PATH: contains location of python.exe - -#### $Python2Version - -_Location:_ $Python2Path -"@ - -Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description diff --git a/images/win/scripts/Installers/Validate-Ruby.ps1 b/images/win/scripts/Installers/Validate-Ruby.ps1 deleted file mode 100644 index 88347ee1b..000000000 --- a/images/win/scripts/Installers/Validate-Ruby.ps1 +++ /dev/null @@ -1,55 +0,0 @@ -################################################################################ -## File: Validate-Ruby.ps1 -## Desc: Verify that Ruby is on the path and output version information. -################################################################################ - -# Function that gets the version of Ruby at the specified path -function Get-RubyVersion -{ - Param - ( - [String]$rubyRootPath - ) - - # Prepend to the path like: C:\hostedtoolcache\windows\Ruby\2.5.0\x64\bin - $env:Path = "$rubyRootPath;" + $env:Path - - # Extract the version from Ruby output like: ruby 2.5.1p57 (2018-03-29 revision 63029) [x64-mingw32] - if( $(ruby --version) -match 'ruby (?.*) \(.*' ) - { - $rubyVersion = $Matches.version - return $rubyVersion - } - - Write-Host "Unable to determine Ruby version at " + $rubyRootPath - exit 1 -} - -# Verify that ruby is on the path -if(Get-Command -Name 'ruby') -{ - Write-Host "$(ruby --version) is on the path." -} -else -{ - Write-Host "Ruby is not on the path." - exit 1 -} - -# Default Ruby Version on Path -$rubyExeOnPath = (Get-Command -Name 'ruby').Path -$rubyBinOnPath = Split-Path -Path $rubyExeOnPath -$rubyVersionOnPath = Get-RubyVersion -rubyRootPath $rubyBinOnPath -$gemVersion = & gem -v - -# Add details of available versions in Markdown -$SoftwareName = "Ruby (x64)" -$Description = @" -#### $rubyVersionOnPath -_Environment:_ -* Location: $rubyBinOnPath -* PATH: contains the location of ruby.exe version $rubyVersionOnPath -* Gem Version: $gemVersion -"@ - -Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description diff --git a/images/win/scripts/Installers/Validate-ToolCache.ps1 b/images/win/scripts/Installers/Validate-ToolCache.ps1 index 3e3b095f2..5ad500bf4 100644 --- a/images/win/scripts/Installers/Validate-ToolCache.ps1 +++ b/images/win/scripts/Installers/Validate-ToolCache.ps1 @@ -63,6 +63,78 @@ function RunTestsByPath { } } +function Get-SystemDefaultPython { + Write-Host "Validate system Python..." + + if (Get-Command -Name 'python') + { + Write-Host "Python $(& python -V 2>&1) on path" + } + else + { + Write-Host "Python is not on path" + exit 1 + } + + $pythonBinVersion = $(& python -V 2>&1) + if ($pythonBinVersion -notlike "Python 3.*") + { + Write-Error "Python 3 is not in the PATH" + exit 1 + } + + $pythonBinOnPath = Split-Path -Path (Get-Command -Name 'python').Path + $description = GetDefaultToolDescription -SoftwareVersion $pythonBinVersion -SoftwareLocation $pythonBinOnPath + + return $description +} + +function Get-SystemDefaultRuby { + Write-Host "Validate system Ruby..." + + if (Get-Command -Name 'ruby') + { + Write-Host "$(ruby --version) is on the path." + } + else + { + Write-Host "Ruby is not on the path." + exit 1 + } + + $rubyBinOnPath = Split-Path -Path (Get-Command -Name 'ruby').Path + if ( $(ruby --version) -notmatch 'ruby (?.*) \(.*' ) + { + Write-Host "Unable to determine Ruby version at " + $rubyBinOnPath + exit 1 + + } + + $rubyVersionOnPath = "Ruby $($Matches.version)" + $description = GetDefaultToolDescription -SoftwareVersion $rubyVersionOnPath -SoftwareLocation $rubyBinOnPath + + $gemVersion = & gem -v + $description += "* Gem Version: $gemVersion
" + + return $description +} + +function GetDefaultToolDescription { + param ( + [Parameter(Mandatory = $True)] + [string]$SoftwareVersion, + [Parameter(Mandatory = $True)] + [string]$SoftwareLocation + ) + + $description = "
__System default version:__ $SoftwareVersion
" + $description += "_Environment:_
" + $description += "* Location: $SoftwareLocation
" + $description += "* PATH: contains the location of $SoftwareVersion
" + + return $description +} + function GetMarkdownDescription { param ( [Parameter(Mandatory = $True)] @@ -123,6 +195,14 @@ function ToolcacheTest { $markdownDescription += GetMarkdownDescription -SoftwareVersion $foundVersion -SoftwareArchitecture $requiredArchitecture } } + + if ($SoftwareName -contains "Python") { + $markdownDescription += Get-SystemDefaultPython + } + if ($SoftwareName -contains "Ruby") { + $markdownDescription += Get-SystemDefaultRuby + } + Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $markdownDescription } diff --git a/images/win/scripts/Installers/Windows2016/Install-Python.ps1 b/images/win/scripts/Installers/Windows2016/Install-Python.ps1 deleted file mode 100644 index f0a76ca92..000000000 --- a/images/win/scripts/Installers/Windows2016/Install-Python.ps1 +++ /dev/null @@ -1,28 +0,0 @@ -################################################################################ -## File: Install-Python.ps1 -## Desc: Configure python on path with 3.6.* version from the tools cache -## Must run after tools cache is setup -################################################################################ - -Import-Module -Name ImageHelpers -Force - -$python36path = $Env:AGENT_TOOLSDIRECTORY + '/Python/3.6*/x64' -$pythonDir = Get-Item -Path $python36path - -if($pythonDir -is [array]) -{ - Write-Host "More than one python 3.6.* installations found" - Write-Host $pythonDir - exit 1 -} - -$currentPath = Get-MachinePath - -if ($currentPath | Select-String -SimpleMatch $pythonDir.FullName) -{ - Write-Host $pythonDir.FullName ' is already in PATH' - exit 0 -} - -Add-MachinePathItem -PathItem $pythonDir.FullName -Add-MachinePathItem -PathItem "$($pythonDir.FullName)\Scripts" diff --git a/images/win/scripts/Installers/Windows2019/Install-Python.ps1 b/images/win/scripts/Installers/Windows2019/Install-Python.ps1 deleted file mode 100644 index 932ec197e..000000000 --- a/images/win/scripts/Installers/Windows2019/Install-Python.ps1 +++ /dev/null @@ -1,28 +0,0 @@ -################################################################################ -## File: Install-Python.ps1 -## Desc: Configure python on path with 3.7.* version from the tools cache -## Must run after tools cache is setup -################################################################################ - -Import-Module -Name ImageHelpers -Force - -$python37path = $Env:AGENT_TOOLSDIRECTORY + '/Python/3.7*/x64' -$pythonDir = Get-Item -Path $python37path - -if($pythonDir -is [array]) -{ - Write-Host "More than one python 3.7.* installations found" - Write-Host $pythonDir - exit 1 -} - -$currentPath = Get-MachinePath - -if ($currentPath | Select-String -SimpleMatch $pythonDir.FullName) -{ - Write-Host $pythonDir.FullName ' is already in PATH' - exit 0 -} - -Add-MachinePathItem -PathItem $pythonDir.FullName -Add-MachinePathItem -PathItem "$($pythonDir.FullName)\Scripts"