1use std::{path::Path, process::Command};
4
5use gitcc_git::discover_repo;
6use itertools::Itertools;
7use serde::{Deserialize, Serialize};
8
9use crate::Error;
10
11#[derive(Debug, Serialize, Deserialize, Default)]
13pub struct ReleaseConfig {
14 pub bump_cmds: Vec<String>,
18}
19
20pub fn exec_bump_command(cmd: &str, version: &str) -> Result<(), Error> {
22 let cmd = cmd.replace("{{version}}", version);
23 let cmd_split = cmd.split(' ').collect::<Vec<_>>();
24 let program = cmd_split[0];
25 let args = cmd_split[1..].iter().copied().collect_vec();
26
27 let cmd_res = Command::new(program)
28 .args(&args)
29 .output()
30 .map_err(|err| Error::msg(format!("failed to execute '{cmd}': {err}").as_str()))?;
31
32 if !cmd_res.status.success() {
33 let stderr = String::from_utf8_lossy(&cmd_res.stderr);
34 return Err(Error::msg(
35 format!("failed to execute '{cmd}': {stderr}").as_str(),
36 ));
37 }
38 Ok(())
39}
40
41pub fn add_all_changes(cwd: &Path) -> Result<(), Error> {
43 let repo = discover_repo(cwd)?;
44 Ok(gitcc_git::add_all(&repo)?)
45}
46
47pub fn set_annotated_tag(cwd: &Path, tag: &str, message: &str) -> Result<(), Error> {
49 let repo = discover_repo(cwd)?;
50 Ok(gitcc_git::set_annotated_tag(&repo, tag, message)?)
51}
52
53pub fn push_with_tags(cwd: &Path) -> Result<(), Error> {
55 let repo = discover_repo(cwd)?;
56 Ok(gitcc_git::push_to_remote(&repo, "origin")?)
57}