anodizer_core/config/defaults.rs
1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use super::archives::ArchiveConfig;
5use super::aur_source::AurSourceConfig;
6use super::build::BuildConfig;
7use super::hooks::HookEntry;
8use super::installers::{
9 AppBundleConfig, DmgConfig, FlatpakConfig, MsiConfig, NsisConfig, PkgConfig,
10};
11use super::nfpm::NfpmConfig;
12use super::notarize::NotarizeConfig;
13use super::publishers::{
14 AurConfig, CargoPublishConfig, ChocolateyConfig, HomebrewCaskConfig, HomebrewConfig,
15 KrewConfig, NixConfig, ScoopConfig, WingetConfig,
16};
17use super::sbom::SbomConfig;
18use super::snapcraft::SnapcraftConfig;
19use super::source::SourceConfig;
20use super::upx::UpxConfig;
21use super::{ChecksumConfig, CrossStrategy, DockerSignConfig, DockerV2Config, SignConfig};
22use crate::packagers::{MakeselfConfig, SrpmConfig};
23
24// ---------------------------------------------------------------------------
25// Defaults
26// ---------------------------------------------------------------------------
27
28/// Workspace-level defaults that path-mirror the `CrateConfig` (and select
29/// top-level `Config`) shape. Each field here is folded into every resolved
30/// crate by `defaults_merge::apply_defaults` according to the deep-merge /
31/// merge-by-identity semantics documented in `defaults_merge`.
32///
33/// Multi-publisher fields are single-struct on both sides today: defaults
34/// supplies one struct per publisher, and per-crate `publish.*` fields are
35/// also single-struct. A future change may introduce list-or-scalar via
36/// `OneOrMany<T>` on the per-crate side so a crate can declare multiple
37/// homebrew taps / scoop buckets / etc.; the defaults side would stay
38/// single-struct and merge into the first per-crate entry by identity.
39#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
40#[serde(default, deny_unknown_fields)]
41pub struct Defaults {
42 // --- Build axis ---
43 /// Default build settings applied to every crate's builds (deep-merged
44 /// into each `CrateConfig.builds[]` entry by identity on `id`/`binary`).
45 pub builds: Option<BuildConfig>,
46 /// Default archive settings applied to all crates.
47 pub archives: Option<ArchiveConfig>,
48 /// Default source-archive settings applied to all crates.
49 pub source: Option<SourceConfig>,
50 /// Default UPX compression settings applied to all crates.
51 pub upx: Option<UpxConfig>,
52
53 // --- Packaging axis ---
54 /// Default nfpm (deb/rpm/apk) settings applied to all crates.
55 pub nfpms: Option<NfpmConfig>,
56 /// Default snapcraft settings applied to all crates.
57 pub snapcrafts: Option<SnapcraftConfig>,
58 /// Default flatpak settings applied to all crates.
59 pub flatpaks: Option<FlatpakConfig>,
60 /// Default app-bundle settings applied to all crates.
61 pub app_bundles: Option<AppBundleConfig>,
62 /// Default DMG settings applied to all crates.
63 pub dmgs: Option<DmgConfig>,
64 /// Default macOS PKG settings applied to all crates.
65 pub pkgs: Option<PkgConfig>,
66 /// Default MSI settings applied to all crates.
67 pub msis: Option<MsiConfig>,
68 /// Default NSIS settings applied to all crates.
69 pub nsis: Option<NsisConfig>,
70 /// Default makeself settings applied to all crates.
71 pub makeselves: Option<MakeselfConfig>,
72 /// Default SRPM settings applied to all crates.
73 pub srpms: Option<SrpmConfig>,
74 /// Default Docker (V2 API) image settings applied to all crates. The
75 /// `docker_v2:` spelling is still accepted via serde alias for back-compat.
76 #[serde(alias = "docker_v2")]
77 pub dockers_v2: Option<DockerV2Config>,
78
79 // --- Publish axis ---
80 /// Default publisher configurations (single-struct per publisher).
81 /// Per-crate `publish.*` entries are merged into these by identity.
82 pub publish: Option<PublishDefaults>,
83
84 // --- Sign / notarize / sbom ---
85 /// Default artifact signing settings.
86 pub sign: Option<SignConfig>,
87 /// Default binary-signing settings.
88 pub binary_signs: Option<SignConfig>,
89 /// Default Docker image signing settings.
90 pub docker_signs: Option<DockerSignConfig>,
91 /// Default macOS notarization settings.
92 pub notarize: Option<NotarizeConfig>,
93 /// Default SBOM generation settings.
94 pub sbom: Option<SbomConfig>,
95
96 // --- Cross-cutting ---
97 /// Default build targets (e.g., ["x86_64-unknown-linux-gnu", "aarch64-apple-darwin"]).
98 pub targets: Option<Vec<String>>,
99 /// Default environment variables (`KEY=VALUE` strings) hoisted across crates.
100 pub env: Option<Vec<String>>,
101 /// Default repo-committed files whose embedded release version is rewritten
102 /// at `tag` time (repo-root-relative path strings). Hoisted across crates;
103 /// folded into each crate's `version_files` by `defaults_merge` when the
104 /// crate does not set its own list. Mirrors `CrateConfig.version_files`.
105 pub version_files: Option<Vec<String>>,
106 /// Default cross-compilation strategy: auto, zigbuild, cross, or cargo.
107 /// Mirrors `CrateConfig.cross` so the strategy can be hoisted to defaults.
108 pub cross: Option<CrossStrategy>,
109 /// Default checksum settings applied to all crates.
110 /// Mirrors `CrateConfig.checksum` so checksum config can be hoisted to defaults.
111 pub checksum: Option<ChecksumConfig>,
112
113 // --- Crate-axis vs workspace-axis (mutually exclusive) ---
114 /// Crate-axis defaults marker. Only valid when top-level `crates:` is set.
115 /// Reserved for per-crate overrides keyed by crate id (future waves).
116 pub crates: Option<DefaultsCrateBlock>,
117 /// Workspace-axis defaults marker. Only valid when top-level `workspaces:` is set.
118 /// Reserved for per-workspace overrides keyed by workspace name (future waves).
119 pub workspaces: Option<DefaultsWorkspaceBlock>,
120}
121
122/// Workspace-default publishers. Each publisher is single-struct in
123/// defaults; per-crate `publish.*` may be either a single struct or a list,
124/// reconciled by the merge engine.
125#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
126#[serde(default, deny_unknown_fields)]
127pub struct PublishDefaults {
128 /// Default Homebrew formula settings.
129 pub homebrew: Option<HomebrewConfig>,
130 /// Default Homebrew Cask settings, merged into per-crate `publish.homebrew_cask`.
131 ///
132 /// Single-struct.
133 pub homebrew_cask: Option<HomebrewCaskConfig>,
134 /// Default crates.io publish settings, merged into per-crate `publish.cargo`.
135 ///
136 /// Single-struct.
137 pub cargo: Option<CargoPublishConfig>,
138 /// Default Scoop manifest settings.
139 pub scoop: Option<ScoopConfig>,
140 /// Default WinGet manifest settings.
141 pub winget: Option<WingetConfig>,
142 /// Default Chocolatey package settings.
143 pub chocolatey: Option<ChocolateyConfig>,
144 /// Default Krew (kubectl plugin manager) settings.
145 pub krew: Option<KrewConfig>,
146 /// Default Nix derivation settings.
147 pub nix: Option<NixConfig>,
148 /// Default AUR (binary) settings.
149 pub aur: Option<AurConfig>,
150 /// Default AUR (source) settings.
151 pub aur_source: Option<AurSourceConfig>,
152 /// Hooks fired once per failed publisher — same surface as
153 /// `publish.on_error` on individual crate configs. Merged into
154 /// every crate's resolved publish config.
155 pub on_error: Option<Vec<HookEntry>>,
156 /// Hooks fired once per publisher a triggered rollback reverted — same
157 /// surface as `publish.on_rollback` on individual crate configs. Merged
158 /// into every crate's resolved publish config.
159 pub on_rollback: Option<Vec<HookEntry>>,
160}
161
162/// Marker block under `defaults.crates:` that signals crate-axis defaults
163/// scope. Required to drive the axis-mismatch validator. Currently
164/// empty; future per-crate-id overrides will live here.
165///
166/// `deny_unknown_fields` so that typing `defaults.crates: { foo: bar }`
167/// surfaces as a parse error rather than silently being accepted — without
168/// it, the empty struct is a sink that swallows arbitrary keys.
169#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
170#[serde(default, deny_unknown_fields)]
171pub struct DefaultsCrateBlock {}
172
173/// Marker block under `defaults.workspaces:` that signals workspace-axis
174/// defaults scope. Required to drive the axis-mismatch validator.
175/// Currently empty; future per-workspace-name overrides will live here.
176///
177/// `deny_unknown_fields` per the same rationale as `DefaultsCrateBlock`.
178#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
179#[serde(default, deny_unknown_fields)]
180pub struct DefaultsWorkspaceBlock {}