Skip to content

Commit

Permalink
feat: add xtask.
Browse files Browse the repository at this point in the history
  • Loading branch information
yassun7010 committed Dec 27, 2024
1 parent 0757331 commit 9eb1577
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
xtask = "run --package xtask --bin xtask --"
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["crates/*"]
members = ["crates/*", "xtask"]

[workspace.package]
edition = "2021"
Expand All @@ -16,5 +16,5 @@ paste = "^1.0"
regex = "^1.6"
serde = "^1.0"
serde_json = "^1.0"
serde_valid_derive = { version = "1.0.1", path = "crates/serde_valid_derive" }
serde_valid_literal = { version = "1.0.1", path = "crates/serde_valid_literal" }
serde_valid_derive = { path = "crates/serde_valid_derive" }
serde_valid_literal = { path = "crates/serde_valid_literal" }
10 changes: 6 additions & 4 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

set -e

cd "$(dirname "$0")"
cd "$(dirname "$0")"/../

cd ../crates/serde_valid_derive
cargo xtask upgate-tags

cd "$(dirname "$0")"/../crates/serde_valid_derive
cargo publish

cd ../crates/serde_valid_literal
cd "$(dirname "$0")"/../crates/serde_valid_literal
cargo publish

# wait tarball package publishment
sleep 20

cd ../crates/serde_valid
cd "$(dirname "$0")"/../crates/serde_valid
cargo publish
12 changes: 12 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "xtask"
edition.workspace = true
version.workspace = true
license.workspace = true
repository.workspace = true
authors.workspace = true
keywords.workspace = true

[dependencies]
clap = { version = "4.5.23", features = ["derive"] }
toml_edit = "0.22.22"
1 change: 1 addition & 0 deletions xtask/src/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod update_tags;
22 changes: 22 additions & 0 deletions xtask/src/commands/update_tags.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use toml_edit::DocumentMut;

use crate::utils;

#[derive(clap::Args, Debug)]
pub struct Args {}

pub fn run(_args: Args) {
let project_root = utils::project_root();

let cargo_toml = std::fs::read_to_string(project_root.join("Cargo.toml")).unwrap();
let mut doc = cargo_toml.parse::<DocumentMut>().unwrap();

let version = doc["workspace"]["package"]["version"]
.clone()
.into_value()
.unwrap();
doc["workspace"]["dependencies"]["serde_valid_derive"]["version"] = version.clone().into();
doc["workspace"]["dependencies"]["serde_valid_literal"]["version"] = version.into();

std::fs::write(project_root.join("Cargo.toml"), doc.to_string()).unwrap();
}
18 changes: 18 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
mod commands;
mod utils;

use clap::Parser;

#[derive(Debug, clap::Parser)]
enum Args {
UpdateTags(commands::update_tags::Args),
}

fn main() {
let args = Args::parse();
match args {
Args::UpdateTags(args) => {
commands::update_tags::run(args);
}
}
}
8 changes: 8 additions & 0 deletions xtask/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::path::PathBuf;

/// Returns the path to the root directory of `tombi` project.
pub fn project_root() -> PathBuf {
let dir = std::env::var("CARGO_MANIFEST_DIR")
.unwrap_or_else(|_| env!("CARGO_MANIFEST_DIR").to_owned());
PathBuf::from(dir).parent().unwrap().to_owned()
}

0 comments on commit 9eb1577

Please sign in to comment.