gh_workflow/
release_plz.rs

1//! A typed representation of the `release-plz` action in a GitHub workflow.
2//! Docs: <https://github.com/release-plz/action>
3use derive_setters::Setters;
4
5use crate::{Step, Use};
6
7#[derive(Clone, Default, Setters)]
8#[setters(strip_option, into)]
9pub struct Release {
10    /// The release-plz command to run. Accepted values: release-pr, release.
11    /// (By default it runs both commands).
12    pub command: Option<Command>,
13
14    /// Registry where the packages are stored. The registry name needs to be
15    /// present in the Cargo config. If unspecified, the publish field of the
16    /// package manifest is used. If the publish field is empty, crates.io is
17    /// used.
18    pub registry: Option<String>,
19
20    /// Path to the Cargo.toml of the project you want to update. Both Cargo
21    /// workspaces and single packages are supported. (Defaults to the root
22    /// directory).
23    pub manifest_path: Option<String>,
24
25    /// Release-plz version to use. E.g. 0.3.70. (Default: latest version).
26    pub version: Option<String>,
27
28    /// Release-plz config file location. (Defaults to release-plz.toml or
29    /// .release-plz.toml).
30    pub config: Option<String>,
31
32    /// Token used to publish to the cargo registry.
33    pub token: Option<String>,
34
35    /// Forge backend. Valid values: github, gitea. (Defaults to github).
36    pub backend: Option<Backend>,
37}
38
39#[derive(Clone)]
40pub enum Command {
41    /// Create a release PR.
42    /// See: <https://release-plz.ieni.dev/docs/usage/release-pr>
43    ReleasePR,
44
45    /// Release the package.
46    /// See: <https://release-plz.ieni.dev/docs/usage/release>
47    Release,
48}
49
50impl std::fmt::Display for Command {
51    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52        match self {
53            Command::ReleasePR => write!(f, "release-pr"),
54            Command::Release => write!(f, "release"),
55        }
56    }
57}
58
59#[derive(Clone)]
60pub enum Backend {
61    GitHub,
62    Gitea,
63}
64
65impl std::fmt::Display for Backend {
66    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
67        match self {
68            Backend::GitHub => write!(f, "github"),
69            Backend::Gitea => write!(f, "gitea"),
70        }
71    }
72}
73
74impl From<Release> for Step<Use> {
75    fn from(value: Release) -> Self {
76        let mut step = Step::new("Release Plz").uses("release-plz", "action", "v0.5");
77
78        if let Some(command) = value.command {
79            step = step.add_with(("command", command.to_string()));
80        }
81
82        if let Some(registry) = value.registry {
83            step = step.add_with(("registry", registry));
84        }
85
86        if let Some(manifest_path) = value.manifest_path {
87            step = step.add_with(("manifest_path", manifest_path));
88        }
89
90        if let Some(version) = value.version {
91            step = step.add_with(("version", version));
92        }
93
94        if let Some(config) = value.config {
95            step = step.add_with(("config", config));
96        }
97
98        if let Some(token) = value.token {
99            step = step.add_with(("token", token));
100        }
101
102        if let Some(backend) = value.backend {
103            step = step.add_with(("backend", backend.to_string()));
104        }
105
106        step
107    }
108}