...

Text file src/github.com/Azure/azure-sdk-for-go/eng/common/scripts/Package-Properties.ps1

Documentation: github.com/Azure/azure-sdk-for-go/eng/common/scripts

     1# Helper functions for retireving useful information from azure-sdk-for-* repo
     2. "${PSScriptRoot}\logging.ps1"
     3
     4class PackageProps
     5{
     6    [string]$Name
     7    [string]$Version
     8    [string]$DevVersion
     9    [string]$DirectoryPath
    10    [string]$ServiceDirectory
    11    [string]$ReadMePath
    12    [string]$ChangeLogPath
    13    [string]$Group
    14    [string]$SdkType
    15    [boolean]$IsNewSdk
    16    [string]$ArtifactName
    17    [string]$ReleaseStatus
    18
    19    PackageProps([string]$name, [string]$version, [string]$directoryPath, [string]$serviceDirectory)
    20    {
    21        $this.Initialize($name, $version, $directoryPath, $serviceDirectory)
    22    }
    23
    24    PackageProps([string]$name, [string]$version, [string]$directoryPath, [string]$serviceDirectory, [string]$group = "")
    25    {
    26        $this.Initialize($name, $version, $directoryPath, $serviceDirectory, $group)
    27    }
    28
    29    hidden [void]Initialize(
    30        [string]$name,
    31        [string]$version,
    32        [string]$directoryPath,
    33        [string]$serviceDirectory
    34    )
    35    {
    36        $this.Name = $name
    37        $this.Version = $version
    38        $this.DirectoryPath = $directoryPath
    39        $this.ServiceDirectory = $serviceDirectory
    40
    41        if (Test-Path (Join-Path $directoryPath "README.md"))
    42        {
    43            $this.ReadMePath = Join-Path $directoryPath "README.md"
    44        }
    45        else
    46        {
    47            $this.ReadMePath = $null
    48        }
    49
    50        if (Test-Path (Join-Path $directoryPath "CHANGELOG.md"))
    51        {
    52            $this.ChangeLogPath = Join-Path $directoryPath "CHANGELOG.md"
    53            # Get release date for current version and set in package property
    54            $changeLogEntry = Get-ChangeLogEntry -ChangeLogLocation $this.ChangeLogPath -VersionString $this.Version
    55            if ($changeLogEntry -and $changeLogEntry.ReleaseStatus)
    56            {
    57              $this.ReleaseStatus = $changeLogEntry.ReleaseStatus.Trim().Trim("()")
    58            } 
    59        }
    60        else
    61        {
    62            $this.ChangeLogPath = $null
    63        }
    64    }
    65
    66    hidden [void]Initialize(
    67        [string]$name,
    68        [string]$version,
    69        [string]$directoryPath,
    70        [string]$serviceDirectory,
    71        [string]$group
    72    )
    73    {
    74        $this.Initialize($name, $version, $directoryPath, $serviceDirectory)
    75        $this.Group = $group
    76    }
    77}
    78
    79# Takes package name and service Name
    80# Returns important properties of the package as related to the language repo
    81# Returns a PS Object with properties @ { pkgName, pkgVersion, pkgDirectoryPath, pkgReadMePath, pkgChangeLogPath }
    82# Note: python is required for parsing python package properties.
    83function Get-PkgProperties
    84{
    85    Param
    86    (
    87        [Parameter(Mandatory = $true)]
    88        [string]$PackageName,
    89        [string]$ServiceDirectory
    90    )
    91
    92    $allPkgProps = Get-AllPkgProperties -ServiceDirectory $ServiceDirectory
    93    $pkgProps = $allPkgProps.Where({ $_.Name -eq $PackageName -or $_.ArtifactName -eq $PackageName });
    94
    95    if ($pkgProps.Count -ge 1)
    96    {
    97        if ($pkgProps.Count -gt 1)
    98        {
    99            Write-Host "Found more than one project with the name [$PackageName], choosing the first one under $($pkgProps[0].DirectoryPath)"
   100        }
   101        return $pkgProps[0]
   102    }
   103
   104    LogError "Failed to retrive Properties for [$PackageName]"
   105    return $null
   106}
   107
   108# Takes ServiceName and Repo Root Directory
   109# Returns important properties for each package in the specified service, or entire repo if the serviceName is not specified
   110# Returns an Table of service key to array values of PS Object with properties @ { pkgName, pkgVersion, pkgDirectoryPath, pkgReadMePath, pkgChangeLogPath }
   111function Get-AllPkgProperties ([string]$ServiceDirectory = $null)
   112{
   113    $pkgPropsResult = @()
   114
   115    if (Test-Path "Function:Get-AllPackageInfoFromRepo")
   116    {
   117        $pkgPropsResult = Get-AllPackageInfoFromRepo -ServiceDirectory $serviceDirectory
   118    }
   119    else
   120    {
   121        if ([string]::IsNullOrEmpty($ServiceDirectory))
   122        {
   123            foreach ($dir in (Get-ChildItem (Join-Path $RepoRoot "sdk") -Directory))
   124            {
   125                $pkgPropsResult += Get-PkgPropsForEntireService -serviceDirectoryPath $dir.FullName
   126            }
   127        }
   128        else
   129        {
   130            $pkgPropsResult = Get-PkgPropsForEntireService -serviceDirectoryPath (Join-Path $RepoRoot "sdk" $ServiceDirectory)
   131        }
   132    }
   133
   134    return $pkgPropsResult
   135}
   136
   137# Given the metadata url under https://github.com/Azure/azure-sdk/tree/main/_data/releases/latest,
   138# the function will return the csv metadata back as part of response.
   139function Get-CSVMetadata ([string]$MetadataUri=$MetadataUri)
   140{
   141    $metadataResponse = Invoke-RestMethod -Uri $MetadataUri -method "GET" -MaximumRetryCount 3 -RetryIntervalSec 10 | ConvertFrom-Csv
   142    return $metadataResponse
   143}
   144
   145function Get-PkgPropsForEntireService ($serviceDirectoryPath)
   146{
   147    $projectProps = @() # Properties from very project inthe service
   148    $serviceDirectory = $serviceDirectoryPath -replace '^.*[\\/]+sdk[\\/]+([^\\/]+).*$', '$1'
   149
   150    if (!$GetPackageInfoFromRepoFn -or !(Test-Path "Function:$GetPackageInfoFromRepoFn"))
   151    {
   152        LogError "The function for '$GetPackageInfoFromRepoFn' was not found.`
   153        Make sure it is present in eng/scripts/Language-Settings.ps1 and referenced in eng/common/scripts/common.ps1.`
   154        See https://github.com/Azure/azure-sdk-tools/blob/main/doc/common/common_engsys.md#code-structure"
   155    }
   156
   157    foreach ($directory in (Get-ChildItem $serviceDirectoryPath -Directory))
   158    {
   159        $pkgProps = &$GetPackageInfoFromRepoFn $directory.FullName $serviceDirectory
   160        if ($null -ne $pkgProps)
   161        {
   162            $projectProps += $pkgProps
   163        }
   164    }
   165
   166    return $projectProps
   167}

View as plain text