1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
# Helper functions for retireving useful information from azure-sdk-for-* repo
. "${PSScriptRoot}\logging.ps1"
class PackageProps
{
[string]$Name
[string]$Version
[string]$DirectoryPath
[string]$ServiceDirectory
[string]$ReadMePath
[string]$ChangeLogPath
[string]$Group
PackageProps([string]$name, [string]$version, [string]$directoryPath, [string]$serviceDirectory)
{
$this.Initialize($name, $version, $directoryPath, $serviceDirectory)
}
PackageProps([string]$name, [string]$version, [string]$directoryPath, [string]$serviceDirectory, [string]$group = "")
{
$this.Initialize($name, $version, $directoryPath, $serviceDirectory, $group)
}
hidden [void]Initialize(
[string]$name,
[string]$version,
[string]$directoryPath,
[string]$serviceDirectory
)
{
$this.Name = $name
$this.Version = $version
$this.DirectoryPath = $directoryPath
$this.ServiceDirectory = $serviceDirectory
if (Test-Path (Join-Path $directoryPath "README.md"))
{
$this.ReadMePath = Join-Path $directoryPath "README.md"
}
else
{
$this.ReadMePath = $null
}
if (Test-Path (Join-Path $directoryPath "CHANGELOG.md"))
{
$this.ChangeLogPath = Join-Path $directoryPath "CHANGELOG.md"
}
else
{
$this.ChangeLogPath = $null
}
}
hidden [void]Initialize(
[string]$name,
[string]$version,
[string]$directoryPath,
[string]$serviceDirectory,
[string]$group
)
{
$this.Initialize($name, $version, $directoryPath, $serviceDirectory)
$this.Group = $group
}
}
# Takes package name and service Name
# Returns important properties of the package as related to the language repo
# Returns a PS Object with properties @ { pkgName, pkgVersion, pkgDirectoryPath, pkgReadMePath, pkgChangeLogPath }
# Note: python is required for parsing python package properties.
function Get-PkgProperties
{
Param
(
[Parameter(Mandatory = $true)]
[string]$PackageName,
[Parameter(Mandatory = $true)]
[string]$ServiceDirectory
)
$pkgDirectoryPath = $null
$serviceDirectoryPath = Join-Path $RepoRoot "sdk" $ServiceDirectory
if (!(Test-Path $serviceDirectoryPath))
{
LogError "Service Directory $ServiceDirectory does not exist"
exit 1
}
$directoriesPresent = Get-ChildItem $serviceDirectoryPath -Directory
foreach ($directory in $directoriesPresent)
{
$pkgDirectoryPath = Join-Path $serviceDirectoryPath $directory.Name
if ($GetPackageInfoFromRepoFn -and (Test-Path "Function:$GetPackageInfoFromRepoFn"))
{
$pkgProps = &$GetPackageInfoFromRepoFn -pkgPath $pkgDirectoryPath -serviceDirectory $ServiceDirectory -pkgName $PackageName
}
else
{
LogError "The function '$GetPackageInfoFromRepoFn' was not found."
}
if ($pkgProps -ne $null)
{
return $pkgProps
}
}
LogError "Failed to retrive Properties for $PackageName"
}
# Takes ServiceName and Repo Root Directory
# Returns important properties for each package in the specified service, or entire repo if the serviceName is not specified
# Returns an Table of service key to array values of PS Object with properties @ { pkgName, pkgVersion, pkgDirectoryPath, pkgReadMePath, pkgChangeLogPath }
function Get-AllPkgProperties ([string]$ServiceDirectory = $null)
{
$pkgPropsResult = @()
if ([string]::IsNullOrEmpty($ServiceDirectory))
{
$searchDir = Join-Path $RepoRoot "sdk"
foreach ($dir in (Get-ChildItem $searchDir -Directory))
{
$serviceDir = Join-Path $searchDir $dir.Name
if (Test-Path (Join-Path $serviceDir "ci.yml"))
{
$activePkgList = Get-PkgListFromYml -ciYmlPath (Join-Path $serviceDir "ci.yml")
if ($activePkgList -ne $null)
{
$pkgPropsResult = Operate-OnPackages -activePkgList $activePkgList -ServiceDirectory $dir.Name -pkgPropsResult $pkgPropsResult
}
}
}
}
else
{
$serviceDir = Join-Path $RepoRoot "sdk" $ServiceDirectory
if (Test-Path (Join-Path $serviceDir "ci.yml"))
{
$activePkgList = Get-PkgListFromYml -ciYmlPath (Join-Path $serviceDir "ci.yml")
if ($activePkgList -ne $null)
{
$pkgPropsResult = Operate-OnPackages -activePkgList $activePkgList -ServiceDirectory $ServiceDirectory -pkgPropsResult $pkgPropsResult
}
}
}
return $pkgPropsResult
}
function Operate-OnPackages ($activePkgList, $ServiceDirectory, [Array]$pkgPropsResult)
{
foreach ($pkg in $activePkgList)
{
$pkgProps = Get-PkgProperties -PackageName $pkg["name"] -ServiceDirectory $ServiceDirectory
$pkgPropsResult += $pkgProps
}
return $pkgPropsResult
}
function Get-PkgListFromYml ($ciYmlPath)
{
$ProgressPreference = "SilentlyContinue"
Register-PSRepository -Default -ErrorAction:SilentlyContinue
Install-Module -Name powershell-yaml -RequiredVersion 0.4.1 -Force -Scope CurrentUser
$ciYmlContent = Get-Content $ciYmlPath -Raw
$ciYmlObj = ConvertFrom-Yaml $ciYmlContent -Ordered
if ($ciYmlObj.Contains("stages"))
{
$artifactsInCI = $ciYmlObj["stages"][0]["parameters"]["Artifacts"]
}
elseif ($ciYmlObj.Contains("extends"))
{
$artifactsInCI = $ciYmlObj["extends"]["parameters"]["Artifacts"]
}
if ($artifactsInCI -eq $null)
{
LogError "Failed to retrive package names in ci $ciYmlPath"
}
return $artifactsInCI
}
|