diff --git a/float-pigment-css/Cargo.toml b/float-pigment-css/Cargo.toml index 48023b1..822744f 100644 --- a/float-pigment-css/Cargo.toml +++ b/float-pigment-css/Cargo.toml @@ -24,15 +24,11 @@ name = "float_pigment_css_update_version" path = "compile_cache/bin/main.rs" required-features = ["compile_cache"] -[[bin]] -name = "publish" -path = "compile_cache/bin/publish.rs" -required-features = ["compile_cache"] - -[[bin]] +[[test]] name = "bincode_test" path = "tests/compatibility/main.rs" required-features = ["compatibility_test"] +test = false [[bench]] name = "parse" diff --git a/float-pigment-css/README.md b/float-pigment-css/README.md index 50cd241..30f1454 100644 --- a/float-pigment-css/README.md +++ b/float-pigment-css/README.md @@ -63,10 +63,5 @@ struct Hello { } ``` -To update the `compile_cache`, this steps should be followed: - -* Make sure the HEAD have the published commit merged. -* Update the cargo version of float-pigment-css. -* Run `cargo run --bin float_pigment_css_update_version`. -* The `compile_cache/publish/version.toml` should be updated. -* Run `cargo run --bin publish` (it will git-tag and git-push). +To update the `compile_cache`, run `cargo run --bin float_pigment_css_update_version`. +(This will be automatically done by the publish script.) diff --git a/float-pigment-css/compile_cache/bin/publish.rs b/float-pigment-css/compile_cache/bin/publish.rs deleted file mode 100644 index c9dad2b..0000000 --- a/float-pigment-css/compile_cache/bin/publish.rs +++ /dev/null @@ -1,191 +0,0 @@ -use colorful::Color; -use colorful::Colorful; - -use std::env; -use std::{path::PathBuf, process::Command}; - -const PUBLISH_BRANCH: &str = "master"; - -fn get_root_path() -> String { - let mut pb = PathBuf::new(); - pb.push(std::env::var("CARGO_MANIFEST_DIR").unwrap()); - pb.push("../"); - pb.to_str().unwrap().to_string() -} - -fn generate_c_header() { - println!("{}", "generate C-header: waiting...".color(Color::Yellow)); - let root = get_root_path(); - let _ret = Command::new("cargo") - .arg("run") - .arg("--bin") - .arg("float_pigment_css_cpp_binding_gen_tool") - .arg("--features") - .arg("build-cpp-header") - .current_dir(root) - .output() - .expect("failed to generate C Header."); - println!("{}", "generate C-header: done!".color(Color::Green)) -} - -struct GitCommand { - pub logger: bool, -} - -impl GitCommand { - fn new() -> Self { - Self { logger: false } - } - fn set_logger(&mut self, v: bool) { - self.logger = v; - } - fn git_branch_checker(&self, target_branch: &str) { - let output = Command::new("git") - .arg("branch") - .arg("--show-current") - .output() - .expect("git branch checker error"); - let ret = String::from_utf8_lossy(&output.stdout).to_string(); - let ver = ret.replace('\n', ""); - println!("current branch: {}", ver.clone().color(Color::Green)); - if ver != target_branch { - println!( - "{}", - format!( - "publish must on branch {}! current branch: {}", - target_branch, ver - ) - .color(Color::Red) - ); - panic!(); - } - } - - fn git_commit(&self, commit: &str) { - println!("{}", "git commit: waiting...".color(Color::Yellow)); - let root = get_root_path(); - let ret = Command::new("git") - .arg("commit") - .arg("-m") - .arg(commit) - .current_dir(root) - .output() - .expect("failed to git commit"); - if self.logger { - println!( - "{}", - String::from_utf8(ret.stdout).unwrap().color(Color::Yellow) - ); - } - println!("{}", "git commit: done!".color(Color::Green)); - } - - fn git_add(&self) { - println!("{}", "git add: waiting...".color(Color::Yellow)); - let root = get_root_path(); - let ret = Command::new("git") - .arg("add") - .arg(".") - .current_dir(root) - .output() - .expect("failed to git add ."); - if self.logger { - println!( - "{}", - String::from_utf8(ret.stdout).unwrap().color(Color::Yellow) - ); - } - println!("{}", "git add: done!".color(Color::Green)); - } - - fn git_tag(&self, tag: &str) { - println!("{}", "git tag: waiting...".color(Color::Green)); - let root = get_root_path(); - let ret = Command::new("git") - .arg("tag") - .arg(tag) - .current_dir(root) - .output() - .expect("failed to git tag"); - if self.logger { - println!( - "{}", - String::from_utf8(ret.stdout).unwrap().color(Color::Yellow) - ); - } - println!("{}", format!("tag: {}", tag).color(Color::Red)); - println!("{}", "git tag: done!".color(Color::Green)); - } - - fn git_push(&self, tag: &str) { - println!( - "[{}] {}", - tag.color(Color::Red), - "git push: waiting...".color(Color::Yellow) - ); - let root = get_root_path(); - // tag - let ret = Command::new("git") - .arg("push") - .arg("--set-upstream") - .arg("origin") - .arg(tag) - .current_dir(root.clone()) - .output() - .expect("failed to git push"); - if self.logger { - println!( - "{}", - String::from_utf8(ret.stdout).unwrap().color(Color::Yellow) - ); - } - println!( - "[{}] {}", - tag.color(Color::Red), - "git push: done!".color(Color::Green) - ); - println!( - "[{}] {}", - PUBLISH_BRANCH.color(Color::Red), - "git push: waiting...".color(Color::Yellow) - ); - // publish branch - let ret = Command::new("git") - .arg("push") - .arg("--set-upstream") - .arg("origin") - .arg(PUBLISH_BRANCH) - .current_dir(root) - .output() - .expect("failed to git push"); - if self.logger { - println!( - "{}", - String::from_utf8(ret.stdout).unwrap().color(Color::Yellow) - ); - } - println!( - "[{}] {}", - PUBLISH_BRANCH.color(Color::Red), - "git push: done!".color(Color::Green) - ); - } -} - -fn main() { - // generate C-Header - #[allow(clippy::needless_collect)] - let args: Vec = env::args().collect(); - let mut git_cmd = GitCommand::new(); - if args.contains(&"--logger".to_string()) { - git_cmd.set_logger(true); - } - git_cmd.git_branch_checker(PUBLISH_BRANCH); - generate_c_header(); - git_cmd.git_add(); - let tag = format!("v{:?}", std::env::var("CARGO_PKG_VERSION").unwrap()); - let tag = tag.replace('"', ""); - git_cmd.git_commit(&tag); - git_cmd.git_tag(&tag); - git_cmd.git_push(&tag); -} diff --git a/publish.sh b/publish.sh index e5d74f0..4c27f30 100755 --- a/publish.sh +++ b/publish.sh @@ -57,7 +57,7 @@ if test -z '$(git status --porcelain)'; then echo 'Git status OK.' # update compile cache for float-pigment-css - if cargo run --bin float_pigment_css_update_version --features compile_cache; then + if cargo run --bin float_pigment_css_update_version; then echo 'Compile cache for float-pigment-css updated.' else echo 'Failed to update compile cache for float-pigment-css! Abort'