Sync eng/common directory with azure-sdk-tools for PR 8900 (#1863)
* Add save-package-properties yaml * Encapsulate Save-Package-Properties.ps1 invocation into yaml * Fix output formatting * Fix code style --------- Co-authored-by: Patrick Hallisey <pahallis@microsoft.com>
This commit is contained in:
Родитель
ffce77e822
Коммит
7adeac7053
|
@ -0,0 +1,46 @@
|
|||
parameters:
|
||||
- name: ServiceDirectory
|
||||
type: string
|
||||
default: ""
|
||||
- name: DiffDirectory
|
||||
type: string
|
||||
default: $(Build.ArtifactStagingDirectory)/diff
|
||||
- name: PackageInfoDirectory
|
||||
type: string
|
||||
default: $(Build.ArtifactStagingDirectory)/PackageInfo
|
||||
- name: TargetPath
|
||||
type: string
|
||||
default: $(Build.SourcesDirectory)
|
||||
- name: ScriptDirectory
|
||||
type: string
|
||||
default: eng/common/scripts
|
||||
|
||||
steps:
|
||||
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
|
||||
- task: Powershell@2
|
||||
displayName: Generate PR Diff
|
||||
inputs:
|
||||
filePath: ${{ parameters.ScriptDirectory }}/Generate-PR-Diff.ps1
|
||||
arguments: >
|
||||
-TargetPath '${{ parameters.TargetPath }}'
|
||||
-ArtifactPath '${{ parameters.DiffDirectory }}'
|
||||
pwsh: true
|
||||
|
||||
- task: Powershell@2
|
||||
displayName: Save package properties filtered for PR
|
||||
inputs:
|
||||
filePath: ${{ parameters.ScriptDirectory }}/Save-Package-Properties.ps1
|
||||
arguments: >
|
||||
-PrDiff ${{ parameters.DiffDirectory }}/diff.json
|
||||
-OutDirectory ${{ parameters.PackageInfoDirectory }}
|
||||
pwsh: true
|
||||
- ${{ else }}:
|
||||
- task: Powershell@2
|
||||
displayName: Save package properties
|
||||
inputs:
|
||||
filePath: ${{ parameters.ScriptDirectory }}/Save-Package-Properties.ps1
|
||||
arguments: >
|
||||
-ServiceDirectory ${{parameters.ServiceDirectory}}
|
||||
-OutDirectory ${{ parameters.PackageInfoDirectory }}
|
||||
-AddDevVersion:$${{ eq(variables['SetDevVersion'],'true') }}
|
||||
pwsh: true
|
|
@ -13,27 +13,29 @@ The path under which changes will be detected.
|
|||
#>
|
||||
[CmdletBinding()]
|
||||
Param (
|
||||
[Parameter(Mandatory=$True)]
|
||||
[Parameter(Mandatory = $True)]
|
||||
[string] $ArtifactPath,
|
||||
[Parameter(Mandatory=$True)]
|
||||
[Parameter(Mandatory = $True)]
|
||||
[string] $TargetPath
|
||||
)
|
||||
|
||||
. (Join-Path $PSScriptRoot "Helpers" "git-helpers.ps1")
|
||||
|
||||
function Get-ChangedServices {
|
||||
Param (
|
||||
[Parameter(Mandatory=$True)]
|
||||
[string[]] $ChangedFiles
|
||||
)
|
||||
function Get-ChangedServices
|
||||
{
|
||||
Param (
|
||||
[Parameter(Mandatory = $True)]
|
||||
[string[]] $ChangedFiles
|
||||
)
|
||||
|
||||
$changedServices = $ChangedFiles | Foreach-Object { if ($_ -match "sdk/([^/]+)") { $matches[1] } } | Sort-Object -Unique
|
||||
$changedServices = $ChangedFiles | Foreach-Object { if ($_ -match "sdk/([^/]+)") { $matches[1] } } | Sort-Object -Unique
|
||||
|
||||
return $changedServices
|
||||
return $changedServices
|
||||
}
|
||||
|
||||
if (!(Test-Path $ArtifactPath)) {
|
||||
New-Item -ItemType Directory -Path $ArtifactPath | Out-Null
|
||||
if (!(Test-Path $ArtifactPath))
|
||||
{
|
||||
New-Item -ItemType Directory -Path $ArtifactPath | Out-Null
|
||||
}
|
||||
|
||||
$ArtifactPath = Resolve-Path $ArtifactPath
|
||||
|
@ -43,9 +45,13 @@ $changedFiles = Get-ChangedFiles -DiffPath $TargetPath
|
|||
$changedServices = Get-ChangedServices -ChangedFiles $changedFiles
|
||||
|
||||
$result = [PSCustomObject]@{
|
||||
"ChangedFiles" = $changedFiles
|
||||
"ChangedServices" = $changedServices
|
||||
"PRNumber" = if ($env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER) { $env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER } else { "-1" }
|
||||
"ChangedFiles" = $changedFiles
|
||||
"ChangedServices" = $changedServices
|
||||
"PRNumber" = if ($env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER) { $env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER } else { "-1" }
|
||||
}
|
||||
|
||||
$result | ConvertTo-Json | Out-File $ArtifactName
|
||||
$json = $result | ConvertTo-Json
|
||||
$json | Out-File $ArtifactName
|
||||
|
||||
Write-Host "`nGenerated diff.json file at $ArtifactName"
|
||||
Write-Host " $($json -replace "`n", "`n ")"
|
||||
|
|
|
@ -36,7 +36,7 @@ Verison property in that file.
|
|||
[CmdletBinding()]
|
||||
Param (
|
||||
[string] $serviceDirectory,
|
||||
[Parameter(Mandatory=$True)]
|
||||
[Parameter(Mandatory = $True)]
|
||||
[string] $outDirectory,
|
||||
[string] $prDiff,
|
||||
[switch] $addDevVersion
|
||||
|
@ -44,7 +44,8 @@ Param (
|
|||
|
||||
. (Join-Path $PSScriptRoot common.ps1)
|
||||
|
||||
function SetOutput($outputPath, $incomingPackageSpec) {
|
||||
function SetOutput($outputPath, $incomingPackageSpec)
|
||||
{
|
||||
|
||||
# If there is an exsiting package info json file read that and set that as output object which gets properties updated here.
|
||||
if (Test-Path $outputPath)
|
||||
|
@ -75,16 +76,19 @@ function SetOutput($outputPath, $incomingPackageSpec) {
|
|||
-Value (ConvertTo-Json -InputObject $outputObject -Depth 100)
|
||||
}
|
||||
|
||||
function GetRelativePath($path) {
|
||||
function GetRelativePath($path)
|
||||
{
|
||||
# If the path is empty return an empty string
|
||||
if (!$path) {
|
||||
if (!$path)
|
||||
{
|
||||
return ''
|
||||
}
|
||||
|
||||
# If the path is already relative return the path. Calling `GetRelativePath`
|
||||
# on a relative path converts the relative path to an absolute path based on
|
||||
# the current working directory which can result in unexpected outputs.
|
||||
if (![IO.Path]::IsPathRooted($path)) {
|
||||
if (![IO.Path]::IsPathRooted($path))
|
||||
{
|
||||
return $path
|
||||
}
|
||||
|
||||
|
@ -98,22 +102,26 @@ $exportedPaths = @{}
|
|||
|
||||
$allPackageProperties = @()
|
||||
|
||||
if ($prDiff) {
|
||||
if ($prDiff)
|
||||
{
|
||||
Write-Host "Getting package properties for PR diff file: $prDiff"
|
||||
$allPackageProperties = Get-PrPkgProperties $prDiff
|
||||
|
||||
if (!$allPackageProperties) {
|
||||
if (!$allPackageProperties)
|
||||
{
|
||||
Write-Host "No packages found matching PR diff file $prDiff"
|
||||
Write-Host "Setting NoPackagesChanged variable to true"
|
||||
Write-Host "##vso[task.setvariable variable=NoPackagesChanged]true"
|
||||
exit 0
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
Write-Host "Getting package properties for service directory: $serviceDirectory"
|
||||
$allPackageProperties = Get-AllPkgProperties $serviceDirectory
|
||||
|
||||
if (!$allPackageProperties) {
|
||||
if (!$allPackageProperties)
|
||||
{
|
||||
Write-Error "Package properties are not available for service directory $serviceDirectory"
|
||||
exit 1
|
||||
}
|
||||
|
@ -124,21 +132,26 @@ if (-not (Test-Path -Path $outDirectory))
|
|||
New-Item -ItemType Directory -Force -Path $outDirectory | Out-Null
|
||||
}
|
||||
|
||||
foreach($pkg in $allPackageProperties)
|
||||
foreach ($pkg in $allPackageProperties)
|
||||
{
|
||||
if ($pkg.Name) {
|
||||
if ($pkg.Name)
|
||||
{
|
||||
Write-Host ""
|
||||
Write-Host "Package Name: $($pkg.Name)"
|
||||
Write-Host "Package Version: $($pkg.Version)"
|
||||
Write-Host "Package SDK Type: $($pkg.SdkType)"
|
||||
Write-Host "Artifact Name: $($pkg.ArtifactName)"
|
||||
Write-Host "Release date: $($pkg.ReleaseStatus)"
|
||||
$configFilePrefix = $pkg.Name
|
||||
|
||||
if ($pkg.ArtifactName)
|
||||
{
|
||||
$configFilePrefix = $pkg.ArtifactName
|
||||
}
|
||||
|
||||
$outputPath = Join-Path -Path $outDirectory "$configFilePrefix.json"
|
||||
Write-Host "Output path of json file: $outputPath"
|
||||
|
||||
$outDir = Split-Path $outputPath -parent
|
||||
if (-not (Test-Path -path $outDir))
|
||||
{
|
||||
|
@ -148,14 +161,17 @@ foreach($pkg in $allPackageProperties)
|
|||
|
||||
# If package properties for a track 2 (IsNewSdk = true) package has
|
||||
# already been written, skip writing to that same path.
|
||||
if ($exportedPaths.ContainsKey($outputPath) -and $exportedPaths[$outputPath].IsNewSdk -eq $true) {
|
||||
if ($exportedPaths.ContainsKey($outputPath) -and $exportedPaths[$outputPath].IsNewSdk -eq $true)
|
||||
{
|
||||
Write-Host "Track 2 package info with file name $($outputPath) already exported. Skipping export."
|
||||
continue
|
||||
}
|
||||
$exportedPaths[$outputPath] = $pkg
|
||||
|
||||
$exportedPaths[$outputPath] = $pkg
|
||||
SetOutput $outputPath $pkg
|
||||
}
|
||||
}
|
||||
|
||||
Get-ChildItem -Path $outDirectory
|
||||
$fileNames = (Get-ChildItem -Path $outDirectory).Name
|
||||
Write-Host "`nFiles written to $outDirectory`:"
|
||||
Write-Host " $($fileNames -join "`n ")"
|
||||
|
|
Загрузка…
Ссылка в новой задаче