verctl_core/config/steps.rs
1//! Declarative steps, lifecycle attachment points, and declared ecosystems.
2
3use garde::Validate;
4use serde::Deserialize;
5
6use super::Config;
7use super::validate::non_empty_hook_argv;
8use super::validate_steps::inside_the_repo_str;
9
10/// One named extension step declared under `steps` in `.ctl/ver.yaml`.
11///
12/// Exactly one of `task` or `run` must be set. `task` executes as
13/// `mise run --raw <task>`; `run` executes an argv directly without a shell.
14/// Inputs reach the command through `VERCTL_PLAN` and, for package-scoped
15/// steps, `VERCTL_PACKAGE`, `VERCTL_VERSION`, `VERCTL_PREVIOUS_VERSION`,
16/// `VERCTL_TAG`, and `VERCTL_RELEASE_COMMIT`.
17#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Validate)]
18#[serde(deny_unknown_fields)]
19#[garde(context(Config as config))]
20#[garde(allow_unvalidated)]
21#[non_exhaustive]
22pub struct StepSpec {
23 /// A mise task name, executed as `mise run --raw <task>`. Omit when `run`
24 /// is set.
25 pub task: Option<String>,
26 /// Direct argv to execute without a shell. Omit when `task` is set.
27 pub run: Option<Vec<String>>,
28 /// Paths relative to the repository root that this step may create,
29 /// modify, or remove. Omit for a step that writes nothing.
30 #[serde(default)]
31 #[garde(inner(custom(inside_the_repo_str)))]
32 pub writes: Vec<String>,
33 /// Postcondition check argv evaluated before a `released` step runs; exit
34 /// zero means the step already completed and is skipped. Omit when not
35 /// attached to `released`.
36 #[serde(default)]
37 #[garde(inner(custom(non_empty_hook_argv)))]
38 pub check: Option<Vec<String>>,
39}
40
41impl StepSpec {
42 /// Command argv executed when this step runs (`mise run --raw <task>` or
43 /// its declared `run` argv).
44 #[must_use]
45 pub fn argv(&self) -> Vec<String> {
46 if let Some(task) = &self.task {
47 return vec![
48 "mise".to_owned(),
49 "run".to_owned(),
50 "--raw".to_owned(),
51 task.clone(),
52 ];
53 }
54 self.run.clone().unwrap_or_default()
55 }
56
57 /// Space-joined command label for reports and error messages.
58 #[must_use]
59 pub fn command(&self) -> String {
60 self.argv().join(" ")
61 }
62}
63
64/// Lifecycle points where named steps attach, either run-wide under top-level
65/// `at` or per package under `packages[].at`.
66#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize)]
67#[serde(deny_unknown_fields)]
68#[non_exhaustive]
69pub struct AttachPoints {
70 /// Steps run during `verctl version` after manifests and lockfiles, before
71 /// served files render. May change only their declared `writes`.
72 #[serde(default)]
73 pub version: Vec<String>,
74 /// Steps run during `verctl release` before any publish, tag, or Release
75 /// side effect. May change nothing; a non-zero exit stops the release.
76 #[serde(default)]
77 pub verify: Vec<String>,
78 /// Steps run during `verctl release` after finalization. Every step listed
79 /// here must declare `check` so reruns skip completed work.
80 #[serde(default)]
81 pub released: Vec<String>,
82}
83
84impl AttachPoints {
85 /// Whether no lifecycle point lists any step.
86 #[must_use]
87 pub fn is_empty(&self) -> bool {
88 self.version.is_empty() && self.verify.is_empty() && self.released.is_empty()
89 }
90
91 /// Every step name attached across `version`, `verify`, and `released`.
92 pub fn all_names(&self) -> impl Iterator<Item = &str> {
93 self.version
94 .iter()
95 .chain(&self.verify)
96 .chain(&self.released)
97 .map(String::as_str)
98 }
99}
100
101/// A repository-declared ecosystem whose release blocks are implemented by
102/// named steps under `steps`.
103///
104/// Built-in ecosystems (`cargo` and `bun`) are selected by manifest file name
105/// unless a package names an ecosystem here. Any other manifest names an
106/// ecosystem or configures its own driver and publisher.
107#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize)]
108#[serde(deny_unknown_fields)]
109#[non_exhaustive]
110pub struct EcosystemSpec {
111 /// Named step implementing the Manifest block. Omit when a manifest driver
112 /// reads and writes the version directly.
113 pub manifest: Option<String>,
114 /// Named step implementing the Lockfile block. Must list its lockfile path
115 /// in `writes`.
116 pub lockfile: Option<String>,
117 /// Named step implementing the Artifact block. Omit when unused.
118 pub artifact: Option<String>,
119 /// Named step implementing the publish upload block. Omit when the package
120 /// releases on GitHub only or declares its own publish block.
121 pub publish: Option<String>,
122 /// Named step querying whether a package version is already published;
123 /// exit zero means already listed. Omit when unchecked.
124 pub registry: Option<String>,
125}
126
127impl EcosystemSpec {
128 /// Every step name referenced by any block of this ecosystem.
129 pub fn step_names(&self) -> impl Iterator<Item = &str> {
130 [
131 self.manifest.as_deref(),
132 self.lockfile.as_deref(),
133 self.artifact.as_deref(),
134 self.publish.as_deref(),
135 self.registry.as_deref(),
136 ]
137 .into_iter()
138 .flatten()
139 }
140}