Skip to content

Add API View to build #2396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
570cd60
Add API View to build
hallipr Mar 26, 2025
91be328
Use toolchain defaulting instead explit toolchain in each cargo call
hallipr Mar 27, 2025
ce98ce7
Add Use-Rust.ps1
hallipr Mar 27, 2025
1d4f099
Run rustup self update
hallipr Mar 27, 2025
8c95b2c
Only update rustup if version < 1.28
hallipr Mar 27, 2025
4138d25
Powershell cleanup
hallipr Mar 27, 2025
d8bdbe2
Only update rustup if we're using 'default' toolchain
hallipr Mar 27, 2025
a55dc3e
Stop Get-rust-AdditionalValidationPackagesFromPackageSet returning $null
hallipr Mar 27, 2025
625d722
Add API Review step to release template
hallipr Mar 27, 2025
c6fff3d
Update eng/pipelines/templates/stages/archetype-rust-release.yml
hallipr Mar 27, 2025
8e1e091
Add execute perm to Use-rust.ps1
hallipr Mar 27, 2025
19e2c86
Use-rust must be inlined powershell for use in the 1es deployment job
hallipr Mar 27, 2025
0f8c7dc
Use regex in place of eng/common semver type
hallipr Mar 27, 2025
b086e70
Add exit on bad exit code
hallipr Mar 27, 2025
b8e2c56
Remove command prefix >
hallipr Mar 27, 2025
e44a370
Change naming to Submit API Review
hallipr Mar 27, 2025
ba3b7fd
Add comments, check rustup version from non-repo folder, use correct …
hallipr Mar 27, 2025
a94b65c
Reorder args in rustup install command
hallipr Mar 27, 2025
5e7bd2b
Remove write-host for rustup default
hallipr Mar 27, 2025
cdeb3ef
Add download step to apireview job
hallipr Mar 28, 2025
77b25c3
Combine API Review and package version update
hallipr Mar 28, 2025
39fb6c7
Bump template project versions to cause api view change detection
hallipr Mar 28, 2025
3319873
Use .rust.json files
hallipr Mar 28, 2025
c6235a3
Update eng/scripts/Language-Settings.ps1
hallipr Apr 1, 2025
a313f6d
Only bump template to 0.2.0
hallipr Apr 1, 2025
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
1 change: 0 additions & 1 deletion eng/pipelines/templates/jobs/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jobs:
pwsh: true
filePath: $(Build.SourcesDirectory)/eng/scripts/Analyze-Code.ps1
arguments: >
-Toolchain '$(Toolchain)'
-PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo'
-SkipPackageAnalysis:('$(NoPackagesChanged)' -eq 'true')

Expand Down
1 change: 0 additions & 1 deletion eng/pipelines/templates/jobs/ci.tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ jobs:
filePath: $(Build.SourcesDirectory)/eng/scripts/Test-Packages.ps1
arguments: >
-PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo'
-Toolchain '$(Toolchain)'

- ${{ if eq(parameters.TestProxy, true) }}:
- pwsh: |
Expand Down
5 changes: 2 additions & 3 deletions eng/pipelines/templates/jobs/live.tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ jobs:
$env:AZURESUBSCRIPTION_CLIENT_ID = $account.Id;
$env:AZURESUBSCRIPTION_TENANT_ID = $account.Tenants;

Write-Host "./eng/scripts/Test-Packages.ps1 -PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo' -Toolchain '$(Toolchain)'"
./eng/scripts/Test-Packages.ps1 -PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo' -Toolchain '$(Toolchain)'
Write-Host "./eng/scripts/Test-Packages.ps1 -PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo'"
./eng/scripts/Test-Packages.ps1 -PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo'
workingDirectory: $(Build.SourcesDirectory)
- ${{ else }}:
- task: Powershell@2
Expand All @@ -139,7 +139,6 @@ jobs:
filePath: $(Build.SourcesDirectory)/eng/scripts/Test-Packages.ps1
arguments: >
-PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo'
-Toolchain '$(Toolchain)'

- ${{ parameters.PostSteps }}

Expand Down
9 changes: 8 additions & 1 deletion eng/pipelines/templates/jobs/pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ jobs:

- template: /eng/pipelines/templates/steps/use-rust.yml@self
parameters:
Toolchain: nightly
WorkingDirectory: $(System.DefaultWorkingDirectory)/eng/tools/generate_api_report
SetDefault: false

