mirror of
https://github.com/actions/runner-images.git
synced 2025-12-24 10:28:00 +08:00
[ubuntu] Refactor Common.Helpers (#8910)
* [ubuntu] Refactor Common.Helpers * Move Get-AndroidPackages function from BeforeAll * Fix ParameterBinding
This commit is contained in:
committed by
GitHub
parent
92e22bd8c6
commit
0c03739e50
@@ -1,16 +1,102 @@
|
||||
Describe "Android" {
|
||||
BeforeAll {
|
||||
function Test-AndroidPackage {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
This function tests existance of an Android package.
|
||||
|
||||
.DESCRIPTION
|
||||
The Test-AndroidPackage function is used to test an existance of Android package in ANDROID_HOME path.
|
||||
|
||||
.PARAMETER PackageName
|
||||
The name of the Android package to test.
|
||||
|
||||
.EXAMPLE
|
||||
Test-AndroidPackage
|
||||
|
||||
This command tests the Android package.
|
||||
|
||||
#>
|
||||
param (
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $PackageName
|
||||
)
|
||||
|
||||
# Convert 'cmake;3.6.4111459' -> 'cmake/3.6.4111459'
|
||||
$PackageName = $PackageName.Replace(";", "/")
|
||||
$targetPath = Join-Path $env:ANDROID_HOME $PackageName
|
||||
$targetPath | Should -Exist
|
||||
}
|
||||
}
|
||||
|
||||
function Get-AndroidPackages {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
This function returns a list of available Android packages.
|
||||
|
||||
.DESCRIPTION
|
||||
The Get-AndroidPackages function checks if a list of packages is already available in a file.
|
||||
If not, it uses the sdkmanager to generate a list of available packages and saves it to a file.
|
||||
It then returns the content of this file.
|
||||
|
||||
.PARAMETER SDKRootPath
|
||||
The root path of the Android SDK installation.
|
||||
If not specified, the function uses the ANDROID_HOME environment variable.
|
||||
|
||||
.EXAMPLE
|
||||
Get-AndroidPackages -SDKRootPath "/usr/local/lib/android/sdk"
|
||||
|
||||
This command returns a list of available Android packages for the specified SDK root path.
|
||||
|
||||
.NOTES
|
||||
This function requires the Android SDK to be installed.
|
||||
#>
|
||||
param (
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string] $SDKRootPath
|
||||
)
|
||||
|
||||
if (-not $SDKRootPath) {
|
||||
$SDKRootPath = $env:ANDROID_HOME
|
||||
}
|
||||
|
||||
$packagesListFile = "$SDKRootPath/packages-list.txt"
|
||||
|
||||
if (-not (Test-Path -Path $packagesListFile -PathType Leaf)) {
|
||||
(/usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --list --verbose 2>&1) |
|
||||
Where-Object { $_ -Match "^[^\s]" } |
|
||||
Where-Object { $_ -NotMatch "^(Loading |Info: Parsing |---|\[=+|Installed |Available )" } |
|
||||
Where-Object { $_ -NotMatch "^[^;]*$" } |
|
||||
Out-File -FilePath $packagesListFile
|
||||
|
||||
Write-Host "Android packages list:"
|
||||
Get-Content $packagesListFile
|
||||
}
|
||||
|
||||
return Get-Content $packagesListFile
|
||||
}
|
||||
|
||||
$androidSdkManagerPackages = Get-AndroidPackages
|
||||
[int]$platformMinVersion = Get-ToolsetValue "android.platform_min_version"
|
||||
[version]$buildToolsMinVersion = Get-ToolsetValue "android.build_tools_min_version"
|
||||
[array]$ndkVersions = Get-ToolsetValue "android.ndk.versions"
|
||||
$ndkFullVersions = $ndkVersions | ForEach-Object { (Get-ChildItem "/usr/local/lib/android/sdk/ndk/${_}.*" | Select-Object -Last 1).Name } | ForEach-Object { "ndk/${_}" }
|
||||
$ndkFullVersions = $ndkVersions |
|
||||
ForEach-Object { (Get-ChildItem "/usr/local/lib/android/sdk/ndk/${_}.*" |
|
||||
Select-Object -Last 1).Name } | ForEach-Object { "ndk/${_}" }
|
||||
# Platforms starting with a letter are the preview versions, which is not installed on the image
|
||||
$platformVersionsList = ($androidSdkManagerPackages | Where-Object { "$_".StartsWith("platforms;") }) -replace 'platforms;android-', '' | Where-Object { $_ -match "^\d" } | Sort-Object -Unique
|
||||
$platformsInstalled = $platformVersionsList | Where-Object { [int]($_.Split("-")[0]) -ge $platformMinVersion } | ForEach-Object { "platforms/android-${_}" }
|
||||
$platformVersionsList = ($androidSdkManagerPackages |
|
||||
Where-Object { "$_".StartsWith("platforms;") }) -replace 'platforms;android-', '' |
|
||||
Where-Object { $_ -match "^\d" } | Sort-Object -Unique
|
||||
$platformsInstalled = $platformVersionsList |
|
||||
Where-Object { [int]($_.Split("-")[0]) -ge $platformMinVersion } |
|
||||
ForEach-Object { "platforms/android-${_}" }
|
||||
|
||||
$buildToolsList = ($androidSdkManagerPackages | Where-Object { "$_".StartsWith("build-tools;") }) -replace 'build-tools;', ''
|
||||
$buildTools = $buildToolsList | Where-Object { $_ -match "\d+(\.\d+){2,}$"} | Where-Object { [version]$_ -ge $buildToolsMinVersion } | Sort-Object -Unique |
|
||||
ForEach-Object { "build-tools/${_}" }
|
||||
$buildTools = $buildToolsList |
|
||||
Where-Object { $_ -match "\d+(\.\d+){2,}$"} |
|
||||
Where-Object { [version]$_ -ge $buildToolsMinVersion } |
|
||||
Sort-Object -Unique |
|
||||
ForEach-Object { "build-tools/${_}" }
|
||||
|
||||
$androidPackages = @(
|
||||
$platformsInstalled,
|
||||
@@ -23,22 +109,6 @@ Describe "Android" {
|
||||
|
||||
$androidPackages = $androidPackages | ForEach-Object { $_ }
|
||||
|
||||
BeforeAll {
|
||||
function Validate-AndroidPackage {
|
||||
param (
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$PackageName
|
||||
)
|
||||
|
||||
# Convert 'm2repository;com;android;support;constraint;constraint-layout-solver;1.0.0-beta1' ->
|
||||
# 'm2repository/com/android/support/constraint/constraint-layout-solver/1.0.0-beta1'
|
||||
# 'cmake;3.6.4111459' -> 'cmake/3.6.4111459'
|
||||
$PackageName = $PackageName.Replace(";", "/")
|
||||
$targetPath = Join-Path $env:ANDROID_HOME $PackageName
|
||||
$targetPath | Should -Exist
|
||||
}
|
||||
}
|
||||
|
||||
Context "SDKManagers" {
|
||||
$testCases = @(
|
||||
@{
|
||||
@@ -61,7 +131,7 @@ Describe "Android" {
|
||||
|
||||
It "<PackageName>" -TestCases $testCases {
|
||||
param ([string] $PackageName)
|
||||
Validate-AndroidPackage $PackageName
|
||||
Test-AndroidPackage $PackageName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user