Skip to content

Commit 4cf12d6

Browse files
committed
Improve version setting and lock file update
1 parent c50be2a commit 4cf12d6

File tree

5 files changed

+54
-72
lines changed

5 files changed

+54
-72
lines changed

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,25 +84,37 @@ stages:
8484
runOnce:
8585
deploy:
8686
steps:
87-
- template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
88-
parameters:
89-
skipCheckoutNone: true
90-
9187
- template: /eng/pipelines/templates/steps/use-rust.yml@self
9288
parameters:
9389
Toolchain: stable
9490

95-
- task: PowerShell@2
91+
- pwsh: |
92+
$additionalOwners = @('heaths', 'hallipr')
93+
$crateName = '${{artifact.name}}'
94+
95+
Write-Host "Publishing packae: '$crateName'"
96+
$manifestPath = "$(Pipeline.Workspace)/drop/$crateName/Cargo.toml"
97+
98+
$command = "cargo publish --locked --manifest-path '$manifestPath' --no-verify"
99+
100+
Write-Host "> $command"
101+
Invoke-Expression $command
102+
103+
if (!$?) {
104+
Write-Error "Failed to publish package: '$crateName'"
105+
exit 1
106+
}
107+
108+
$existingOwners = (cargo owner --list $crateName) -replace " \(.*", ""
109+
$missingOwners = $additionalOwners | Where-Object { $existingOwners -notcontains $_ }
110+
111+
foreach ($owner in $missingOwners) {
112+
Write-Host "> cargo owner --add $owner $crateName"
113+
cargo owner --add $owner $crateName
114+
}
96115
displayName: Publish Crate
97116
env:
98117
CARGO_REGISTRY_TOKEN: $(azure-sdk-cratesio-token)
99-
inputs:
100-
targetType: filePath
101-
filePath: $(Build.SourcesDirectory)/eng/scripts/Publish-Crates.ps1
102-
arguments: >
103-
-PackagesPath '$(Pipeline.Workspace)/drop'
104-
-CrateNames '${{artifact.name}}'
105-
-AdditionalOwners 'heaths','hallipr'
106118
107119
# - job: CreateApiReview
108120
# displayName: "Api Review"

