summaryrefslogtreecommitdiffstats
path: root/xtask
diff options
context:
space:
mode:
authorhar7an <99636919+har7an@users.noreply.github.com>2023-08-28 06:24:27 +0000
committerGitHub <noreply@github.com>2023-08-28 06:24:27 +0000
commit8031d6bf645f2de10820d861292efb26358b4af1 (patch)
treeb406d1cafd3290ae17c27cc1607a9332eebc7664 /xtask
parentf6b08ddfaa4e1a12199df0ba317a140e4729efbf (diff)
xtask/pipeline: Fix publish task (#2711)
* 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.
Diffstat (limited to 'xtask')
-rw-r--r--xtask/Cargo.toml1
-rw-r--r--xtask/src/build.rs32
-rw-r--r--xtask/src/pipelines.rs45
3 files changed, 63 insertions, 15 deletions
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml
index 4a529f87c..2ab2b1c4c 100644
--- a/xtask/Cargo.toml
+++ b/xtask/Cargo.toml
@@ -11,3 +11,4 @@ xshell = "= 0.2.2"
xflags = "0.3.1"
which = "4.2"
toml = "0.5"
+prost-build = "0.11.9"
diff --git a/xtask/src/build.rs b/xtask/src/build.rs
index b77eda40d..4babad0c3 100644
--- a/xtask/src/build.rs
+++ b/xtask/src/build.rs
@@ -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!();
diff --git a/xtask/src/pipelines.rs b/xtask/src/pipelines.rs
index 9c82c6c0a..4195af763 100644
--- a/xtask/src/pipelines.rs
+++ b/xtask/src/pipelines.rs
@@ -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";
@@ -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;
}
}
}
@@ -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)?;