diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index d085a398fc..330cfc1eba 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -44,12 +44,21 @@ function Get-AllPackageInfoFromRepo ([string] $ServiceDirectory) { $searchPath = Join-Path $searchPath $ServiceDirectory -Resolve } - # when a package is marked `publish = false` in the Cargo.toml, `cargo metadata` returns an empty array for - # `publish`, otherwise it returns null. We only want to include packages where `publish` is null. + # Enumerate packages that do not have "test" as an independent word in the + # name. + # Examples: + # "azure_core" - included + # "azure_core_test" - excluded + # "azure_attestation" - included $packages = Invoke-LoggedCommand "cargo metadata --format-version 1 --no-deps" -GroupOutput | ConvertFrom-Json -AsHashtable | Select-Object -ExpandProperty packages - | Where-Object { $_.manifest_path.StartsWith($searchPath) -and $null -eq $_.publish } + | Where-Object { $_.manifest_path.StartsWith($searchPath) -and "test" -notin ($_.name -split '_') } + + if (!$packages) { + LogWarning "No publishable packages found in service directory: $ServiceDirectory" + return @() + } $packageManifests = @{} foreach ($package in $packages) { @@ -120,7 +129,7 @@ function Get-AllPackageInfoFromRepo ([string] $ServiceDirectory) { function Get-rust-AdditionalValidationPackagesFromPackageSet ($packagesWithChanges, $diff, $allPackageProperties) { # if the change was in a service directory, but not in a package directory, test all the packages in the service directory [array]$serviceFiles = ($diff.ChangedFiles + $diff.DeletedFiles) | ForEach-Object { $_ -replace '\\', '/' } | Where-Object { $_ -match "^sdk/.+/" } - + # remove files that target any specific package foreach ($package in $allPackageProperties) { $packagePathPattern = "^$( [Regex]::Escape($package.DirectoryPath.Replace('\', '/')) )/" diff --git a/eng/scripts/Pack-Crates.ps1 b/eng/scripts/Pack-Crates.ps1 index 72323370a9..9ff98af62b 100755 --- a/eng/scripts/Pack-Crates.ps1 +++ b/eng/scripts/Pack-Crates.ps1 @@ -57,9 +57,6 @@ function Get-PackagesToBuild() { } function Get-OutputPackageNames($workspacePackages) { - $packablePackages = $workspacePackages | Where-Object -Property publish -NE -Value @() - $packablePackageNames = $packablePackages.name - $names = @() switch ($PsCmdlet.ParameterSetName) { 'Named' { @@ -71,12 +68,12 @@ function Get-OutputPackageNames($workspacePackages) { } default { - return $packablePackageNames + return $workspacePackages.name } } foreach ($name in $names) { - if (-not $packablePackageNames.Contains($name)) { + if (-not $workspacePackages.name.Contains($name)) { Write-Error "Package '$name' is not in the workspace or does not publish" exit 1 } @@ -109,9 +106,18 @@ try { $packageParams += "--no-verify" } - LogGroupStart "cargo publish --locked --dry-run --allow-dirty $($packageParams -join ' ')" - Write-Host "cargo publish --locked --dry-run --allow-dirty $($packageParams -join ' ')" - & cargo publish --locked --dry-run --allow-dirty @packageParams 2>&1 ` + # Some packages are not publishable, in cases where the script is not in a + # release context, run cargo package` instead of `cargo publish --dry-run`. + # The two are equivalent (https://doc.rust-lang.org/cargo/reference/publishing.html) + # though `cargo publish` has additional checks like publishability. + $subCommand = @("package") + if ($Release) { + $subCommand = @("publish", "--dry-run") + } + + LogGroupStart "cargo $($subCommand -join ' ') --locked --allow-dirty $($packageParams -join ' ')" + Write-Host "cargo $($subCommand -join ' ') --locked --allow-dirty $($packageParams -join ' ')" + & cargo @subCommand --locked --allow-dirty @packageParams 2>&1 ` | Tee-Object -Variable packResult ` | ForEach-Object { Write-Host $_ -ForegroundColor Gray } LogGroupEnd diff --git a/eng/scripts/Test-Semver.ps1 b/eng/scripts/Test-Semver.ps1 index 8b66287d3e..70ac714a9a 100755 --- a/eng/scripts/Test-Semver.ps1 +++ b/eng/scripts/Test-Semver.ps1 @@ -14,9 +14,6 @@ param( . ([System.IO.Path]::Combine($PSScriptRoot, 'shared', 'Cargo.ps1')) function Get-OutputPackageNames($workspacePackages) { - $packablePackages = $workspacePackages | Where-Object -Property publish -NE -Value @() - $packablePackageNames = $packablePackages.name - $names = @() switch ($PsCmdlet.ParameterSetName) { 'Named' { @@ -28,12 +25,13 @@ function Get-OutputPackageNames($workspacePackages) { } default { - return $packablePackageNames + return $workspacePackages.name + } } foreach ($name in $names) { - if (-not $packablePackageNames.Contains($name)) { + if (-not $workspacePackages.name.Contains($name)) { Write-Error "Package '$name' is not in the workspace or does not publish" exit 1 }