- template: /eng/pipelines/templates/steps/use-rust.yml@self
parameters:
Expand Down Expand Up @@ -69,3 +70,9 @@ jobs:
ArtifactPath: $(Build.ArtifactStagingDirectory)
ArtifactName: ${{ parameters.PipelineArtifactName }}
CustomCondition: and(succeededOrFailed(), ne(variables['NoPackagesChanged'],'true'))

- template: /eng/common/pipelines/templates/steps/create-apireview.yml
parameters:
Artifacts: ${{ parameters.Artifacts }}

- template: /eng/common/pipelines/templates/steps/detect-api-changes.yml
33 changes: 16 additions & 17 deletions eng/pipelines/templates/stages/archetype-rust-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ stages:
$token = $env:CARGO_REGISTRY_TOKEN
$crateName = '${{artifact.name}}'

$manifestPath = "$(Pipeline.Workspace)/drop/$crateName/Cargo.toml"
$manifestPath = "$(Pipeline.Workspace)/drop/$crateName/contents/Cargo.toml"
Write-Host "> cargo publish --manifest-path `"$manifestPath`""
cargo publish --manifest-path $manifestPath
if (!$?) {
Expand All @@ -112,23 +112,8 @@ stages:
env:
CARGO_REGISTRY_TOKEN: $(azure-sdk-cratesio-token)

# - job: CreateApiReview
# displayName: "Api Review"
# condition: and(succeeded(), ne(variables['Skip.CreateApiReview'], 'true'))
# dependsOn: PublishPackage
# steps:
# - template: /eng/common/pipelines/templates/steps/create-apireview.yml
# parameters:
# ArtifactPath: $(Pipeline.Workspace)/${{parameters.PipelineArtifactName}}
# Artifacts: ${{parameters.Artifacts}}
# ConfigFileDir: $(Pipeline.Workspace)/${{parameters.PipelineArtifactName}}/PackageInfo
# MarkPackageAsShipped: true
# ArtifactName: ${{parameters.PipelineArtifactName}}
# SourceRootPath: $(Pipeline.Workspace)/azure-sdk-for-rust
# PackageName: ${{artifact.name}}

- job: UpdatePackageVersion
displayName: "Update Package Versions"
displayName: "API Review and Package Version Update"
condition: and(succeeded(), ne(variables['Skip.UpdatePackageVersion'], 'true'))
dependsOn: PublishPackage
steps:
Expand All @@ -141,6 +126,20 @@ stages:
parameters:
Toolchain: nightly

- download: current
displayName: Download ${{parameters.PipelineArtifactName}} artifact
artifact: ${{parameters.PipelineArtifactName}}

- template: /eng/common/pipelines/templates/steps/create-apireview.yml
parameters:
ArtifactPath: $(Pipeline.Workspace)/${{parameters.PipelineArtifactName}}
Artifacts: ${{parameters.Artifacts}}
ConfigFileDir: $(Pipeline.Workspace)/${{parameters.PipelineArtifactName}}/PackageInfo
MarkPackageAsShipped: true
ArtifactName: ${{parameters.PipelineArtifactName}}
SourceRootPath: $(System.DefaultWorkingDirectory)
PackageName: ${{artifact.name}}

# Apply the version increment to each library, which updates the Cargo.toml and changelog files.
- task: PowerShell@2
displayName: Increment ${{artifact.name}} version
Expand Down
102 changes: 80 additions & 22 deletions eng/pipelines/templates/steps/use-rust.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,100 @@
parameters:
- name: Toolchain
type: string
default: stable
default: active
# Expexted values: 'stable', 'nightly', 'msrv', 'active' or a specific toolchain version
# 'msrv' will read the MSRV from azure_core
# 'active' will use the active toolchain for the working directory, which will be from rust-toolchain.toml, from a
# folder override or the rustup default toolchain
- name: MaxAttempts
type: number
default: 3
- name: WorkingDirectory
type: string
default: $(System.DefaultWorkingDirectory)
- name: SetDefault
type: boolean
default: true

steps:
- pwsh: |
$toolchain = '${{ parameters.Toolchain }}'
if ($toolchain -eq 'msrv') {
Write-Host "Reading MSRV from azure_core"
$toolchain = cargo read-manifest --manifest-path ./sdk/core/azure_core/Cargo.toml | ConvertFrom-Json | Select-Object -ExpandProperty rust_version
}
- pwsh: |
$Toolchain = '${{ parameters.Toolchain }}'
$MaxAttempts = ${{ parameters.MaxAttempts }}
$SetDefault = $${{ parameters.SetDefault }}

function Invoke-LoggedCommand($command) {
Write-Host "##[group]$command"
Invoke-Expression $command
Write-Host "##[endgroup]"
if ($LASTEXITCODE -ne 0) {
Write-Host "Command failed: $command"
exit $LASTEXITCODE
}
}

if ($Toolchain -eq 'msrv') {
Write-Host "Reading MSRV from azure_core"
$toolchainArg = cargo read-manifest --manifest-path "$(System.DefaultWorkingDirectory)/sdk/core/azure_core/Cargo.toml"
| ConvertFrom-Json
| Select-Object -ExpandProperty rust_version
}
elseif ($Toolchain -eq 'active') {
# You can't call 'rustup install' without a toolchain before rustup 1.28.0. If know we'll be doing that, make sure
# we have the latest rustup installed

# Depending on the version of rustup currently installed, simply calling `rustup --version` will install the
# active toolchain per rust-toolchain.toml if it's not already installed. We should check the rust version
# outside of our repo's context to avoid any rustup-toolchain file influence.

Push-Location '$(Pipeline.Workspace)'
Invoke-LoggedCommand "rustup --version" | Tee-Object -Variable rustupVersion

if ($rustupVersion -match 'rustup (\d+).(\d+).\d+') {
$major = $matches[1]
$minor = $matches[2]
if ($major -lt 1 -or $minor -lt 28) {
Invoke-LoggedCommand "rustup self update"
}
}
Pop-Location

Write-Host "Setting Toolchain variable to $toolchain"
Write-Host "##vso[task.setvariable variable=Toolchain]$toolchain"
$toolchainArg = ''
}
else {
$toolchainArg = $toolchain
}

$attempts = 0
$maxAttempts = ${{ parameters.MaxAttempts }}
$attempts = 0

while ($true) {
while ($true) {
$attempts++
Write-Host "> rustup toolchain install --no-self-update $toolchain"
rustup toolchain install --no-self-update $toolchain

if ($?) { exit 0 }
Invoke-LoggedCommand "rustup install --no-self-update $toolchainArg"

if ($attempts -lt $maxAttempts) {
Write-Host "Failed to install $toolchain, attempt $attempts, retrying..."
} else {
Write-Host "Failed to install $toolchain after $attempts attempts."
exit 1
if ($?) { break }

if ($attempts -lt $MaxAttempts) {
Write-Host "Install failed, attempt $attempts, retrying..."
}
else {
Write-Host "Install failed after $attempts attempts."
exit 1
}

# Failures to update are usually caused by file locks in Windows.
# Sleep for a few seconds to give the blocking process a chance to release the lock.
Start-Sleep -Seconds 3
}
}

if ($SetDefault) {
if ($Toolchain -eq 'active') {
$toolchainArg = rustup show active-toolchain -v | Select-Object -First 1
}

Invoke-LoggedCommand "rustup default $toolchainArg"
}

Invoke-LoggedCommand "rustup show"

displayName: "Use Rust ${{ parameters.Toolchain }}"
displayName: "Use Rust ${{ parameters.Toolchain }}"
workingDirectory: ${{ parameters.WorkingDirectory }}
14 changes: 6 additions & 8 deletions eng/scripts/Analyze-Code.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#Requires -Version 7.0
param(
[string]$Toolchain = 'stable',
[string]$PackageInfoDirectory,
[switch]$CheckWasm = $true,
[switch]$SkipPackageAnalysis
Expand All @@ -15,26 +14,25 @@ Set-StrictMode -Version 2.0

Write-Host @"
Analyzing code with
Toolchain: '$Toolchain'
RUSTFLAGS: '${env:RUSTFLAGS}'
RUSTDOCFLAGS: '${env:RUSTDOCFLAGS}'
"@

if ($CheckWasm) {
Invoke-LoggedCommand "rustup target add --toolchain $Toolchain wasm32-unknown-unknown"
Invoke-LoggedCommand "rustup target add wasm32-unknown-unknown"
}

Invoke-LoggedCommand "cargo +$Toolchain check --package azure_core --all-features --all-targets --keep-going"
Invoke-LoggedCommand "cargo check --package azure_core --all-features --all-targets --keep-going"

Invoke-LoggedCommand "cargo +$Toolchain fmt --all -- --check"
Invoke-LoggedCommand "cargo fmt --all -- --check"

Invoke-LoggedCommand "cargo +$Toolchain clippy --workspace --all-features --all-targets --keep-going --no-deps"
Invoke-LoggedCommand "cargo clippy --workspace --all-features --all-targets --keep-going --no-deps"

if ($CheckWasm) {
Invoke-LoggedCommand "cargo +$Toolchain clippy --target=wasm32-unknown-unknown --workspace --keep-going --no-deps"
Invoke-LoggedCommand "cargo clippy --target=wasm32-unknown-unknown --workspace --keep-going --no-deps"
}

Invoke-LoggedCommand "cargo +$Toolchain doc --workspace --no-deps --all-features"
Invoke-LoggedCommand "cargo doc --workspace --no-deps --all-features"

# Verify package dependencies

Expand Down
26 changes: 22 additions & 4 deletions eng/scripts/Language-Settings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,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('\', '/')) )/"
Expand All @@ -127,15 +128,14 @@ function Get-rust-AdditionalValidationPackagesFromPackageSet ($packagesWithChang

$affectedServiceDirectories = $serviceFiles | ForEach-Object { $_ -replace '^sdk/(.+?)/.*', '$1' } | Sort-Object -Unique

$affectedPackages = $allPackageProperties | Where-Object { $affectedServiceDirectories -contains $_.ServiceDirectory }

[array]$additionalPackages = $affectedPackages | Where-Object { $packagesWithChanges -notcontains $_ }
$affectedPackages = @($allPackageProperties | Where-Object { $affectedServiceDirectories -contains $_.ServiceDirectory })
$additionalPackages = @($affectedPackages | Where-Object { $packagesWithChanges -notcontains $_ })

foreach ($package in $additionalPackages) {
$package.IncludedForValidation = $true
}

return $additionalPackages
return $additionalPackages ?? @()
}

function Get-rust-PackageInfoFromPackageFile([IO.FileInfo]$pkg, [string]$workingDirectory) {
Expand Down Expand Up @@ -167,3 +167,21 @@ function Get-rust-PackageInfoFromPackageFile([IO.FileInfo]$pkg, [string]$working
ReadmeContent = $readmeContent
}
}

function Find-rust-Artifacts-For-Apireview([string]$ArtifactPath, [string]$packageName) {
[array]$files = Get-ChildItem -Path $ArtifactPath -Recurse -Filter "$packageName`_rust.json"