eng/scripts/Pack-Crates.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Push-Location $RepoRoot
130130
try {
131131
[array]$packages = Get-PackagesToBuild
132132

133-
$command = "cargo +nightly -Zpackage-workspace package --allow-dirty"
133+
$command = "cargo +nightly -Zpackage-workspace package --allow-dirty --locked"
134134

135135
Write-Host "Building packages:"
136136
foreach ($package in $packages) {

eng/scripts/Publish-Crates.ps1

Lines changed: 0 additions & 40 deletions
This file was deleted.

eng/scripts/Update-PackageVersion.ps1

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,20 @@ if ($content -ne $updated) {
8282
Write-Host "Updated version in $tomlPath from $($pkgProperties.Version) to $packageSemVer."
8383

8484
Write-Host "Updaging dependencies in Cargo.toml files."
85-
Invoke-LoggedCommand "cargo +nightly -Zscript '$RepoRoot/eng/scripts/update-pathversions.rs' update" | Out-Null
85+
Invoke-LoggedCommand "cargo +nightly -Zscript '$RepoRoot/eng/scripts/update-pathversions.rs' update"
8686

8787
if ($env:SYSTEM_DEBUG -eq 'true') {
88-
Write-Host "##[group] $RepoRoot/Cargo.lock"
89-
Get-Content "$RepoRoot/Cargo.lock"
90-
Write-Host "##[endgroup]"
88+
New-Item -ItemType Directory -Path "$RepoRoot/target" -Force | Out-Null
89+
Get-Content "$RepoRoot/Cargo.lock" | Out-File -FilePath "$RepoRoot/target/Cargo.lock.before" -Encoding utf8
9190
}
9291

93-
Write-Host "Updating Cargo.lock using 'cargo metadata'."
94-
Invoke-LoggedCommand "cargo metadata --no-deps --format-version 1" | Out-Null
92+
Write-Host "Updating Cargo.lock."
93+
Invoke-LoggedCommand "cargo update --workspace"
9594

9695
if ($env:SYSTEM_DEBUG -eq 'true') {
97-
Write-Host "##[group] $RepoRoot/Cargo.lock"
98-
Get-Content "$RepoRoot/Cargo.lock"
99-
Write-Host "##[endgroup]"
96+
Get-Content "$RepoRoot/Cargo.lock" | Out-File -FilePath "$RepoRoot/target/Cargo.lock.after" -Encoding utf8
97+
Invoke-LoggedCommand "git diff --no-index -- $RepoRoot/target/Cargo.lock.before $RepoRoot/target/Cargo.lock.after" -AllowedExitCodes 0, 1
98+
$LASTEXITCODE = 0
10099
}
101100
}
102101
else {

eng/scripts/update-pathversions.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2424
.expect("requires 'add' or 'update' mode argument");
2525

2626
let script_root = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?);
27-
let repo_root = script_root.join("../../..").canonicalize()?;
27+
let repo_root = script_root.join("../..").canonicalize()?;
2828

2929
// find all Cargo.toml files in the repo_root directory
3030
let exclude_dirs = vec![
@@ -38,13 +38,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
3838

3939
for mut toml_file in toml_files {
4040
let should_add = add_mode && !toml_file.is_publish_disabled;
41-
42-
update_package_versions(toml_file.document.as_table_mut(), &package_versions, should_add);
41+
println!("Processing {}", toml_file.path.display());
42+
update_package_versions(toml_file.document.as_table_mut(), &package_versions, None, should_add);
4343

4444
// if the toml file has a workspace table, update the workspace table
4545
if let Some(workspace) = toml_file.document.get_mut("workspace") {
4646
if let Some(table) = workspace.as_table_mut() {
47-
update_package_versions(table, &package_versions, should_add);
47+
update_package_versions(table, &package_versions, Some("workspace"), should_add);
4848
}
4949
}
5050

@@ -57,6 +57,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
5757
}
5858

5959
fn load_cargo_toml_files(repo_root: &PathBuf, exclude_dirs: &Vec<PathBuf>) -> Result<Vec<TomlInfo>, Box<dyn Error>> {
60+
println!("Loading Cargo.toml files in {}", repo_root.display());
6061
let mut toml_paths = Vec::new();
6162
find_cargo_toml_files(repo_root, exclude_dirs, &mut toml_paths)?;
6263

@@ -109,7 +110,7 @@ fn get_package_versions(toml_files: &Vec<TomlInfo>) -> Vec<(String, String, bool
109110
package_versions
110111
}
111112

112-
fn update_package_versions(toml: &mut Table, package_versions: &Vec<(String, String, bool)>, add: bool) {
113+
fn update_package_versions(toml: &mut Table, package_versions: &Vec<(String, String, bool)>, prefix: Option<&str>, add: bool) {
113114
// for each dependency table, for each package in package_versions
114115
// if the package is in the dependency table
115116
// if the dependency has both path and version properties, update the version property
@@ -121,16 +122,26 @@ fn update_package_versions(toml: &mut Table, package_versions: &Vec<(String, Str
121122
let dependency_tables = get_dependency_tables(toml);
122123

123124
for (table_name, table) in dependency_tables {
125+
let table_display_name = if prefix.is_some() {
126+
format!("{}.{}", prefix.unwrap(), table_name)
127+
} else {
128+
table_name.clone()
129+
};
124130
for (package, version, is_publish_disabled) in package_versions {
125131
if let Some(dependency) = table.get_mut(package) {
126132
// azure_idenentity will only be a transitive dev-dependency
127133
let should_add = add && table_name != "dev-dependencies" && !is_publish_disabled && package != "azure_identity";
128134

129-
let has_path_property = dependency.get("path").is_some();
130-
let has_version_property = dependency.get("version").is_some();
131-
132-
if has_path_property && (has_version_property || should_add) {
133-
dependency["version"] = value(version);
135+
if dependency.get("path").is_some() {
136+
if let Some(current_version) = dependency.get("version") {
137+
if current_version.as_str() != Some(version) {
138+
dependency["version"] = value(version);
139+
println!(" Updating {table_display_name}.{package} to {version}");
140+
}
141+
} else if should_add {
142+
dependency["version"] = value(version);
143+
println!(" Adding {table_display_name}.{package} version {version}");
144+
}
134145
}
135146
}
136147
}

0 commit comments

Comments
 (0)