more comments, sync check

Signed-off-by: Alex Chi <iskyzh@gmail.com>
This commit is contained in:
Alex Chi
2022-12-23 22:32:30 -05:00
parent 72cee6ac13
commit 3c50c81b69
20 changed files with 298 additions and 46 deletions

View File

@@ -17,6 +17,10 @@ enum Action {
Show,
/// Run CI jobs
Ci,
/// Sync starter repo and reference solution.
Sync,
/// Check starter code
Scheck,
}
/// Simple program to greet a person
@@ -36,6 +40,16 @@ fn switch_to_workspace_root() -> Result<()> {
Ok(())
}
fn switch_to_starter_root() -> Result<()> {
std::env::set_current_dir(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.ok_or_else(|| anyhow!("failed to find the workspace root"))?
.join("mini-lsm-starter"),
)?;
Ok(())
}
fn fmt() -> Result<()> {
println!("{}", style("cargo fmt").bold());
cmd!("cargo", "fmt").run()?;
@@ -78,6 +92,28 @@ fn serve_book() -> Result<()> {
Ok(())
}
fn sync() -> Result<()> {
cmd!("mkdir", "-p", "sync-tmp").run()?;
cmd!("cp", "-a", "mini-lsm-starter/", "sync-tmp/mini-lsm-starter").run()?;
let cargo_toml = "sync-tmp/mini-lsm-starter/Cargo.toml";
std::fs::write(
cargo_toml,
std::fs::read_to_string(cargo_toml)?.replace("mini-lsm-starter", "mini-lsm")
+ "\n[workspace]\n",
)?;
cmd!(
"cargo",
"semver-checks",
"check-release",
"--manifest-path",
cargo_toml,
"--baseline-root",
"mini-lsm/Cargo.toml",
)
.run()?;
Ok(())
}
fn main() -> Result<()> {
let args = Args::parse();
@@ -87,6 +123,8 @@ fn main() -> Result<()> {
cmd!("cargo", "install", "cargo-nextest", "--locked").run()?;
println!("{}", style("cargo install mdbook mdbook-toc").bold());
cmd!("cargo", "install", "mdbook", "mdbook-toc", "--locked").run()?;
println!("{}", style("cargo install cargo-semver-checks").bold());
cmd!("cargo", "install", "cargo-semver-checks", "--locked").run()?;
}
Action::Check => {
switch_to_workspace_root()?;
@@ -95,6 +133,13 @@ fn main() -> Result<()> {
test()?;
clippy()?;
}
Action::Scheck => {
switch_to_starter_root()?;
fmt()?;
check()?;
test()?;
clippy()?;
}
Action::Book => {
switch_to_workspace_root()?;
serve_book()?;
@@ -111,6 +156,10 @@ fn main() -> Result<()> {
println!("CARGO_MANIFEST_DIR={}", env!("CARGO_MANIFEST_DIR"));
println!("PWD={:?}", std::env::current_dir()?);
}
Action::Sync => {
switch_to_workspace_root()?;
sync()?;
}
}
Ok(())