mirror of
https://github.com/actions/python-versions.git
synced 2025-04-06 23:39:38 +00:00
Add support for unstable Python versions (#38)
* Add support of unstable versions to package generation (#2) * Add support of symver versions to Python setup scripts and tests Co-authored-by: Maksim Petrov <47208721+vmapetr@users.noreply.github.com> Co-authored-by: MaksimZhukov <v-mazhuk@microsoft.com> Co-authored-by: Maxim Lobanov <v-malob@microsoft.com>
This commit is contained in:
@ -1,13 +1,12 @@
|
||||
set -e
|
||||
|
||||
MAJOR_VERSION="{{__VERSION_MAJOR__}}"
|
||||
MINOR_VERSION="{{__VERSION_MINOR__}}"
|
||||
BUILD_VERSION="{{__VERSION_BUILD__}}"
|
||||
PYTHON_FULL_VERSION="{{__VERSION_FULL__}}"
|
||||
MAJOR_VERSION=$(echo $PYTHON_FULL_VERSION | cut -d '.' -f 1)
|
||||
MINOR_VERSION=$(echo $PYTHON_FULL_VERSION | cut -d '.' -f 2)
|
||||
|
||||
PYTHON_MAJOR=python$MAJOR_VERSION
|
||||
PYTHON_MAJOR_DOT_MINOR=python$MAJOR_VERSION.$MINOR_VERSION
|
||||
PYTHON_MAJORMINOR=python$MAJOR_VERSION$MINOR_VERSION
|
||||
PYTHON_FULL_VERSION=$MAJOR_VERSION.$MINOR_VERSION.$BUILD_VERSION
|
||||
|
||||
if [ -z ${AGENT_TOOLSDIRECTORY+x} ]; then
|
||||
# No AGENT_TOOLSDIRECTORY on GitHub images
|
||||
|
@ -1,10 +1,9 @@
|
||||
[String] $Architecture = "{{__ARCHITECTURE__}}"
|
||||
[Version] $Version = "{{__VERSION__}}"
|
||||
[String] $Version = "{{__VERSION__}}"
|
||||
[String] $PythonExecName = "{{__PYTHON_EXEC_NAME__}}"
|
||||
|
||||
function Get-RegistryVersionFilter {
|
||||
param
|
||||
(
|
||||
param(
|
||||
[Parameter(Mandatory)][String] $Architecture,
|
||||
[Parameter(Mandatory)][Int32] $MajorVersion,
|
||||
[Parameter(Mandatory)][Int32] $MinorVersion
|
||||
@ -12,20 +11,15 @@ function Get-RegistryVersionFilter {
|
||||
|
||||
$archFilter = if ($Architecture -eq 'x86') { "32-bit" } else { "64-bit" }
|
||||
### Python 2.7 x86 have no architecture postfix
|
||||
if (($Architecture -eq "x86") -and ($MajorVersion -eq 2))
|
||||
{
|
||||
if (($Architecture -eq "x86") -and ($MajorVersion -eq 2)) {
|
||||
"Python $MajorVersion.$MinorVersion.\d+$"
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
"Python $MajorVersion.$MinorVersion.*($archFilter)"
|
||||
}
|
||||
}
|
||||
|
||||
function Remove-RegistryEntries
|
||||
{
|
||||
param
|
||||
(
|
||||
function Remove-RegistryEntries {
|
||||
param(
|
||||
[Parameter(Mandatory)][String] $Architecture,
|
||||
[Parameter(Mandatory)][Int32] $MajorVersion,
|
||||
[Parameter(Mandatory)][Int32] $MinorVersion
|
||||
@ -35,10 +29,8 @@ function Remove-RegistryEntries
|
||||
|
||||
$regPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
|
||||
$regKeys = Get-ChildItem -Path Registry::$regPath -Recurse | Where-Object Property -Ccontains DisplayName
|
||||
foreach ($key in $regKeys)
|
||||
{
|
||||
if ($key.getValue("DisplayName") -match $versionFilter)
|
||||
{
|
||||
foreach ($key in $regKeys) {
|
||||
if ($key.getValue("DisplayName") -match $versionFilter) {
|
||||
Remove-Item -Path $key.PSParentPath -Recurse -Force -Verbose
|
||||
}
|
||||
}
|
||||
@ -63,40 +55,34 @@ function Remove-RegistryEntries
|
||||
}
|
||||
|
||||
function Get-ExecParams {
|
||||
param
|
||||
(
|
||||
param(
|
||||
[Parameter(Mandatory)][Boolean] $IsMSI,
|
||||
[Parameter(Mandatory)][String] $PythonArchPath
|
||||
)
|
||||
|
||||
if ($IsMSI)
|
||||
{
|
||||
if ($IsMSI) {
|
||||
"TARGETDIR=$PythonArchPath ALLUSERS=1"
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
"DefaultAllUsersTargetDir=$PythonArchPath InstallAllUsers=1"
|
||||
}
|
||||
}
|
||||
|
||||
$ToolcacheRoot = $env:AGENT_TOOLSDIRECTORY
|
||||
if ([string]::IsNullOrEmpty($ToolcacheRoot))
|
||||
{
|
||||
if ([string]::IsNullOrEmpty($ToolcacheRoot)) {
|
||||
# GitHub images don't have `AGENT_TOOLSDIRECTORY` variable
|
||||
$ToolcacheRoot = $env:RUNNER_TOOL_CACHE
|
||||
}
|
||||
$PythonToolcachePath = Join-Path -Path $ToolcacheRoot -ChildPath "Python"
|
||||
$PythonVersionPath = Join-Path -Path $PythonToolcachePath -ChildPath $Version.ToString()
|
||||
$PythonVersionPath = Join-Path -Path $PythonToolcachePath -ChildPath $Version
|
||||
$PythonArchPath = Join-Path -Path $PythonVersionPath -ChildPath $Architecture
|
||||
|
||||
$IsMSI = $PythonExecName -match "msi"
|
||||
|
||||
$MajorVersion = $Version.Major
|
||||
$MinorVersion = $Version.Minor
|
||||
$MajorVersion = $Version.Split('.')[0]
|
||||
$MinorVersion = $Version.Split('.')[1]
|
||||
|
||||
Write-Host "Check if Python hostedtoolcache folder exist..."
|
||||
if (-Not (Test-Path $PythonToolcachePath))
|
||||
{
|
||||
if (-Not (Test-Path $PythonToolcachePath)) {
|
||||
Write-Host "Create Python toolcache folder"
|
||||
New-Item -ItemType Directory -Path $PythonToolcachePath | Out-Null
|
||||
}
|
||||
@ -104,22 +90,17 @@ if (-Not (Test-Path $PythonToolcachePath))
|
||||
Write-Host "Check if current Python version is installed..."
|
||||
$InstalledVersions = Get-Item "$PythonToolcachePath\$MajorVersion.$MinorVersion.*\$Architecture"
|
||||
|
||||
if ($null -ne $InstalledVersions)
|
||||
{
|
||||
if ($null -ne $InstalledVersions) {
|
||||
Write-Host "Python$MajorVersion.$MinorVersion ($Architecture) was found in $PythonToolcachePath..."
|
||||
|
||||
foreach ($InstalledVersion in $InstalledVersions)
|
||||
{
|
||||
if (Test-Path -Path $InstalledVersion)
|
||||
{
|
||||
foreach ($InstalledVersion in $InstalledVersions) {
|
||||
if (Test-Path -Path $InstalledVersion) {
|
||||
Write-Host "Deleting $InstalledVersion..."
|
||||
Remove-Item -Path $InstalledVersion -Recurse -Force
|
||||
Remove-Item -Path "$($InstalledVersion.Parent.FullName)/${Architecture}.complete" -Force -Verbose
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Write-Host "No Python$MajorVersion.$MinorVersion.* found"
|
||||
}
|
||||
|
||||
@ -136,8 +117,7 @@ Write-Host "Install Python $Version in $PythonToolcachePath..."
|
||||
$ExecParams = Get-ExecParams -IsMSI $IsMSI -PythonArchPath $PythonArchPath
|
||||
|
||||
cmd.exe /c "cd $PythonArchPath && call $PythonExecName $ExecParams /quiet"
|
||||
if ($LASTEXITCODE -ne 0)
|
||||
{
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Throw "Error happened during Python installation"
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user