Skip to content

Commit

Permalink
fix gen-rpc-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Feb 2, 2024
1 parent 3514d09 commit bac7bfb
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 38 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ doc-deps: ## Build the documentation for the local package and all dependencies.
.PHONY: gen-rpc-doc
gen-rpc-doc: submodule-init ## Generate rpc documentation
cd devtools/doc/rpc-gen && cargo build
cd docs/ckb_rpc_openrpc/ && git reset --hard && git clean -fd
./target/debug/ckb-rpc-gen rpc/README.md
./target/debug/ckb-rpc-gen --json
./target/debug/ckb-rpc-gen rpc/README.md

.PHONY: gen-hashes
gen-hashes: ## Generate docs/hashes.toml
Expand Down
28 changes: 16 additions & 12 deletions devtools/doc/rpc-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@ fn dump_openrpc_json() -> Result<(), Box<dyn std::error::Error>> {
"finished dump openrpc json for version: {:?} at dir: {:?}",
version, json_dir
);
// run git commit all changes before generate rpc readme
run_command("git", &["add", "."], Some(OPENRPC_DIR));
run_command(
"git",
&[
"commit",
"-m",
&format!("update openrpc json for version: {:?}", version),
],
Some(OPENRPC_DIR),
);
run_command("git", &["push"], Some(OPENRPC_DIR));

if is_git_repo_dirty() {
// run git commit all changes before generate rpc readme
eprintln!("commit OpenRPC changes to repo: {}", get_git_remote_url());
run_command("git", &["add", "."], Some(OPENRPC_DIR));
run_command(
"git",
&[
"commit",
"-m",
&format!("update openrpc json for version: {:?}", version),
],
Some(OPENRPC_DIR),
);
run_command("git", &["push"], Some(OPENRPC_DIR));
}
Ok(())
}

Expand Down
14 changes: 14 additions & 0 deletions devtools/doc/rpc-gen/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,17 @@ pub(crate) fn checkout_tag_branch(version: &str) {
run_command("git", &["checkout", "-b", version], dir);
}
}

pub(crate) fn is_git_repo_dirty() -> bool {
let res = run_command("git", &["status", "--porcelain"], Some(OPENRPC_DIR));
res.map(|s| !s.is_empty()).unwrap_or(false)
}

pub(crate) fn get_git_remote_url() -> String {
run_command(
"git",
&["config", "--get", "remote.origin.url"],
Some(OPENRPC_DIR),
)
.map_or("".to_string(), |s| s.trim().to_string())
}
2 changes: 1 addition & 1 deletion docs/ckb_rpc_openrpc
Loading

0 comments on commit bac7bfb

Please sign in to comment.