Compare commits

..

1 Commits

Author SHA1 Message Date
Connie Yau
9a7cb46c10 Add serviceConnections parameter to npmAuthenticate task. 2025-12-05 19:09:41 +00:00
5 changed files with 44 additions and 71 deletions

View File

@ -6,6 +6,9 @@ parameters:
- name: CustomCondition - name: CustomCondition
type: string type: string
default: succeeded() default: succeeded()
- name: ServiceConnection
type: string
default: ''
steps: steps:
- pwsh: | - pwsh: |
@ -21,8 +24,10 @@ steps:
$content | Out-File '${{ parameters.npmrcPath }}' $content | Out-File '${{ parameters.npmrcPath }}'
displayName: 'Create .npmrc' displayName: 'Create .npmrc'
condition: ${{ parameters.CustomCondition }} condition: ${{ parameters.CustomCondition }}
- task: npmAuthenticate@0 - task: npmAuthenticate@0
displayName: Authenticate .npmrc displayName: Authenticate .npmrc
condition: ${{ parameters.CustomCondition }} condition: ${{ parameters.CustomCondition }}
inputs: inputs:
workingFile: ${{ parameters.npmrcPath }} workingFile: ${{ parameters.npmrcPath }}
azureDevOpsServiceConnection: ${{ parameters.ServiceConnection }}

View File

@ -14,9 +14,9 @@ parameters:
- name: TestPipeline - name: TestPipeline
type: boolean type: boolean
default: false default: false
- name: Artifacts - name: ArtifactsJson
type: object type: string
default: [] default: ''
steps: steps:
- ${{ if eq(parameters.TestPipeline, true) }}: - ${{ if eq(parameters.TestPipeline, true) }}:
@ -31,5 +31,5 @@ steps:
-PackageNames '${{ coalesce(parameters.PackageName, parameters.PackageNames) }}' -PackageNames '${{ coalesce(parameters.PackageName, parameters.PackageNames) }}'
-ServiceDirectory '${{ parameters.ServiceDirectory }}' -ServiceDirectory '${{ parameters.ServiceDirectory }}'
-TagSeparator '${{ parameters.TagSeparator }}' -TagSeparator '${{ parameters.TagSeparator }}'
-Artifacts @('${{ replace(convertToJson(parameters.Artifacts), '''', '`''') }}' | ConvertFrom-Json) -ArtifactsJson '${{ parameters.ArtifactsJson }}'
pwsh: true pwsh: true

View File

