Skip to content

Commit bac7bfb

Browse files
committed
fix gen-rpc-doc
1 parent 3514d09 commit bac7bfb

File tree

6 files changed

+55
-38
lines changed

6 files changed

+55
-38
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,8 @@ doc-deps: ## Build the documentation for the local package and all dependencies.
104104
.PHONY: gen-rpc-doc
105105
gen-rpc-doc: submodule-init ## Generate rpc documentation
106106
cd devtools/doc/rpc-gen && cargo build
107-
cd docs/ckb_rpc_openrpc/ && git reset --hard && git clean -fd
108-
./target/debug/ckb-rpc-gen rpc/README.md
109107
./target/debug/ckb-rpc-gen --json
108+
./target/debug/ckb-rpc-gen rpc/README.md
110109

111110
.PHONY: gen-hashes
112111
gen-hashes: ## Generate docs/hashes.toml

devtools/doc/rpc-gen/src/main.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,22 @@ fn dump_openrpc_json() -> Result<(), Box<dyn std::error::Error>> {
2222
"finished dump openrpc json for version: {:?} at dir: {:?}",
2323
version, json_dir
2424
);
25-
// run git commit all changes before generate rpc readme
26-
run_command("git", &["add", "."], Some(OPENRPC_DIR));
27-
run_command(
28-
"git",
29-
&[
30-
"commit",
31-
"-m",
32-
&format!("update openrpc json for version: {:?}", version),
33-
],
34-
Some(OPENRPC_DIR),
35-
);
36-
run_command("git", &["push"], Some(OPENRPC_DIR));
25+
26+
if is_git_repo_dirty() {
27+
// run git commit all changes before generate rpc readme
28+
eprintln!("commit OpenRPC changes to repo: {}", get_git_remote_url());
29+
run_command("git", &["add", "."], Some(OPENRPC_DIR));
30+
run_command(
31+
"git",
32+
&[
33+
"commit",
34+
"-m",
35+
&format!("update openrpc json for version: {:?}", version),
36+
],
37+
Some(OPENRPC_DIR),
38+
);
39+
run_command("git", &["push"], Some(OPENRPC_DIR));
40+
}
3741
Ok(())
3842
}
3943

devtools/doc/rpc-gen/src/utils.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,17 @@ pub(crate) fn checkout_tag_branch(version: &str) {
6767
run_command("git", &["checkout", "-b", version], dir);
6868
}
6969
}
70+
71+
pub(crate) fn is_git_repo_dirty() -> bool {
72+
let res = run_command("git", &["status", "--porcelain"], Some(OPENRPC_DIR));
73+
res.map(|s| !s.is_empty()).unwrap_or(false)
74+
}
75+
76+
pub(crate) fn get_git_remote_url() -> String {
77+
run_command(
78+
"git",
79+
&["config", "--get", "remote.origin.url"],
80+
Some(OPENRPC_DIR),
81+
)
82+
.map_or("".to_string(), |s| s.trim().to_string())
83+
}

0 commit comments

Comments
 (0)