Skip to content

Commit 75c522e

Browse files
authored
Add API View to build (Azure#2396)
* Add API View to build * Use toolchain defaulting instead explicit toolchain in each cargo call
1 parent e02feab commit 75c522e

File tree

16 files changed

+171
-107
lines changed

16 files changed

+171
-107
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eng/pipelines/templates/jobs/analyze.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ jobs:
3939
pwsh: true
4040
filePath: $(Build.SourcesDirectory)/eng/scripts/Analyze-Code.ps1
4141
arguments: >
42-
-Toolchain '$(Toolchain)'
4342
-PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo'
4443
-SkipPackageAnalysis:('$(NoPackagesChanged)' -eq 'true')
4544

eng/pipelines/templates/jobs/ci.tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ jobs:
7070
filePath: $(Build.SourcesDirectory)/eng/scripts/Test-Packages.ps1
7171
arguments: >
7272
-PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo'
73-
-Toolchain '$(Toolchain)'
7473
7574
- ${{ if eq(parameters.TestProxy, true) }}:
7675
- pwsh: |

eng/pipelines/templates/jobs/live.tests.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ jobs:
121121
$env:AZURESUBSCRIPTION_CLIENT_ID = $account.Id;
122122
$env:AZURESUBSCRIPTION_TENANT_ID = $account.Tenants;
123123
124-
Write-Host "./eng/scripts/Test-Packages.ps1 -PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo' -Toolchain '$(Toolchain)'"
125-
./eng/scripts/Test-Packages.ps1 -PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo' -Toolchain '$(Toolchain)'
124+
Write-Host "./eng/scripts/Test-Packages.ps1 -PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo'"
125+
./eng/scripts/Test-Packages.ps1 -PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo'
126126
workingDirectory: $(Build.SourcesDirectory)
127127
- ${{ else }}:
128128
- task: Powershell@2
@@ -139,7 +139,6 @@ jobs:
139139
filePath: $(Build.SourcesDirectory)/eng/scripts/Test-Packages.ps1
140140
arguments: >
141141
-PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo'
142-
-Toolchain '$(Toolchain)'
143142
144143
- ${{ parameters.PostSteps }}
145144

eng/pipelines/templates/jobs/pack.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ jobs:
3232
3333
- template: /eng/pipelines/templates/steps/use-rust.yml@self
3434
parameters:
35-
Toolchain: nightly
35+
WorkingDirectory: $(System.DefaultWorkingDirectory)/eng/tools/generate_api_report
36+
SetDefault: false
3637

3738
- template: /eng/pipelines/templates/steps/use-rust.yml@self
3839
parameters:
@@ -69,3 +70,9 @@ jobs:
6970
ArtifactPath: $(Build.ArtifactStagingDirectory)
7071
ArtifactName: ${{ parameters.PipelineArtifactName }}
7172
CustomCondition: and(succeededOrFailed(), ne(variables['NoPackagesChanged'],'true'))
73+
74+
- template: /eng/common/pipelines/templates/steps/create-apireview.yml
75+
parameters:
76+
Artifacts: ${{ parameters.Artifacts }}
77+
78+
- template: /eng/common/pipelines/templates/steps/detect-api-changes.yml

eng/pipelines/templates/stages/archetype-rust-release.yml

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ stages:
9393
$token = $env:CARGO_REGISTRY_TOKEN
9494
$crateName = '${{artifact.name}}'
9595
96-
$manifestPath = "$(Pipeline.Workspace)/drop/$crateName/Cargo.toml"
96+
$manifestPath = "$(Pipeline.Workspace)/drop/$crateName/contents/Cargo.toml"
9797
Write-Host "> cargo publish --manifest-path `"$manifestPath`""
9898
cargo publish --manifest-path $manifestPath
9999
if (!$?) {
@@ -112,23 +112,8 @@ stages:
112112
env:
113113
CARGO_REGISTRY_TOKEN: $(azure-sdk-cratesio-token)
114114
115-
# - job: CreateApiReview
116-
# displayName: "Api Review"
117-
# condition: and(succeeded(), ne(variables['Skip.CreateApiReview'], 'true'))
118-
# dependsOn: PublishPackage
119-
# steps:
120-
# - template: /eng/common/pipelines/templates/steps/create-apireview.yml
121-
# parameters:
122-
# ArtifactPath: $(Pipeline.Workspace)/${{parameters.PipelineArtifactName}}
123-
# Artifacts: ${{parameters.Artifacts}}
124-
# ConfigFileDir: $(Pipeline.Workspace)/${{parameters.PipelineArtifactName}}/PackageInfo
125-
# MarkPackageAsShipped: true
126-
# ArtifactName: ${{parameters.PipelineArtifactName}}
127-
# SourceRootPath: $(Pipeline.Workspace)/azure-sdk-for-rust
128-
# PackageName: ${{artifact.name}}
129-
130115
- job: UpdatePackageVersion
131-
displayName: "Update Package Versions"
116+
displayName: "API Review and Package Version Update"
132117
condition: and(succeeded(), ne(variables['Skip.UpdatePackageVersion'], 'true'))
133118
dependsOn: PublishPackage
134119
steps:
@@ -141,6 +126,20 @@ stages:
141126
parameters:
142127
Toolchain: nightly
143128

129+
- download: current
130+
displayName: Download ${{parameters.PipelineArtifactName}} artifact
131+
artifact: ${{parameters.PipelineArtifactName}}
132+
133+
- template: /eng/common/pipelines/templates/steps/create-apireview.yml
134+
parameters:
135+
ArtifactPath: $(Pipeline.Workspace)/${{parameters.PipelineArtifactName}}
136+
Artifacts: ${{parameters.Artifacts}}
137+
ConfigFileDir: $(Pipeline.Workspace)/${{parameters.PipelineArtifactName}}/PackageInfo
138+
MarkPackageAsShipped: true
139+
ArtifactName: ${{parameters.PipelineArtifactName}}
140+
SourceRootPath: $(System.DefaultWorkingDirectory)
141+
PackageName: ${{artifact.name}}
142+
144143
# Apply the version increment to each library, which updates the Cargo.toml and changelog files.
145144
- task: PowerShell@2
146145
displayName: Increment ${{artifact.name}} version
Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,100 @@
11
parameters:
22
- name: Toolchain
33
type: string
4-
default: stable
4+
default: active
5+
# Expexted values: 'stable', 'nightly', 'msrv', 'active' or a specific toolchain version
6+
# 'msrv' will read the MSRV from azure_core
7+
# 'active' will use the active toolchain for the working directory, which will be from rust-toolchain.toml, from a
8+
# folder override or the rustup default toolchain
59
- name: MaxAttempts
610
type: number
711
default: 3
12+
- name: WorkingDirectory
13+
type: string
14+
default: $(System.DefaultWorkingDirectory)
15+
- name: SetDefault
16+
type: boolean
17+
default: true
818

919
steps:
10-
- pwsh: |
11-
$toolchain = '${{ parameters.Toolchain }}'
12-
if ($toolchain -eq 'msrv') {
13-
Write-Host "Reading MSRV from azure_core"
14-
$toolchain = cargo read-manifest --manifest-path ./sdk/core/azure_core/Cargo.toml | ConvertFrom-Json | Select-Object -ExpandProperty rust_version
15-
}
20+
- pwsh: |
21+
$Toolchain = '${{ parameters.Toolchain }}'
22+
$MaxAttempts = ${{ parameters.MaxAttempts }}
23+
$SetDefault = $${{ parameters.SetDefault }}
24+
25+
function Invoke-LoggedCommand($command) {
26+
Write-Host "##[group]$command"
27+
Invoke-Expression $command
28+
Write-Host "##[endgroup]"
29+
if ($LASTEXITCODE -ne 0) {
30+
Write-Host "Command failed: $command"
31+
exit $LASTEXITCODE
32+
}
33+
}
34+
35+
if ($Toolchain -eq 'msrv') {
36+
Write-Host "Reading MSRV from azure_core"
37+
$toolchainArg = cargo read-manifest --manifest-path "$(System.DefaultWorkingDirectory)/sdk/core/azure_core/Cargo.toml"
38+
| ConvertFrom-Json
39+
| Select-Object -ExpandProperty rust_version
40+
}
41+
elseif ($Toolchain -eq 'active') {
42+
# You can't call 'rustup install' without a toolchain before rustup 1.28.0. If know we'll be doing that, make sure
43+
# we have the latest rustup installed
44+
45+
# Depending on the version of rustup currently installed, simply calling `rustup --version` will install the
46+
# active toolchain per rust-toolchain.toml if it's not already installed. We should check the rust version
47+
# outside of our repo's context to avoid any rustup-toolchain file influence.
48+
49+
Push-Location '$(Pipeline.Workspace)'
50+
Invoke-LoggedCommand "rustup --version" | Tee-Object -Variable rustupVersion
51+
52+
if ($rustupVersion -match 'rustup (\d+).(\d+).\d+') {
53+
$major = $matches[1]
54+
$minor = $matches[2]
55+
if ($major -lt 1 -or $minor -lt 28) {
56+
Invoke-LoggedCommand "rustup self update"
57+
}
58+
}
59+
Pop-Location
1660
17-
Write-Host "Setting Toolchain variable to $toolchain"
18-
Write-Host "##vso[task.setvariable variable=Toolchain]$toolchain"
61+
$toolchainArg = ''
62+
}
63+
else {
64+
$toolchainArg = $toolchain
65+
}
1966
20-
$attempts = 0
21-
$maxAttempts = ${{ parameters.MaxAttempts }}
67+
$attempts = 0
2268
23-
while ($true) {
69+
while ($true) {
2470
$attempts++
25-
Write-Host "> rustup toolchain install --no-self-update $toolchain"
26-
rustup toolchain install --no-self-update $toolchain
2771
28-
if ($?) { exit 0 }
72+
Invoke-LoggedCommand "rustup install --no-self-update $toolchainArg"
2973
30-
if ($attempts -lt $maxAttempts) {
31-
Write-Host "Failed to install $toolchain, attempt $attempts, retrying..."
32-
} else {
33-
Write-Host "Failed to install $toolchain after $attempts attempts."
34-
exit 1
74+
if ($?) { break }
75+
76+
if ($attempts -lt $MaxAttempts) {
77+
Write-Host "Install failed, attempt $attempts, retrying..."
78+
}
79+
else {
80+
Write-Host "Install failed after $attempts attempts."
81+
exit 1
3582
}
3683
3784
# Failures to update are usually caused by file locks in Windows.
3885
# Sleep for a few seconds to give the blocking process a chance to release the lock.
3986
Start-Sleep -Seconds 3
40-
}
87+
}
88+
89+
if ($SetDefault) {
90+
if ($Toolchain -eq 'active') {
91+
$toolchainArg = rustup show active-toolchain -v | Select-Object -First 1
92+
}
93+
94+
Invoke-LoggedCommand "rustup default $toolchainArg"
95+
}
96+
97+
Invoke-LoggedCommand "rustup show"
4198
42-
displayName: "Use Rust ${{ parameters.Toolchain }}"
99+
displayName: "Use Rust ${{ parameters.Toolchain }}"
100+
workingDirectory: ${{ parameters.WorkingDirectory }}

eng/scripts/Analyze-Code.ps1

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#Requires -Version 7.0
44
param(
5-
[string]$Toolchain = 'stable',
65
[string]$PackageInfoDirectory,
76
[switch]$CheckWasm = $true,
87
[switch]$SkipPackageAnalysis
@@ -15,26 +14,25 @@ Set-StrictMode -Version 2.0
1514

1615
Write-Host @"
1716
Analyzing code with
18-
Toolchain: '$Toolchain'
1917
RUSTFLAGS: '${env:RUSTFLAGS}'
2018
RUSTDOCFLAGS: '${env:RUSTDOCFLAGS}'
2119
"@
2220

2321
if ($CheckWasm) {
24-
Invoke-LoggedCommand "rustup target add --toolchain $Toolchain wasm32-unknown-unknown"
22+
Invoke-LoggedCommand "rustup target add wasm32-unknown-unknown"
2523
}
2624

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

29-
Invoke-LoggedCommand "cargo +$Toolchain fmt --all -- --check"
27+
Invoke-LoggedCommand "cargo fmt --all -- --check"
3028

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

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

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

3937
# Verify package dependencies
4038

eng/scripts/Language-Settings.ps1

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ function Get-AllPackageInfoFromRepo ([string] $ServiceDirectory) {
119119
function Get-rust-AdditionalValidationPackagesFromPackageSet ($packagesWithChanges, $diff, $allPackageProperties) {
120120
# if the change was in a service directory, but not in a package directory, test all the packages in the service directory
121121
[array]$serviceFiles = ($diff.ChangedFiles + $diff.DeletedFiles) | ForEach-Object { $_ -replace '\\', '/' } | Where-Object { $_ -match "^sdk/.+/" }
122+
122123
# remove files that target any specific package
123124
foreach ($package in $allPackageProperties) {
124125
$packagePathPattern = "^$( [Regex]::Escape($package.DirectoryPath.Replace('\', '/')) )/"
@@ -127,15 +128,14 @@ function Get-rust-AdditionalValidationPackagesFromPackageSet ($packagesWithChang
127128

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

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

134134
foreach ($package in $additionalPackages) {
135135
$package.IncludedForValidation = $true
136136
}
137137

138-
return $additionalPackages
138+
return $additionalPackages ?? @()
139139
}
140140

141141
function Get-rust-PackageInfoFromPackageFile([IO.FileInfo]$pkg, [string]$workingDirectory) {
@@ -167,3 +167,21 @@ function Get-rust-PackageInfoFromPackageFile([IO.FileInfo]$pkg, [string]$working
167167
ReadmeContent = $readmeContent
168168
}
169169
}
170+
171+
function Find-rust-Artifacts-For-Apireview([string]$ArtifactPath, [string]$packageName) {
172+
[array]$files = Get-ChildItem -Path $ArtifactPath -Recurse -Filter "$packageName.rust.json"
173+
174+
if (!$files) {
175+
Write-Host "$($packageName) does not have api review json"
176+
return $null
177+
}
178+
elseif ($files.Count -ne 1) {
179+
Write-Host "$($artifactPath) should contain only one api review for $($packageName)"
180+
Write-Host "Number of files $($files.Count)"
181+
return $null
182+
}
183+
$packages = @{
184+
$files[0].Name = $files[0].FullName
185+
}
186+
return $packages
187+
}

0 commit comments

Comments
 (0)