Skip to content
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

xtask/pipeline: Fix publish task #2711

Merged
merged 6 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 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 xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ xshell = "= 0.2.2"
xflags = "0.3.1"
which = "4.2"
toml = "0.5"
prost-build = "0.11.9"
32 changes: 32 additions & 0 deletions xtask/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,38 @@ pub fn build(sh: &Shell, flags: flags::Build) -> anyhow::Result<()> {
}
}

// zellij-utils requires protobuf definition files to be present. Usually these are
// auto-generated with `build.rs`-files, but this is currently broken for us.
// See [this PR][1] for details.
//
// [1]: https://github.com/zellij-org/zellij/pull/2711#issuecomment-1695015818
{
let zellij_utils_basedir = crate::project_root().join("zellij-utils");
let _pd = sh.push_dir(zellij_utils_basedir);

let prost_asset_dir = sh.current_dir().join("assets").join("prost");
let protobuf_source_dir = sh.current_dir().join("src").join("plugin_api");
std::fs::create_dir_all(&prost_asset_dir).unwrap();

let mut prost = prost_build::Config::new();
prost.out_dir(prost_asset_dir);
prost.include_file("generated_plugin_api.rs");
let mut proto_files = vec![];
for entry in std::fs::read_dir(&protobuf_source_dir).unwrap() {
let entry_path = entry.unwrap().path();
if entry_path.is_file() {
if let Some(extension) = entry_path.extension() {
if extension == "proto" {
proto_files.push(entry_path.display().to_string())
}
}
}
}
prost
.compile_protos(&proto_files, &[protobuf_source_dir])
.unwrap();
}

let _pd = sh.push_dir(Path::new(crate_name));
// Tell the user where we are now
println!();
Expand Down
45 changes: 30 additions & 15 deletions xtask/src/pipelines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ pub fn dist(sh: &Shell, _flags: flags::Dist) -> anyhow::Result<()> {
.with_context(err_context)
}

/// Actions for the user to choose from to resolve publishing errors/conflicts.
enum UserAction {
Retry,
Abort,
Ignore,
}

/// Make a zellij release and publish all crates.
pub fn publish(sh: &Shell, flags: flags::Publish) -> anyhow::Result<()> {
let err_context = "failed to publish zellij";
Expand Down Expand Up @@ -333,38 +340,46 @@ pub fn publish(sh: &Shell, flags: flags::Publish) -> anyhow::Result<()> {
println!("Publishing crate '{crate_name}' failed with error:");
println!("{:?}", err);
println!();
println!("Retry? [y/n]");
println!("Please choose what to do: [r]etry/[a]bort/[i]gnore");

let stdin = std::io::stdin();
let mut buffer = String::new();
let retry: bool;
let action;

loop {
let mut buffer = String::new();
stdin.read_line(&mut buffer).context(err_context)?;

match buffer.trim_end() {
"y" | "Y" => {
retry = true;
"r" | "R" => {
action = UserAction::Retry;
break;
},
"n" | "N" => {
retry = false;
"a" | "A" => {
action = UserAction::Abort;
break;
},
"i" | "I" => {
action = UserAction::Ignore;
break;
},
_ => {
println!(" --> Unknown input '{buffer}', ignoring...");
println!();
println!("Retry? [y/n]");
println!("Please choose what to do: [r]etry/[a]bort/[i]gnore");
},
}
}

if retry {
continue;
} else {
println!("Aborting publish for crate '{crate_name}'");
return Err::<(), _>(err);
match action {
UserAction::Retry => continue,
UserAction::Ignore => break,
UserAction::Abort => {
eprintln!("Aborting publish for crate '{crate_name}'");
return Err::<(), _>(err);
},
}
} else {
// publish successful, continue to next crate
break;
}
}
}
Expand All @@ -380,7 +395,7 @@ pub fn publish(sh: &Shell, flags: flags::Publish) -> anyhow::Result<()> {
// program. When dry-running we need to undo the release commit first!
let result = closure();

if flags.dry_run {
if flags.dry_run && !skip_build {
cmd!(sh, "git reset --hard HEAD~1")
.run()
.context(err_context)?;
Expand Down
Loading