split setup files for Windows / Nix; fix links in cotributing.md; add security.md

This commit is contained in:
Maxim Lobanov 2020-04-14 09:39:04 +03:00
parent 4ea482db2f
commit 6bda58c1bc
12 changed files with 168 additions and 82 deletions

View File

@ -1,9 +1,7 @@
## Contributing
TO-DO: Fix the links after moving to final repository
[fork]: https://github.com/actions/virtual-environments/fork
[pr]: https://github.com//actions/virtual-environments/compare
[fork]: https://github.com/actions/python-versions/fork
[pr]: https://github.com/actions/python-versions/compare
[code-of-conduct]: CODE_OF_CONDUCT.md
Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.

3
SECURITY.md Normal file
View File

@ -0,0 +1,3 @@
If you discover a security issue in this repo, please submit it through the [GitHub Security Bug Bounty](https://hackerone.com/github)
Thanks for helping make GitHub Actions safe for everyone.

View File

@ -15,7 +15,8 @@ steps:
displayName: 'Apply build artifact to the local machines'
inputs:
TargetType: inline
script: './setup.ps1'
script: |
if ($env:PLATFORM -match 'windows') { powershell ./setup.ps1 } else { sh ./setup.sh }
workingDirectory: '$(Build.BinariesDirectory)'
- task: UsePythonVersion@0

View File

@ -20,6 +20,9 @@ class NixPythonBuilder : PythonBuilder {
.PARAMETER InstallationTemplateName
The name of template that will be used to create installation script for generated Python artifact.
.PARAMETER InstallationScriptName
The name of installation script that will be generated for Python artifact.
.PARAMETER OutputArtifactName
The name of archive with Python binaries that will be generated as part of Python artifact.
@ -28,6 +31,7 @@ class NixPythonBuilder : PythonBuilder {
[string] $Platform
[string] $PlatformVersion
[string] $InstallationTemplateName
[string] $InstallationScriptName
[string] $OutputArtifactName
NixPythonBuilder(
@ -36,7 +40,8 @@ class NixPythonBuilder : PythonBuilder {
) : Base($version, "x64") {
$this.Platform = $platform.Split("-")[0]
$this.PlatformVersion = $platform.Split("-")[1]
$this.InstallationTemplateName = "nix-setup-template.ps1"
$this.InstallationTemplateName = "nix-setup-template.sh"
$this.InstallationScriptName = "setup.sh"
$this.OutputArtifactName = "tool.zip"
}
@ -101,16 +106,13 @@ class NixPythonBuilder : PythonBuilder {
Create Python artifact installation script based on template specified in InstallationTemplateName property.
#>
$installationTemplateLocation = Join-Path -Path $this.InstallationTemplatesLocation -ChildPath $this.InstallationTemplateName
$installationTemplateContent = Get-Content -Path $installationTemplateLocation -Raw
$installationScriptLocation = New-Item -Path $this.ArtifactLocation -Name $this.InstallationScriptName -ItemType File
$installationTemplateLocation = Join-Path -Path $this.InstallationTemplatesLocation -ChildPath $this.InstallationTemplateName
$variablesToReplace = @{
"{{__VERSION__}}" = $this.Version;
}
$variablesToReplace.keys | ForEach-Object { $installationTemplateContent = $installationTemplateContent.Replace($_, $variablesToReplace[$_]) }
$installationTemplateContent = Get-Content -Path $installationTemplateLocation -Raw
$installationTemplateContent = $installationTemplateContent -f $this.Version.Major, $this.Version.Minor, $this.Version.Build
$installationTemplateContent | Out-File -FilePath $installationScriptLocation
Write-Debug "Done; Installation script location: $installationScriptLocation)"
}

View File

@ -24,9 +24,6 @@ class PythonBuilder {
.PARAMETER InstallationTemplatesLocation
The location of installation script template. Using "installers" folder from current repository.
.PARAMETER InstallationScriptName
The name of installation script that will be generated for Python artifact.
#>
[version] $Version
@ -35,7 +32,6 @@ class PythonBuilder {
[string] $TempFolderLocation
[string] $ArtifactLocation
[string] $InstallationTemplatesLocation
[string] $InstallationScriptName
PythonBuilder ([version] $version, [string] $architecture) {
$this.Version = $version
@ -46,7 +42,6 @@ class PythonBuilder {
$this.ArtifactLocation = $env:BUILD_BINARIESDIRECTORY
$this.InstallationTemplatesLocation = Join-Path -Path $PSScriptRoot -ChildPath "../installers"
$this.InstallationScriptName = "setup.ps1"
}
[uri] GetBaseUri() {

View File

@ -17,15 +17,20 @@ class WinPythonBuilder : PythonBuilder {
.PARAMETER InstallationTemplateName
The name of installation script template that will be used in generated artifact.
.PARAMETER InstallationScriptName
The name of generated installation script.
#>
[string] $InstallationTemplateName
[string] $InstallationScriptName
WinPythonBuilder(
[version] $version,
[string] $architecture
) : Base($version, $architecture) {
$this.InstallationTemplateName = "win-setup-template.ps1"
$this.InstallationScriptName = "setup.ps1"
}
[string] GetPythonExtension() {

View File

@ -39,8 +39,9 @@ function Download-File {
(New-Object System.Net.WebClient).DownloadFile($Uri, $targetFilepath)
return $targetFilepath
} catch {
Write-Host "Error during downloading file from '$Uri'"
"$_"
break
exit 1
}
}

View File

@ -12,33 +12,85 @@ Optional parameter. The name of tool repository
Required parameter. PAT Token to overcome GitHub API Rate limit
.PARAMETER OutputFile
Required parameter. File "*.json" where generated results will be saved
.PARAMETER PlatformMapFile
Optional parameter. Path to the json file with platform map
Structure example:
{
"macos-1014": [
{
"platform": "darwin",
"platform_version": "10.14"
}, ...
], ...
}
#>
param (
[Parameter(Mandatory)] [string] $GitHubRepositoryOwner,
[Parameter(Mandatory)] [string] $GitHubRepositoryName,
[Parameter(Mandatory)] [string] $GitHubAccessToken,
[Parameter(Mandatory)] [string] $OutputFile
[Parameter(Mandatory)] [string] $OutputFile,
[string] $PlatformMapFile
)
Import-Module (Join-Path $PSScriptRoot "github-api.psm1")
if ($PlatformMapFile -and (Test-Path $PlatformMapFile)) {
$PlatformMap = Get-Content $PlatformMapFile -Raw | ConvertFrom-Json -AsHashtable
} else {
$PlatformMap = @{}
}
function New-AssetItem {
param (
[Parameter(Mandatory)][string]$Filename,
[Parameter(Mandatory)][string]$DownloadUrl,
[Parameter(Mandatory)][string]$Arch,
[Parameter(Mandatory)][string]$Platform,
[string]$PlatformVersion
)
$asset = New-Object PSObject
$asset | Add-Member -Name "filename" -Value $Filename -MemberType NoteProperty
$asset | Add-Member -Name "arch" -Value $Arch -MemberType NoteProperty
$asset | Add-Member -Name "platform" -Value $Platform -MemberType NoteProperty
if ($PlatformVersion) { $asset | Add-Member -Name "platform_version" -Value $PlatformVersion -MemberType NoteProperty }
$asset | Add-Member -Name "download_url" -Value $DownloadUrl -MemberType NoteProperty
return $asset
}
function Build-AssetsList {
param (
[AllowEmptyCollection()]
[Parameter(Mandatory)][array]$ReleaseAssets
)
return $ReleaseAssets | ForEach-Object {
$parts = [IO.path]::GetFileNameWithoutExtension($_.name).Split("-")
$assets = @()
foreach($releaseAsset in $ReleaseAssets) {
$parts = [IO.path]::GetFileNameWithoutExtension($releaseAsset.name).Split("-")
$arch = $parts[-1]
$buildPlatform = [string]::Join("-", $parts[2..($parts.Length-2)])
return [PSCustomObject]@{
filename = $_.name
arch = $parts[-1]
platform = [string]::Join("-", $parts[2..($parts.Length-2)])
download_url = $_.browser_download_url
if ($PlatformMap[$buildPlatform]) {
$PlatformMap[$buildPlatform] | ForEach-Object {
$assets += New-AssetItem -Filename $releaseAsset.name `
-DownloadUrl $releaseAsset.browser_download_url `
-Arch $arch `
-Platform $_.platform `
-PlatformVersion $_.platform_version
}
} else {
$assets += New-AssetItem -Filename $releaseAsset.name `
-DownloadUrl $releaseAsset.browser_download_url `
-Arch $arch `
-Platform $buildPlatform
}
}
return $assets
}
function Get-VersionFromRelease {
@ -84,7 +136,7 @@ function Build-VersionsManifest {
}
# Sort versions by descending
return $versionsHash.Values | Sort-Object -Property "version" -Descending
return $versionsHash.Values | Sort-Object -Property @{ Expression = { [Version]$_.version }; Descending = $true }
}
$gitHubApi = Get-GitHubApi -AccountName $GitHubRepositoryOwner -ProjectName $GitHubRepositoryName -AccessToken $GitHubAccessToken

View File

@ -0,0 +1,29 @@
{
"macos-1014": [
{
"platform": "darwin",
"platform_version": "10.14"
},
{
"platform": "darwin",
"platform_version": "10.15"
}
],
"ubuntu-1604": [
{
"platform": "linux",
"platform_version": "16.04"
}
],
"ubuntu-1804": [
{
"platform": "linux",
"platform_version": "18.04"
}
],
"windows-2016": [
{
"platform": "win32"
}
]
}

View File

@ -1,54 +0,0 @@
[Version]$Version = "{{__VERSION__}}"
$PythonToolcachePath = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath "Python"
$PythonVersionPath = Join-Path -Path $PythonToolcachePath -ChildPath $Version.ToString()
$PythonArchPath = Join-Path -Path $PythonVersionPath -ChildPath "x64"
$ToolArchiveName = "tool.zip"
$PythonMajorBinary = "python$($Version.Major)"
$PythonMajorDotMinorBinary = "python$($Version.Major).$($Version.Minor)"
Write-Host "Check if Python hostedtoolcache folder exist..."
if (-Not (Test-Path $PythonToolcachePath)) {
Write-Host "Create Python toolcache folder"
New-Item -ItemType Directory -Path $PythonToolcachePath | Out-Null
} else {
Write-Host "Check if current Python version is installed..."
if (Test-Path -Path $PythonVersionPath) {
Write-Host "Python$Version was found in $PythonToolcachePath"
Write-Host "Delete Python$Version..."
Remove-Item -Path $PythonVersionPath -Recurse -Force | Out-Null
} else {
Write-Host "No Python$Version found"
}
}
Write-Host "Create Python $Version folder in $PythonToolcachePath"
New-Item -ItemType Directory -Path $PythonArchPath -Force | Out-Null
Write-Host "Copy Python binaries to hostedtoolcache folder"
Copy-Item -Path $ToolArchiveName -Destination $PythonArchPath | Out-Null
Set-Location -Path $PythonArchPath
Write-Host "Unzip python to $PythonArchPath"
Expand-Archive -Path $ToolArchiveName -Destination "."
Write-Host "Remove temporary files..."
Remove-Item -Path $ToolArchiveName | Out-Null
Write-Host "Create additional symlinks"
ln -s ./bin/$PythonMajorDotMinorBinary python
Set-Location -Path "./bin"
if (-not (Test-Path "./python")) {
ln -s $PythonMajorDotMinorBinary python
}
chmod +x ../python $PythonMajorBinary $PythonMajorDotMinorBinary python
Write-Host "Upgrading PIP..."
./python -m ensurepip
./python -m pip install --ignore-installed pip
Write-Host "Create complete file"
New-Item -ItemType File -Path $PythonVersionPath -Name "x64.complete" | Out-Null

View File

@ -0,0 +1,54 @@
set -e
MAJOR_VERSION={0}
MINOR_VERSION={1}
BUILD_VERSION={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
PYTHON_TOOLCACHE_PATH=$AGENT_TOOLSDIRECTORY/Python
PYTHON_TOOLCACHE_VERSION_PATH=$PYTHON_TOOLCACHE_PATH/$PYTHON_FULL_VERSION
PYTHON_TOOLCACHE_VERSION_ARCH_PATH=$PYTHON_TOOLCACHE_VERSION_PATH/x64
echo "Check if Python hostedtoolcache folder exist..."
if [ ! -d $PYTHON_TOOLCACHE_PATH ]; then
echo "Creating Python hostedtoolcache folder..."
mkdir -p $PYTHON_TOOLCACHE_PATH
elif [ -d $PYTHON_TOOLCACHE_VERSION_PATH ]; then
echo "Deleting Python $PYTHON_FULL_VERSION"
rm -rf $PYTHON_TOOLCACHE_VERSION_PATH
fi
echo "Create Python $PYTHON_FULL_VERSION folder"
mkdir -p $PYTHON_TOOLCACHE_VERSION_ARCH_PATH
echo "Copy Python binaries to hostedtoolcache folder"
cp ./tool.zip $PYTHON_TOOLCACHE_VERSION_ARCH_PATH
cd $PYTHON_TOOLCACHE_VERSION_ARCH_PATH
echo "Unzip python to $PYTHON_TOOLCACHE_VERSION_PATH"
unzip -q tool.zip
echo "Python unzipped successfully"
rm tool.zip
echo "Create additional symlinks (Required for UsePythonVersion VSTS task)"
ln -s ./bin/$PYTHON_MAJOR_DOT_MINOR python
cd bin/
ln -s $PYTHON_MAJOR_DOT_MINOR $PYTHON_MAJORMINOR
if [ ! -f python ]; then
ln -s $PYTHON_MAJOR_DOT_MINOR python
fi
chmod +x ../python $PYTHON_MAJOR $PYTHON_MAJOR_DOT_MINOR $PYTHON_MAJORMINOR python
echo "Upgrading PIP..."
./python -m ensurepip
./python -m pip install --ignore-installed pip
echo "Create complete file"
touch $PYTHON_TOOLCACHE_VERSION_PATH/x64.complete