Skip to content

Commit e030e5b

Browse files
committed
git tag in publishing script
1 parent 7f351cb commit e030e5b

File tree

5 files changed

+37
-17
lines changed

5 files changed

+37
-17
lines changed

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ resolver = "2"
44

55
[workspace.package]
66
rust-version = "1.81"
7-
version = "0.21.0"
7+
version = "0.21.1"
88

99
[workspace.dependencies]
10-
garde = { path = "garde", version = "=0.21.0", default-features = false }
11-
garde_derive = { path = "garde_derive", version = "=0.21.0", default-features = false }
10+
garde = { path = "garde", version = "=0.21.1", default-features = false }
11+
garde_derive = { path = "garde_derive", version = "=0.21.1", default-features = false }
1212

1313
[profile.dev.package]
1414
insta = { opt-level = 3 }

xtask/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn main() -> ExitCode {
2929
match try_main() {
3030
Ok(()) => ExitCode::SUCCESS,
3131
Err(e) => {
32-
let _ = write!(stderr(), "{e}");
32+
let _ = writeln!(stderr(), "{e}");
3333
ExitCode::FAILURE
3434
}
3535
}

xtask/src/task/publish.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use argp::FromArgs;
22

3-
use crate::util::{cargo, CommandExt as _};
3+
use crate::util::get_workspace_manifest;
4+
use crate::util::{cargo, git, CommandExt as _};
45
use crate::Result;
56

67
#[derive(FromArgs)]
@@ -12,6 +13,18 @@ impl Publish {
1213
cargo("publish").with_args(["-p", "garde_derive"]).run()?;
1314
cargo("publish").with_args(["-p", "garde"]).run()?;
1415

16+
let version: semver::Version = get_workspace_manifest()?["workspace"]["package"]["version"]
17+
.as_str()
18+
.unwrap()
19+
.parse()?;
20+
21+
// push tag
22+
git("tag").with_arg(format!("v{}", version)).run()?;
23+
git("push")
24+
.with_arg("origin")
25+
.with_arg(format!("v{}", version))
26+
.run()?;
27+
1528
Ok(())
1629
}
1730
}

xtask/src/task/version.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
use std::path::Path;
2-
31
use argp::FromArgs;
4-
use toml_edit::DocumentMut;
52

6-
use crate::util::{cargo, CommandExt as _};
3+
use crate::util::{cargo, get_workspace_manifest, get_workspace_manifest_path, CommandExt as _};
74
use crate::Result;
85

96
#[derive(FromArgs)]
@@ -63,12 +60,7 @@ impl argp::FromArgValue for Bump {
6360

6461
impl Version {
6562
pub fn run(self) -> Result {
66-
let cargo_toml_path = Path::new(env!("CARGO_MANIFEST_DIR"))
67-
.parent()
68-
.unwrap()
69-
.join("Cargo.toml");
70-
let mut cargo_toml = std::fs::read_to_string(&cargo_toml_path)?.parse::<DocumentMut>()?;
71-
63+
let mut cargo_toml = get_workspace_manifest()?;
7264
let workspace = &mut cargo_toml["workspace"];
7365

7466
let version = workspace["package"]["version"]
@@ -106,7 +98,7 @@ impl Version {
10698
}
10799
}
108100

109-
std::fs::write(&cargo_toml_path, cargo_toml.to_string())?;
101+
std::fs::write(get_workspace_manifest_path(), cargo_toml.to_string())?;
110102

111103
Ok(())
112104
}

xtask/src/util.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
use std::ffi::OsStr;
22
use std::path::Path;
3+
use std::path::PathBuf;
34
use std::process::{Command, Stdio};
45

56
use anyhow::anyhow;
7+
use toml_edit::DocumentMut;
68

79
use crate::Result;
810

911
pub fn project_root() -> &'static Path {
10-
Path::new(env!("CARGO_MANIFEST_DIR"))
12+
Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap()
13+
}
14+
15+
pub fn get_workspace_manifest_path() -> PathBuf {
16+
project_root().join("Cargo.toml")
17+
}
18+
19+
pub fn get_workspace_manifest() -> Result<DocumentMut> {
20+
let cargo_toml_path = project_root().join("Cargo.toml");
21+
Ok(std::fs::read_to_string(&cargo_toml_path)?.parse::<DocumentMut>()?)
22+
}
23+
24+
pub fn git(cmd: &str) -> Command {
25+
Command::new("git").with_arg(cmd)
1126
}
1227

1328
pub fn rustup(cmd: &str) -> Command {

0 commit comments

Comments
 (0)