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 2dcb4fb
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 37 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ 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

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() && has_write_permission_to_git_repo() {
// 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
19 changes: 19 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,22 @@ 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 has_write_permission_to_git_repo() -> bool {
let res = run_command("git", &["push", "--dry-run"], Some(OPENRPC_DIR));
res.map(|s| !s.contains("fatal:")).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 2dcb4fb

Please sign in to comment.