Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
update all relevant packages instead of hardcoding them
  • Loading branch information
joao-paulo-parity committed Oct 1, 2021
commit 701a8715f9666a762307157e098e15d88f863ed1
32 changes: 27 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ serde_yaml = "0.8"
thiserror = "1"
url = "2.1.1"
html-escape = "0.2.9"
cargo-lock = "^7.0.1"
71 changes: 50 additions & 21 deletions src/companion.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use regex::RegexBuilder;
use rocksdb::DB;
use snafu::ResultExt;
use std::{path::Path, time::Duration};
use std::{
collections::hash_set::HashSet, iter::FromIterator, path::Path,
time::Duration,
};
use tokio::time::delay_for;

use crate::{
Expand Down Expand Up @@ -171,29 +174,55 @@ async fn update_companion_repository(
return Err(e);
}

// `cargo update` should normally make changes to the lockfile with the latest SHAs from Github
run_cmd(
"cargo",
&[
"update",
"-vp",
if merge_done_in == MAIN_REPO_FOR_STAGING {
MAIN_REPO_FOR_STAGING
// Update the packages from 'merge_done_in' in the companion
let url_merge_was_done_in =
format!("https://github.com/{}/{}", owner, merge_done_in);
let cargo_lock_path = Path::new(&repo_dir).join("Cargo.lock");
let lockfile =
cargo_lock::Lockfile::load(cargo_lock_path).map_err(|err| {
Error::Message {
msg: format!(
"Failed to parse lockfile of {}: {:?}",
contributor_repo, err
),
}
})?;
let pkgs_in_companion: HashSet<&str> = {
HashSet::from_iter(lockfile.packages.iter().filter_map(|pkg| {
if let Some(src) = pkg.source.as_ref() {
if src.url().as_str() == url_merge_was_done_in {
Some(pkg.name.as_str())
} else {
None
}
} else {
"sp-io"
},
],
&repo_dir,
CommandMessage::Configured(CommandMessageConfiguration {
secrets_to_hide,
are_errors_silenced: false,
}),
)
.await?;
None
}
}))
};
if !pkgs_in_companion.is_empty() {
let args = {
let mut args = vec!["update", "-v"];
args.extend(
pkgs_in_companion.iter().map(|pkg| ["-p", pkg]).flatten(),
);
args
};
run_cmd(
"cargo",
&args,
&repo_dir,
CommandMessage::Configured(CommandMessageConfiguration {
secrets_to_hide,
are_errors_silenced: false,
}),
)
.await?;
}

// Check if `cargo update` resulted in any changes. If the master merge commit already had the
// latest lockfile then no changes might have been made.
let changes_after_update_output = run_cmd_with_output(
let output = run_cmd_with_output(
"git",
&["status", "--short"],
&repo_dir,
Expand All @@ -203,7 +232,7 @@ async fn update_companion_repository(
}),
)
.await?;
if !String::from_utf8_lossy(&(&changes_after_update_output).stdout[..])
if !String::from_utf8_lossy(&(&output).stdout[..])
.trim()
.is_empty()
{
Expand Down