@ -5,83 +5,63 @@ param (
[string]$BuildID, [string]$BuildID,
[Parameter(mandatory = $false)] [Parameter(mandatory = $false)]
[string]$PackageNames = "", [string]$PackageNames = "",
[Parameter(mandatory = $false)] [Parameter(mandatory = $true)]
# ServiceDirectory is required when using PackageNames,
# or when Artifacts do not include their own ServiceDirectory property.
[string]$ServiceDirectory, [string]$ServiceDirectory,
[Parameter(mandatory = $false)] [Parameter(mandatory = $false)]
[string]$TagSeparator = "_", [string]$TagSeparator = "_",
[Parameter(mandatory = $false)] [Parameter(mandatory = $false)]
[object[]]$Artifacts = @() [string]$ArtifactsJson = ""
) )
. (Join-Path $PSScriptRoot common.ps1) . (Join-Path $PSScriptRoot common.ps1)
# Ensure Artifacts is always an array
$Artifacts = @($Artifacts)
Write-Host "PackageNames: $PackageNames" Write-Host "PackageNames: $PackageNames"
Write-Host "ServiceDirectory: $ServiceDirectory" Write-Host "ServiceDirectory: $ServiceDirectory"
Write-Host "BuildID: $BuildID" Write-Host "BuildID: $BuildID"
Write-Host "Artifacts count: $($Artifacts.Count)" Write-Host "ArtifactsJson: $ArtifactsJson"
if ($Artifacts -and $Artifacts.Count -gt 0) { $packageNamesArray = @()
# When using Artifacts, process each artifact with its name and groupId (if applicable) $artifacts = $null
# If ArtifactsJson is provided, extract package names from it
if (![String]::IsNullOrWhiteSpace($ArtifactsJson)) {
Write-Host "Using ArtifactsJson to determine package names"
try { try {
foreach ($artifact in $Artifacts) { $artifacts = $ArtifactsJson | ConvertFrom-Json
# Validate required properties $packageNamesArray = $artifacts | ForEach-Object { $_.name }
if (-not (Get-Member -InputObject $artifact -Name 'name' -MemberType Properties)) { Write-Host "Extracted package names from ArtifactsJson: $($packageNamesArray -join ', ')"
LogError "Artifact is missing required 'name' property." }
exit 1 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
}
if ($artifacts) {
# When using ArtifactsJson, process each artifact with its name and groupId (if applicable)
try {
foreach ($artifact in $artifacts) {
$packageName = $artifact.name $packageName = $artifact.name
if ([String]::IsNullOrWhiteSpace($packageName)) {
LogError "Artifact 'name' property is null or empty."
exit 1
}
$artifactServiceDirectory = $null
# Check for ServiceDirectory property
if (Get-Member -InputObject $artifact -Name 'ServiceDirectory' -MemberType Properties) {
if (![String]::IsNullOrWhiteSpace($artifact.ServiceDirectory)) {
$artifactServiceDirectory = $artifact.ServiceDirectory
}
}
if ([String]::IsNullOrWhiteSpace($artifactServiceDirectory)) {
$artifactServiceDirectory = $ServiceDirectory
}
# 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") $newVersion = [AzureEngSemanticVersion]::new("1.0.0")
$prefix = "$packageName$TagSeparator" $prefix = "$packageName$TagSeparator"
if ($Language -eq "java") { 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 $groupId = $artifact.groupId
Write-Host "Processing $packageName with groupId $groupId"
if ([String]::IsNullOrWhiteSpace($groupId)) { if ([String]::IsNullOrWhiteSpace($groupId)) {
LogError "GroupId is missing for package $packageName." LogError "GroupId is missing for package $packageName."
exit 1 exit 1
} }
Write-Host "Processing $packageName with groupId $groupId"
# Use groupId+artifactName format for tag prefix (e.g., "com.azure.v2+azure-sdk-template_") # Use groupId+artifactName format for tag prefix (e.g., "com.azure.v2+azure-sdk-template_")
$prefix = "$groupId+$packageName$TagSeparator" $prefix = "$groupId+$packageName$TagSeparator"
} }
else {
Write-Host "Processing $packageName"
}
Write-Host "Get Latest Tag : git tag -l $prefix*" Write-Host "Get Latest Tag : git tag -l $prefix*"
$latestTags = git tag -l "$prefix*" $latestTags = git tag -l "$prefix*"
@ -107,27 +87,21 @@ if ($Artifacts -and $Artifacts.Count -gt 0) {
if ($Language -ne "java") { if ($Language -ne "java") {
SetPackageVersion -PackageName $packageName ` SetPackageVersion -PackageName $packageName `
-Version $newVersion.ToString() ` -Version $newVersion.ToString() `
-ServiceDirectory $artifactServiceDirectory -ServiceDirectory $ServiceDirectory
} else { } else {
SetPackageVersion -PackageName $packageName ` SetPackageVersion -PackageName $packageName `
-Version $newVersion.ToString() ` -Version $newVersion.ToString() `
-ServiceDirectory $artifactServiceDirectory ` -ServiceDirectory $ServiceDirectory `
-GroupId $groupId -GroupId $groupId
} }
} }
} }
catch { catch {
LogError "Failed to process Artifacts: exception: $($_.Exception.Message)" LogError "Failed to process ArtifactsJson: $ArtifactsJson, exception: $($_.Exception.Message)"
exit 1 exit 1
} }
} elseif (![String]::IsNullOrWhiteSpace($PackageNames)) { } else {
# Fallback to original logic when using PackageNames string # Fallback to original logic when using PackageNames string
if ([String]::IsNullOrWhiteSpace($ServiceDirectory)) {
LogError "ServiceDirectory is required when using PackageNames."
exit 1
}
$packageNamesArray = $PackageNames.Split(',')
foreach ($packageName in $packageNamesArray) { foreach ($packageName in $packageNamesArray) {
Write-Host "Processing $packageName" Write-Host "Processing $packageName"
$newVersion = [AzureEngSemanticVersion]::new("1.0.0") $newVersion = [AzureEngSemanticVersion]::new("1.0.0")
@ -157,7 +131,4 @@ if ($Artifacts -and $Artifacts.Count -gt 0) {
-Version $newVersion.ToString() ` -Version $newVersion.ToString() `
-ServiceDirectory $ServiceDirectory -ServiceDirectory $ServiceDirectory
} }
} else {
LogError "Either PackageNames or Artifacts must be provided."
exit 1
} }

View File

@ -94,9 +94,6 @@ function LogGroupStart() {
elseif (Test-SupportsGitHubLogging) { elseif (Test-SupportsGitHubLogging) {
Write-Host "::group::$args" Write-Host "::group::$args"
} }
else {
Write-Host "> $args"
}
} }
function LogGroupEnd() { function LogGroupEnd() {

View File

@ -1,7 +1,7 @@
{ {
"name": "azure-sdk-for-cpp", "name": "azure-sdk-for-cpp",
"version": "1.5.0", "version": "1.5.0",
"builtin-baseline": "74e6536215718009aae747d86d84b78376bf9e09", "builtin-baseline": "4334d8b4c8916018600212ab4dd4bbdc343065d1",
"dependencies": [ "dependencies": [
{ {
"name": "curl" "name": "curl"