moon_config/workspace/pipeline_config.rs
1use crate::{config_enum, config_struct, is_false};
2use moon_common::Id;
3use schematic::Config;
4
5config_enum!(
6 /// Toggles the state of actions within the pipeline.
7 #[derive(Config)]
8 #[serde(untagged)]
9 pub enum PipelineActionSwitch {
10 Default,
11 Enabled(bool),
12 Only(Vec<Id>),
13 }
14);
15
16impl PipelineActionSwitch {
17 pub fn is_disabled(&self) -> bool {
18 match self {
19 Self::Default => false,
20 Self::Enabled(value) => !value,
21 Self::Only(list) => list.is_empty(),
22 }
23 }
24
25 pub fn is_enabled(&self, id: &Id) -> bool {
26 match self {
27 Self::Default => true,
28 Self::Enabled(value) => *value,
29 Self::Only(list) => list.contains(id),
30 }
31 }
32}
33
34impl From<bool> for PipelineActionSwitch {
35 fn from(value: bool) -> Self {
36 Self::Enabled(value)
37 }
38}
39
40config_struct!(
41 /// Configures aspects of the action pipeline.
42 #[derive(Config)]
43 pub struct PipelineConfig {
44 /// Automatically clean the cache after every task run.
45 /// @since 1.24.0
46 #[setting(default = true)]
47 pub auto_clean_cache: bool,
48
49 /// The lifetime in which task outputs will be cached.
50 #[setting(default = "7 days")]
51 pub cache_lifetime: String,
52
53 /// Automatically inherit color settings for all tasks being ran.
54 #[setting(default = true)]
55 pub inherit_colors_for_piped_tasks: bool,
56
57 /// Run the `InstallDependencies` actions for each running task
58 /// when changes to lockfiles and manifests are detected.
59 /// @since 1.34.0
60 #[setting(nested)]
61 pub install_dependencies: PipelineActionSwitch,
62
63 /// A threshold in milliseconds in which to force kill running child
64 /// processes after the pipeline receives an external signal. A value
65 /// of 0 will not kill the process and let them run to completion.
66 #[setting(default = 2000)]
67 pub kill_process_threshold: u32,
68
69 /// Logs the task's command and arguments when running the task.
70 #[serde(default, skip_serializing_if = "is_false")]
71 pub log_running_command: bool,
72
73 /// Run the `SyncProject` actions in the pipeline for each owning project
74 /// of a running task.
75 /// @since 1.34.0
76 #[setting(nested)]
77 pub sync_projects: PipelineActionSwitch,
78
79 /// When creating `SyncProject` actions, recursively create a `SyncProject`
80 /// action for each project dependency, and link them as a relationship.
81 /// @since 1.34.0
82 #[setting(default = true)]
83 pub sync_project_dependencies: bool,
84
85 /// Run the `SyncWorkspace` action before all actions in the pipeline.
86 /// @since 1.34.0
87 #[setting(default = true)]
88 pub sync_workspace: bool,
89 }
90);