Skip to content

Commit 7cb7c83

Browse files
committed
Add setting.
1 parent 5d1fcc5 commit 7cb7c83

9 files changed

Lines changed: 100 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
- Added extensive testing to account for edge cases.
2525
- When the server doesn't support the configured compression, it will now default to "identity"
2626
(uncompressed) instead of disabling the cache entirely.
27+
- **Tasks**
28+
- Added a `taskOptions` setting to `moon.*` that allows you to configure default task options for
29+
all tasks within the current project, which can be overridden per task.
2730
- **VCS**
2831
- Hardened all executed Git commands: revisions are validated against argument injection,
2932
credential prompts now fail immediately instead of hanging, and the fsmonitor daemon is now

crates/config/src/project_config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::project::*;
22
use crate::shapes::Input;
33
use crate::task_config::{EnvMap, TaskConfig};
4+
use crate::task_options_config::{PartialTaskOptionsConfig, TaskOptionsConfig};
45
use crate::{config_enum, config_struct, config_unit_enum};
56
use moon_common::Id;
67
use rustc_hash::FxHashMap;
@@ -163,6 +164,12 @@ config_struct!(
163164
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
164165
pub tasks: BTreeMap<Id, TaskConfig>,
165166

167+
/// Shared task options for all tasks. Can be overriden per task.
168+
/// @since 2.4.0
169+
#[setting(nested)]
170+
#[serde(skip_serializing_if = "Option::is_none")]
171+
pub task_options: Option<TaskOptionsConfig>,
172+
166173
/// Overrides top-level toolchain settings, scoped to this project.
167174
#[setting(nested)]
168175
pub toolchains: ProjectToolchainsConfig,

crates/config/src/workspace/cache_config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ config_struct!(
88
/// Maximum total size of the local cache, for example "10gb" or
99
/// "512mib". When exceeded, the least recently used cached task outputs
1010
/// are evicted. Unlimited when unset.
11+
/// @since 2.4.0
1112
pub max_size: Option<String>,
1213

1314
// /// Byte threshold above which to use memory-mapped I/O for hashing.
@@ -16,6 +17,7 @@ config_struct!(
1617
// pub mmap_threshold: u64,
1718
/// Verify hash on every read. When enabled, reads are slower
1819
/// but detect on-disk corruption.
20+
/// @since 2.3.0
1921
pub verify_integrity: bool,
2022
}
2123
);
@@ -25,6 +27,7 @@ config_struct!(
2527
#[derive(Config)]
2628
pub struct CacheConfig {
2729
/// Configures aspects of the content-addressable storage (CAS) cache.
30+
/// @since 2.3.0
2831
#[setting(nested)]
2932
pub cas: CacheCasConfig,
3033
}

crates/config/src/workspace/experiments_config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@ config_struct!(
66
#[derive(Config)]
77
pub struct ExperimentsConfig {
88
/// Track and determine affected projects and tasks asynchronously.
9+
/// @since 2.2.0
910
#[setting(env = "MOON_EXPERIMENT_ASYNC_AFFECTED_TRACKING", parse_env = env::parse_bool)]
1011
pub async_affected_tracking: bool,
1112

1213
/// Build the project and task graphs asynchronously.
14+
/// @since 2.2.0
1315
#[setting(env = "MOON_EXPERIMENT_ASYNC_GRAPH_BUILDING", parse_env = env::parse_bool)]
1416
pub async_graph_building: bool,
1517

1618
/// Store task outputs in a local CAS (content-addressable storage) cache.
19+
/// @since 2.3.0
1720
#[setting(env = "MOON_EXPERIMENT_CAS_OUTPUTS_CACHE", parse_env = env::parse_bool)]
1821
pub cas_outputs_cache: bool,
1922

2023
/// Use native file hashing instead of using the VCS.
24+
/// @since 2.3.0
2125
#[setting(env = "MOON_EXPERIMENT_NATIVE_FILE_HASHING", parse_env = env::parse_bool)]
2226
pub native_file_hashing: bool,
2327
}

crates/task-builder/src/tasks_builder.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ pub struct TasksBuilder<'proj> {
111111
// Tasks to merge and build
112112
task_ids: FxHashSet<&'proj Id>,
113113
global_tasks: FxHashMap<&'proj Id, Vec<&'proj TaskConfig>>,
114-
global_task_options: Vec<&'proj TaskOptionsConfig>,
115114
local_tasks: FxHashMap<&'proj Id, &'proj TaskConfig>,
115+
shared_task_options: Vec<&'proj TaskOptionsConfig>,
116116
filters: Option<&'proj ProjectWorkspaceInheritedTasksConfig>,
117117
}
118118

@@ -135,7 +135,7 @@ impl<'proj> TasksBuilder<'proj> {
135135
implicit_inputs: vec![],
136136
task_ids: FxHashSet::default(),
137137
global_tasks: FxHashMap::default(),
138-
global_task_options: vec![],
138+
shared_task_options: vec![],
139139
local_tasks: FxHashMap::default(),
140140
filters: None,
141141
}
@@ -234,7 +234,7 @@ impl<'proj> TasksBuilder<'proj> {
234234
}
235235

236236
if let Some(options) = &global_config.task_options {
237-
self.global_task_options.push(options);
237+
self.shared_task_options.push(options);
238238
}
239239

240240
self.implicit_deps.extend(&global_config.implicit_deps);
@@ -263,6 +263,10 @@ impl<'proj> TasksBuilder<'proj> {
263263
self.task_ids.insert(id);
264264
}
265265

266+
if let Some(options) = &local_config.task_options {
267+
self.shared_task_options.push(options);
268+
}
269+
266270
self
267271
}
268272

@@ -617,7 +621,7 @@ impl<'proj> TasksBuilder<'proj> {
617621
options.unix_shell = default_unix_shell();
618622
options.windows_shell = default_windows_shell();
619623

620-
let mut chain = self.global_task_options.clone();
624+
let mut chain = self.shared_task_options.clone();
621625

622626
chain.extend(
623627
self.get_config_inherit_chain(id)?

packages/types/src/project-config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ export interface ProjectConfig {
262262
* boundary enforcement, and task inheritance.
263263
*/
264264
tags?: Id[];
265+
/**
266+
* Shared task options for all tasks. Can be overriden per task.
267+
* @since 2.4.0
268+
*/
269+
taskOptions: TaskOptionsConfig | null;
265270
/**
266271
* A map of identifiers to task objects. Tasks represent the work-unit
267272
* of a project, and can be ran in the action pipeline.
@@ -478,6 +483,11 @@ export interface PartialProjectConfig {
478483
* boundary enforcement, and task inheritance.
479484
*/
480485
tags?: Id[] | null;
486+
/**
487+
* Shared task options for all tasks. Can be overriden per task.
488+
* @since 2.4.0
489+
*/
490+
taskOptions?: PartialTaskOptionsConfig | null;
481491
/**
482492
* A map of identifiers to task objects. Tasks represent the work-unit
483493
* of a project, and can be ran in the action pipeline.

packages/types/src/workspace-config.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,27 @@ import type { ExtendsFrom, Id } from './common';
66

77
/** Configures aspects of the content-addressable storage (CAS) cache. */
88
export interface CacheCasConfig {
9+
/**
10+
* Maximum total size of the local cache, for example "10gb" or
11+
* "512mib". When exceeded, the least recently used cached task outputs
12+
* are evicted. Unlimited when unset.
13+
* @since 2.4.0
14+
*/
15+
maxSize: string | null;
916
/**
1017
* Verify hash on every read. When enabled, reads are slower
1118
* but detect on-disk corruption.
19+
* @since 2.3.0
1220
*/
1321
verifyIntegrity: boolean;
1422
}
1523

1624
/** Configures aspects of the caching engine and layer. */
1725
export interface CacheConfig {
18-
/** Configures aspects of the content-addressable storage (CAS) cache. */
26+
/**
27+
* Configures aspects of the content-addressable storage (CAS) cache.
28+
* @since 2.3.0
29+
*/
1930
cas: CacheCasConfig;
2031
}
2132

@@ -164,24 +175,28 @@ export interface DockerConfig {
164175
export interface ExperimentsConfig {
165176
/**
166177
* Track and determine affected projects and tasks asynchronously.
178+
* @since 2.2.0
167179
*
168180
* @env MOON_EXPERIMENT_ASYNC_AFFECTED_TRACKING
169181
*/
170182
asyncAffectedTracking: boolean;
171183
/**
172184
* Build the project and task graphs asynchronously.
185+
* @since 2.2.0
173186
*
174187
* @env MOON_EXPERIMENT_ASYNC_GRAPH_BUILDING
175188
*/
176189
asyncGraphBuilding: boolean;
177190
/**
178191
* Store task outputs in a local CAS (content-addressable storage) cache.
192+
* @since 2.3.0
179193
*
180194
* @env MOON_EXPERIMENT_CAS_OUTPUTS_CACHE
181195
*/
182196
casOutputsCache: boolean;
183197
/**
184198
* Use native file hashing instead of using the VCS.
199+
* @since 2.3.0
185200
*
186201
* @env MOON_EXPERIMENT_NATIVE_FILE_HASHING
187202
*/
@@ -678,16 +693,27 @@ export interface WorkspaceConfig {
678693

679694
/** Configures aspects of the content-addressable storage (CAS) cache. */
680695
export interface PartialCacheCasConfig {
696+
/**
697+
* Maximum total size of the local cache, for example "10gb" or
698+
* "512mib". When exceeded, the least recently used cached task outputs
699+
* are evicted. Unlimited when unset.
700+
* @since 2.4.0
701+
*/
702+
maxSize?: string | null;
681703
/**
682704
* Verify hash on every read. When enabled, reads are slower
683705
* but detect on-disk corruption.
706+
* @since 2.3.0
684707
*/
685708
verifyIntegrity?: boolean | null;
686709
}
687710

688711
/** Configures aspects of the caching engine and layer. */
689712
export interface PartialCacheConfig {
690-
/** Configures aspects of the content-addressable storage (CAS) cache. */
713+
/**
714+
* Configures aspects of the content-addressable storage (CAS) cache.
715+
* @since 2.3.0
716+
*/
691717
cas?: PartialCacheCasConfig | null;
692718
}
693719

@@ -832,24 +858,28 @@ export interface PartialDockerConfig {
832858
export interface PartialExperimentsConfig {
833859
/**
834860
* Track and determine affected projects and tasks asynchronously.
861+
* @since 2.2.0
835862
*
836863
* @env MOON_EXPERIMENT_ASYNC_AFFECTED_TRACKING
837864
*/
838865
asyncAffectedTracking?: boolean | null;
839866
/**
840867
* Build the project and task graphs asynchronously.
868+
* @since 2.2.0
841869
*
842870
* @env MOON_EXPERIMENT_ASYNC_GRAPH_BUILDING
843871
*/
844872
asyncGraphBuilding?: boolean | null;
845873
/**
846874
* Store task outputs in a local CAS (content-addressable storage) cache.
875+
* @since 2.3.0
847876
*
848877
* @env MOON_EXPERIMENT_CAS_OUTPUTS_CACHE
849878
*/
850879
casOutputsCache?: boolean | null;
851880
/**
852881
* Use native file hashing instead of using the VCS.
882+
* @since 2.3.0
853883
*
854884
* @env MOON_EXPERIMENT_NATIVE_FILE_HASHING
855885
*/

website/static/schemas/v2/project.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@
136136
"$ref": "#/definitions/Id"
137137
}
138138
},
139+
"taskOptions": {
140+
"title": "taskOptions",
141+
"description": "Shared task options for all tasks. Can be overriden per task. @since 2.4.0",
142+
"anyOf": [
143+
{
144+
"$ref": "#/definitions/TaskOptionsConfig"
145+
},
146+
{
147+
"type": "null"
148+
}
149+
]
150+
},
139151
"tasks": {
140152
"title": "tasks",
141153
"description": "A map of identifiers to task objects. Tasks represent the work-unit of a project, and can be ran in the action pipeline.",

website/static/schemas/v2/workspace.json

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,23 @@
186186
"description": "Configures aspects of the content-addressable storage (CAS) cache.",
187187
"type": "object",
188188
"properties": {
189+
"maxSize": {
190+
"title": "maxSize",
191+
"description": "Maximum total size of the local cache, for example \"10gb\" or \"512mib\". When exceeded, the least recently used cached task outputs are evicted. Unlimited when unset. @since 2.4.0",
192+
"anyOf": [
193+
{
194+
"type": "string"
195+
},
196+
{
197+
"type": "null"
198+
}
199+
]
200+
},
189201
"verifyIntegrity": {
190202
"title": "verifyIntegrity",
191-
"description": "Verify hash on every read. When enabled, reads are slower but detect on-disk corruption.",
203+
"description": "Verify hash on every read. When enabled, reads are slower but detect on-disk corruption. @since 2.3.0",
192204
"type": "boolean",
193-
"markdownDescription": "Verify hash on every read. When enabled, reads are slower but detect on-disk corruption."
205+
"markdownDescription": "Verify hash on every read. When enabled, reads are slower but detect on-disk corruption. @since 2.3.0"
194206
}
195207
},
196208
"additionalProperties": false,
@@ -202,13 +214,13 @@
202214
"properties": {
203215
"cas": {
204216
"title": "cas",
205-
"description": "Configures aspects of the content-addressable storage (CAS) cache.",
217+
"description": "Configures aspects of the content-addressable storage (CAS) cache. @since 2.3.0",
206218
"allOf": [
207219
{
208220
"$ref": "#/definitions/CacheCasConfig"
209221
}
210222
],
211-
"markdownDescription": "Configures aspects of the content-addressable storage (CAS) cache."
223+
"markdownDescription": "Configures aspects of the content-addressable storage (CAS) cache. @since 2.3.0"
212224
}
213225
},
214226
"additionalProperties": false
@@ -465,23 +477,23 @@
465477
"properties": {
466478
"asyncAffectedTracking": {
467479
"title": "asyncAffectedTracking",
468-
"description": "Track and determine affected projects and tasks asynchronously.",
480+
"description": "Track and determine affected projects and tasks asynchronously. @since 2.2.0",
469481
"type": "boolean"
470482
},
471483
"asyncGraphBuilding": {
472484
"title": "asyncGraphBuilding",
473-
"description": "Build the project and task graphs asynchronously.",
485+
"description": "Build the project and task graphs asynchronously. @since 2.2.0",
474486
"type": "boolean"
475487
},
476488
"casOutputsCache": {
477489
"title": "casOutputsCache",
478-
"description": "Store task outputs in a local CAS (content-addressable storage) cache.",
490+
"description": "Store task outputs in a local CAS (content-addressable storage) cache. @since 2.3.0",
479491
"type": "boolean",
480-
"markdownDescription": "Store task outputs in a local CAS (content-addressable storage) cache."
492+
"markdownDescription": "Store task outputs in a local CAS (content-addressable storage) cache. @since 2.3.0"
481493
},
482494
"nativeFileHashing": {
483495
"title": "nativeFileHashing",
484-
"description": "Use native file hashing instead of using the VCS.",
496+
"description": "Use native file hashing instead of using the VCS. @since 2.3.0",
485497
"type": "boolean"
486498
}
487499
},

0 commit comments

Comments
 (0)