Skip to content

Commit

Permalink
xtask/pipeline: Fix publish task (#2711)
Browse files Browse the repository at this point in the history
* xtask/pipeline: Fix publish task

which was previously stuck in an infinite loop after successfully
publishing a crate. The error originated in the code only checking for
error conditions but not breaking out of the inner infinite loop in case
of success.

* xtask: Improve publish failure UX

by offering the user more actions to choose from when an error occured.

* utils/assets: Add generated prost files to assets

to make sure they're available at build time and are picked up by all
components. It seems we hit some strange bug with the build script
where, when running `cargo publish --dry-run` the build script **is
not** run before regularly compiling zellij-utils. This shouldn't happen
according to the docs, but I cannot explain what's causing it. So we're
using this as a workaround for now to make a smooth release.

* xtask: Prevent accidental git commit deletion

when dry-running a publish.

* utils: Add comments to protobuf-related code

to explain why these changes were performed. The comments all include a
link to an issue comment explaining the situation in greater detail.

* xtask: Build protobuf definitions

when building any part of the project, similar to how we build the
plugins when required. This should ensure that all crates built through
`cargo xtask` (which is the officially supported build method) will
receive up-to-date protobuf definitions.
  • Loading branch information
har7an authored Aug 28, 2023
1 parent f6b08dd commit 8031d6b
Show file tree
Hide file tree
Showing 19 changed files with 2,181 additions and 34 deletions.
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

0 comments on commit 8031d6b

Please sign in to comment.