mirror of
https://github.com/actions/python-versions.git
synced 2025-04-08 00:09:39 +00:00
mplement script to build and prepare packages for Python
This commit is contained in:
80
helpers/common-helpers.psm1
Normal file
80
helpers/common-helpers.psm1
Normal file
@ -0,0 +1,80 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
The execute command and print all output to the logs
|
||||
#>
|
||||
function Execute-Command {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][string] $Command
|
||||
)
|
||||
|
||||
Write-Debug "Execute $Command"
|
||||
|
||||
try {
|
||||
Invoke-Expression $Command | ForEach-Object { Write-Host $_ }
|
||||
}
|
||||
catch {
|
||||
Write-Host "Error happened during command execution: $Command"
|
||||
Write-Host "##vso[task.logissue type=error;] $_"
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Download file from url and return local path to file
|
||||
#>
|
||||
function Download-File {
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[Uri]$Uri,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String]$OutputFolder
|
||||
)
|
||||
|
||||
$targetFilename = [IO.Path]::GetFileName($Uri)
|
||||
$targetFilepath = Join-Path $OutputFolder $targetFilename
|
||||
|
||||
Write-Debug "Download source from $Uri to $OutFile"
|
||||
try {
|
||||
(New-Object System.Net.WebClient).DownloadFile($Uri, $targetFilepath)
|
||||
return $targetFilepath
|
||||
} catch {
|
||||
Write-Host "Error during downloading file from '$Uri'"
|
||||
"$_"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Generate file that contains the list of all files in particular directory
|
||||
#>
|
||||
function New-ToolStructureDump {
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String]$ToolPath,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[String]$OutputFolder
|
||||
)
|
||||
|
||||
$outputFile = Join-Path $OutputFolder "tools_structure.txt"
|
||||
|
||||
$folderContent = Get-ChildItem -Path $ToolPath -Recurse | Sort-Object | Select-Object -Property FullName, Length
|
||||
$folderContent | ForEach-Object {
|
||||
$relativePath = $_.FullName.Replace($ToolPath, "");
|
||||
return "${relativePath}"
|
||||
} | Out-File -FilePath $outputFile
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Check if it is macOS / Ubuntu platform
|
||||
#>
|
||||
function IsNixPlatform {
|
||||
param(
|
||||
[Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()]
|
||||
[String]$Platform
|
||||
)
|
||||
|
||||
return ($Platform -match "macos") -or ($Platform -match "ubuntu")
|
||||
}
|
Reference in New Issue
Block a user