Fix documentation for Python and Ruby on Windows images (#478)

* Remove separate Python installation for Windows

* Remove Python2 symlink creation

* Move install-ruby and install-python to download-toolcache

* Improve download-toolcache for windows

* Small fix in docs for ruby

* V mapetr/test alt toolcache docs (#8)

* Merge Validate-Ruby and Validate-Python with Validate-Toolcache

* Small fix in output

* Small fix in download toolcache output
This commit is contained in:
Maksim Petrov
2020-03-12 14:53:17 +03:00
committed by GitHub
parent a3ecb363d7
commit 161e8c26fd
9 changed files with 115 additions and 232 deletions

View File

@@ -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":[

View File

@@ -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":[

View File

@@ -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"
Set-DefaultPythonVersion -Version "3.7"
Set-DefaultRubyVersion -Version "2.5"

View File

@@ -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

View File

@@ -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

View File

@@ -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 (?<version>.*) \(.*' )
{
$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

View File

@@ -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 (?<version>.*) \(.*' )
{
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<br/>"
return $description
}
function GetDefaultToolDescription {
param (
[Parameter(Mandatory = $True)]
[string]$SoftwareVersion,
[Parameter(Mandatory = $True)]
[string]$SoftwareLocation
)
$description = "<br/>__System default version:__ $SoftwareVersion<br/>"
$description += "_Environment:_<br/>"
$description += "* Location: $SoftwareLocation<br/>"
$description += "* PATH: contains the location of $SoftwareVersion<br/>"
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
}

View File

@@ -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"

View File

@@ -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"