if (!$files) {
Write-Host "$($packageName) does not have api review json"
return $null
}
elseif ($files.Count -ne 1) {
Write-Host "$($artifactPath) should contain only one api review for $($packageName)"
Write-Host "No of files $($files.Count)"
return $null
}
$packages = @{
$files[0].Name = $files[0].FullName
}
return $packages
}
31 changes: 24 additions & 7 deletions eng/scripts/Pack-Crates.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ try {
Write-Host " $packageName ($type)"
}

function Create-ApiViewFile($package) {
$command = "cargo run --manifest-path $RepoRoot/eng/tools/generate_api_report/Cargo.toml -- --package $($package.name)"
Invoke-LoggedCommand $command -GroupOutput | Out-Host

$packagePath = Split-Path -Path $package.manifest_path -Parent

"$packagePath/review/$($package.name)_rust.json"
}

foreach ($package in $packages) {
Write-Host ""

Expand All @@ -210,16 +219,24 @@ try {
-Package $package

if ($OutputPath -and $package.OutputPackage) {
$packageOutputPath = "$OutputPath/$packageName"
$targetPackagePath = "$RepoRoot/target/package/$packageName-$packageVersion"
$sourcePath = "$RepoRoot/target/package/$packageName-$packageVersion"
$targetPath = "$OutputPath/$packageName"
$targetContentsPath = "$targetPath/contents"
$targetApiReviewFile = "$targetPath/$packageName`_rust.json"

if (Test-Path -Path $packageOutputPath) {
Remove-Item -Path $packageOutputPath -Recurse -Force
if (Test-Path -Path $targetContentsPath) {
Remove-Item -Path $targetContentsPath -Recurse -Force
}

Write-Host "Copying package '$packageName' to '$packageOutputPath'"
New-Item -ItemType Directory -Path $packageOutputPath -Force | Out-Null
Copy-Item -Path $targetPackagePath/* -Destination $packageOutputPath -Recurse -Exclude "Cargo.toml.orig"
Write-Host "Copying package '$packageName' to '$targetContentsPath'"
New-Item -ItemType Directory -Path $targetContentsPath -Force | Out-Null
Copy-Item -Path $sourcePath/* -Destination $targetContentsPath -Recurse -Exclude "Cargo.toml.orig"

Write-Host "Creating API review file"
$apiReviewFile = Create-ApiViewFile $package

Write-Host "Copying API review file to '$targetApiReviewFile'"
Copy-Item -Path $apiReviewFile -Destination $targetApiReviewFile -Force
}
}

Expand Down
Loading
Loading