Get default python and relenv versions from CICD

This commit is contained in:
twangboy 2023-08-29 16:47:30 -06:00 committed by Gareth J. Greenaway
parent 7c82945cb8
commit 2d5584a309
2 changed files with 72 additions and 13 deletions

View file

@ -39,11 +39,14 @@ param(
[Parameter(Mandatory=$false)]
[ValidatePattern("^\d{1,2}.\d{1,2}.\d{1,2}$")]
[Alias("p")]
[String] $PythonVersion = "3.10.12",
# The version of Python to build/fetch. This is tied to the version of
# Relenv
[String] $PythonVersion,
[Parameter(Mandatory=$false)]
[Alias("r")]
[String] $RelenvVersion = "0.13.4",
# The version of Relenv to install
[String] $RelenvVersion,
[Parameter(Mandatory=$false)]
[Alias("b")]
@ -57,7 +60,7 @@ param(
[Switch] $CICD,
[Parameter(Mandatory=$false)]
# Don't install. It should already be installed
# Don't install/build python. It should already be installed
[Switch] $SkipInstall
)
@ -98,6 +101,33 @@ if ( [String]::IsNullOrEmpty($Version) ) {
}
}
#-------------------------------------------------------------------------------
# Verify Python and Relenv Versions
#-------------------------------------------------------------------------------
$yaml = Get-Content -Path "$PROJECT_DIR\cicd\shared-gh-workflows-context.yml"
$dict_versions = @{}
$yaml | ForEach-Object {
$val1, $val2 = $_ -split ": "
$dict_versions[$val1] = $val2.Trim("""")
}
if ( [String]::IsNullOrEmpty($PythonVersion) ) {
$PythonVersion = $dict_versions["python_version"]
if ( [String]::IsNullOrEmpty($PythonVersion) ) {
Write-Host "Failed to load Python Version"
exit 1
}
}
if ( [String]::IsNullOrEmpty($RelenvVersion) ) {
$RelenvVersion = $dict_versions["relenv_version"]
if ( [String]::IsNullOrEmpty($RelenvVersion) ) {
Write-Host "Failed to load Relenv Version"
exit 1
}
}
#-------------------------------------------------------------------------------
# Start the Script
#-------------------------------------------------------------------------------

View file

@ -18,11 +18,14 @@ param(
[Parameter(Mandatory=$false)]
[ValidatePattern("^\d{1,2}.\d{1,2}.\d{1,2}$")]
[Alias("v")]
[String] $Version = "3.10.12",
# The version of python to build/fetch. This is tied to the version of
# Relenv
[String] $Version,
[Parameter(Mandatory=$false)]
[Alias("r")]
[String] $RelenvVersion = "0.13.4",
# The version of Relenv to install
[String] $RelenvVersion,
[Parameter(Mandatory=$false)]
[ValidateSet("x64", "x86", "amd64")]
@ -68,6 +71,33 @@ function Write-Result($result, $ForegroundColor="Green") {
Write-Host -ForegroundColor $ForegroundColor ("{0,$position}$result" -f "")
}}
#-------------------------------------------------------------------------------
# Verify Python and Relenv Versions
#-------------------------------------------------------------------------------
$yaml = Get-Content -Path "$PROJECT_DIR\cicd\shared-gh-workflows-context.yml"
$dict_versions = @{}
$yaml | ForEach-Object {
$val1, $val2 = $_ -split ": "
$dict_versions[$val1] = $val2.Trim("""")
}
if ( [String]::IsNullOrEmpty($Version) ) {
$Version = $dict_versions["python_version"]
if ( [String]::IsNullOrEmpty($Version) ) {
Write-Host "Failed to load Python Version"
exit 1
}
}
if ( [String]::IsNullOrEmpty($RelenvVersion) ) {
$RelenvVersion = $dict_versions["relenv_version"]
if ( [String]::IsNullOrEmpty($RelenvVersion) ) {
Write-Host "Failed to load Relenv Version"
exit 1
}
}
#-------------------------------------------------------------------------------
# Start the Script
#-------------------------------------------------------------------------------
@ -145,7 +175,6 @@ if ( $env:VIRTUAL_ENV ) {
#-------------------------------------------------------------------------------
$SCRIPT_DIR = (Get-ChildItem "$($myInvocation.MyCommand.Definition)").DirectoryName
$BUILD_DIR = "$SCRIPT_DIR\buildenv"
$SCRIPTS_DIR = "$BUILD_DIR\Scripts"
$RELENV_DIR = "${env:LOCALAPPDATA}\relenv"
$SYS_PY_BIN = (python -c "import sys; print(sys.executable)")
$BLD_PY_BIN = "$BUILD_DIR\Scripts\python.exe"
@ -238,16 +267,16 @@ $env:RELENV_FETCH_VERSION=$RelenvVersion
#-------------------------------------------------------------------------------
if ( $Build ) {
Write-Host "Building Python with Relenv (long-running): " -NoNewLine
$output = relenv build --clean --arch $ARCH
$output = relenv build --clean --python $Version --arch $ARCH
} else {
Write-Host "Fetching Python with Relenv: " -NoNewLine
relenv fetch --python $Version --arch $ARCH | Out-Null
}
if ( Test-Path -Path "$RELENV_DIR\build\$Version-$ARCH-win.tar.xz") {
Write-Result "Success" -ForegroundColor Green
} else {
Write-Result "Failed" -ForegroundColor Red
exit 1
if ( Test-Path -Path "$RELENV_DIR\build\$Version-$ARCH-win.tar.xz") {
Write-Result "Success" -ForegroundColor Green
} else {
Write-Result "Failed" -ForegroundColor Red
exit 1
}
}
#-------------------------------------------------------------------------------