Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ parameters:
- name: TestPipeline
type: boolean
default: false
- name: ArtifactsJson
type: string
default: ''
- name: Artifacts
type: object
default: []

steps:
- ${{ if eq(parameters.TestPipeline, true) }}:
Expand All @@ -31,5 +31,5 @@ steps:
-PackageNames '${{ coalesce(parameters.PackageName, parameters.PackageNames) }}'
-ServiceDirectory '${{ parameters.ServiceDirectory }}'
-TagSeparator '${{ parameters.TagSeparator }}'
-ArtifactsJson '${{ parameters.ArtifactsJson }}'
-Artifacts @('${{ replace(convertToJson(parameters.Artifacts), '''', '`''') }}' | ConvertFrom-Json)
pwsh: true
89 changes: 54 additions & 35 deletions eng/common/scripts/SetTestPipelineVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,77 @@ param (
[string]$BuildID,
[Parameter(mandatory = $false)]
[string]$PackageNames = "",
[Parameter(mandatory = $true)]
[Parameter(mandatory = $false)]
[string]$ServiceDirectory,
[Parameter(mandatory = $false)]
[string]$TagSeparator = "_",
[Parameter(mandatory = $false)]
[string]$ArtifactsJson = ""
[object[]]$Artifacts = @()
)

. (Join-Path $PSScriptRoot common.ps1)

# Ensure Artifacts is always an array
$Artifacts = @($Artifacts)

Write-Host "PackageNames: $PackageNames"
Write-Host "ServiceDirectory: $ServiceDirectory"
Write-Host "BuildID: $BuildID"
Write-Host "ArtifactsJson: $ArtifactsJson"

$packageNamesArray = @()
$artifacts = $null

# If ArtifactsJson is provided, extract package names from it
if (![String]::IsNullOrWhiteSpace($ArtifactsJson)) {
Write-Host "Using ArtifactsJson to determine package names"
try {
$artifacts = $ArtifactsJson | ConvertFrom-Json
$packageNamesArray = $artifacts | ForEach-Object { $_.name }
Write-Host "Extracted package names from ArtifactsJson: $($packageNamesArray -join ', ')"
}
catch {
LogError "Failed to parse ArtifactsJson: $($_.Exception.Message)"
exit 1
}
}
elseif (![String]::IsNullOrWhiteSpace($PackageNames)) {
$packageNamesArray = $PackageNames.Split(',')
}
else {
LogError "Either PackageNames or ArtifactsJson must be provided."
exit 1
}
Write-Host "Artifacts count: $($Artifacts.Count)"

if ($artifacts) {
# When using ArtifactsJson, process each artifact with its name and groupId (if applicable)
if ($Artifacts -and $Artifacts.Count -gt 0) {
# When using Artifacts, process each artifact with its name and groupId (if applicable)
try {
foreach ($artifact in $artifacts) {
foreach ($artifact in $Artifacts) {
# Validate required properties
if (-not (Get-Member -InputObject $artifact -Name 'name' -MemberType Properties)) {
LogError "Artifact is missing required 'name' property."
exit 1
}

$packageName = $artifact.name
if ([String]::IsNullOrWhiteSpace($packageName)) {
LogError "Artifact 'name' property is null or empty."
exit 1
}

# Check for ServiceDirectory property
$artifactServiceDirectory = $ServiceDirectory
if (Get-Member -InputObject $artifact -Name 'ServiceDirectory' -MemberType Properties) {
if (![String]::IsNullOrWhiteSpace($artifact.ServiceDirectory)) {
$artifactServiceDirectory = $artifact.ServiceDirectory
Comment thread
weshaggard marked this conversation as resolved.
}
}

# Validate ServiceDirectory is available
if ([String]::IsNullOrWhiteSpace($artifactServiceDirectory)) {
LogError "ServiceDirectory is required but not provided for artifact '$packageName'. Provide it via script parameter or artifact property."
exit 1
}

$newVersion = [AzureEngSemanticVersion]::new("1.0.0")
$prefix = "$packageName$TagSeparator"

if ($Language -eq "java") {
# Check for groupId property
if (-not (Get-Member -InputObject $artifact -Name 'groupId' -MemberType Properties)) {
LogError "Artifact '$packageName' is missing required 'groupId' property for Java language."
exit 1
}

$groupId = $artifact.groupId
Write-Host "Processing $packageName with groupId $groupId"
if ([String]::IsNullOrWhiteSpace($groupId)) {
LogError "GroupId is missing for package $packageName."
exit 1
}

Write-Host "Processing $packageName with groupId $groupId"
# Use groupId+artifactName format for tag prefix (e.g., "com.azure.v2+azure-sdk-template_")
$prefix = "$groupId+$packageName$TagSeparator"
}
else {
Write-Host "Processing $packageName"
}

Write-Host "Get Latest Tag : git tag -l $prefix*"
$latestTags = git tag -l "$prefix*"
Expand All @@ -87,21 +101,23 @@ if ($artifacts) {
if ($Language -ne "java") {
SetPackageVersion -PackageName $packageName `
-Version $newVersion.ToString() `
-ServiceDirectory $ServiceDirectory
-ServiceDirectory $artifactServiceDirectory
} else {
SetPackageVersion -PackageName $packageName `
-Version $newVersion.ToString() `
-ServiceDirectory $ServiceDirectory `
-ServiceDirectory $artifactServiceDirectory `
-GroupId $groupId
}
}
}
catch {
LogError "Failed to process ArtifactsJson: $ArtifactsJson, exception: $($_.Exception.Message)"
LogError "Failed to process Artifacts: exception: $($_.Exception.Message)"
exit 1
}
} else {
} elseif (![String]::IsNullOrWhiteSpace($PackageNames)) {
# Fallback to original logic when using PackageNames string
Comment thread
raych1 marked this conversation as resolved.
$packageNamesArray = @()
Comment thread
raych1 marked this conversation as resolved.
Outdated
$packageNamesArray = $PackageNames.Split(',')
foreach ($packageName in $packageNamesArray) {
Write-Host "Processing $packageName"
$newVersion = [AzureEngSemanticVersion]::new("1.0.0")
Expand Down Expand Up @@ -131,4 +147,7 @@ if ($artifacts) {
-Version $newVersion.ToString() `
-ServiceDirectory $ServiceDirectory
}
} else {
LogError "Either PackageNames or Artifacts must be provided."
exit 1
}
Loading