1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use super::{CommitAuthorConfig, ContentSource, MakeLatestConfig};
// ---------------------------------------------------------------------------
// SnapshotConfig
// ---------------------------------------------------------------------------
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct SnapshotConfig {
/// Version string template for snapshot builds (e.g., "{{ Commit }}-SNAPSHOT").
/// Accepts the deprecated `name_template:` alias (renamed to
/// `version_template`): a non-empty `name_template` is folded into
/// `version_template`.
/// A deprecation warning is emitted at config-load time when the alias
/// is hit (see `apply_snapshot_legacy_aliases`).
#[serde(alias = "name_template")]
pub version_template: String,
}
// ---------------------------------------------------------------------------
// NightlyConfig
// ---------------------------------------------------------------------------
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
#[serde(default, deny_unknown_fields)]
pub struct NightlyConfig {
/// Template for the rendered version string the nightly run sets on
/// `Version` / `RawVersion`. Default:
/// `"{{ incpatch(v=Version) }}-{{ ShortCommit }}-nightly"` — produces
/// commit-immutable nightly versions (two same-day commits yield two
/// distinct nightly versions).
///
/// The `{{ NightlyBuild }}` template var (a stateless per-base-version
/// build counter derived from `git rev-list --count <last-tag>..HEAD`)
/// enables nushell-style schemes such as
/// `"{{ Base }}-nightly.{{ NightlyBuild }}+{{ ShortCommit }}"`.
pub version_template: Option<String>,
/// Template for the nightly release's NAME, replacing
/// `release.name_template` on nightly runs only. Unset falls through to
/// `release.name_template`, so a nightly is named exactly like a stable
/// release unless this says otherwise. Templates are rendered with the
/// nightly `Version` already applied.
pub name_template: Option<String>,
/// The tag the nightly release is created on, replacing the crate's
/// `tag_template` (and any `release.tag` override) on nightly runs only.
/// Templates allowed.
///
/// Unset — the default — leaves the crate's own `tag_template` to create
/// the tag from the nightly version (`v{{ Version }}` →
/// `v1.2.4-abc1234-nightly`), which keeps two nightlies at different
/// commits distinguishable.
///
/// Set it to pin one rolling tag instead (`tag_name: nightly` → tag
/// `nightly`, moved each run). In a workspace that creates more than one
/// tag family the value is prefixed with the publishing crate's family so
/// the tracks do not collide on a single tag: with `operator-v{{ Version }}`,
/// `tag_name: edge` yields `operator-vedge`.
pub tag_name: Option<String>,
/// Whether to publish a GitHub Release at all. Default: `true`.
/// Set `false` for nightly-only docker pushes / blob uploads.
pub publish_release: Option<bool>,
/// Skip the nightly release when the run's changelog resolved to ZERO
/// notable entries. Default: `false` — a nightly always cuts, even at a
/// commit that already shipped as a stable release.
///
/// `true` makes a nightly a no-op on a quiet day: it skips exactly what
/// `publish_release: false` skips (the release publish; every other
/// configured stage still runs) and exits 0. In a per-crate workspace the
/// decision is made per crate, against that crate's own range.
///
/// The signal is the changelog stage's own entry count, so
/// `changelog.filters` / `paths` / `groups` decide what counts as
/// notable. A run that produces no such count never skips: `--skip=changelog`
/// (the stage did not run) and `changelog.use: github-native` (GitHub
/// composes the notes server-side, so anodizer counts nothing) both leave
/// the nightly to cut as usual.
///
/// A repo with no prior tag in the crate's family is never skipped
/// either: its whole history is unreleased, so "no changes since the last
/// release" is not a claim it can make.
pub skip_if_no_changes: Option<bool>,
/// Publish the nightly release to a DIFFERENT repository than the source
/// repo, in `"owner/repo"` form (e.g. `"nushell/nightly"`). Default
/// (`None`) publishes to the configured `release.github` repo, unchanged.
///
/// When set, the nightly release create, asset upload, AND retention
/// (`keep_single_release` / `retention.keep_last`) delete calls all
/// target this repo. The active SCM token is assumed to have write
/// access to `publish_repo`. GitHub-only (the nushell adoption target).
pub publish_repo: Option<String>,
/// Delete the prior release that points at the same tag before
/// creating the new one. Default: `false`. Set `true` to maintain a
/// single rolling nightly release on GitHub.
///
/// Back-compat alias for `retention: { keep_last: 1 }`. When both
/// `keep_single_release` and `retention` are set, `retention` wins.
/// Destructive: deletes a published release via the GitHub Releases API.
/// GitHub-only.
pub keep_single_release: Option<bool>,
/// Retention policy for nightly releases on GitHub. Generalizes
/// `keep_single_release` (which is `keep_last: 1`): keeps the N newest
/// nightly releases matching the nightly tag/name and deletes the rest
/// (releases + the tags anodizer created for them). Operates on
/// `publish_repo` when set. Default (`None`): no retention sweep.
pub retention: Option<RetentionConfig>,
/// Override `release.draft` for nightly runs only.
/// `None` falls through to `release.draft`; `Some(v)` overrides it.
pub draft: Option<bool>,
/// Mark the nightly release as a prerelease. Default: `true`.
///
/// Unlike [`Self::draft`], `None` does NOT fall through to
/// `release.prerelease`: that field resolves to `false` for a nightly, so
/// falling through would publish every nightly as a stable release. An
/// unset `release.prerelease` is `false`, and `prerelease: auto` does not
/// rescue it either — `auto` reads the tag the run cuts, which answers
/// `true` only while that tag parses as a semver carrying a prerelease
/// part, and a pinned [`Self::tag_name`] (`nightly`, `edge`) parses as no
/// semver at all. Set `false` to opt out.
pub prerelease: Option<bool>,
/// Override `release.make_latest` for nightly runs only. Default:
/// `false` — a rolling nightly must not displace the newest stable
/// release in the GitHub UI, in `releases/latest`, or for the install
/// scripts and `gh release download` invocations that resolve it.
///
/// `None` does not fall through to `release.make_latest` for the same
/// reason as [`Self::prerelease`]: unset there means GitHub's own
/// default, which IS latest.
#[schemars(schema_with = "super::release::make_latest_schema")]
pub make_latest: Option<MakeLatestConfig>,
}
/// Retention policy for nightly releases on the publish repo.
///
/// `keep_last: N` keeps the N newest nightly releases (matched by the
/// nightly tag/name) and deletes the older ones, including the git tags
/// anodizer created for them.
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
#[serde(default, deny_unknown_fields)]
pub struct RetentionConfig {
/// Number of newest nightly releases to keep. `0` is treated as `1`
/// (never delete every nightly), matching the `keep_single_release`
/// floor. nushell keeps 10.
pub keep_last: usize,
}
impl NightlyConfig {
/// Resolve the effective `keep_last` retention count, or `None` when no
/// retention is requested.
///
/// Precedence: an explicit `retention:` block wins over the legacy
/// `keep_single_release:` alias. `keep_single_release: true` (with no
/// `retention`) maps to `keep_last: 1`; `false` maps to `None`. A
/// `retention.keep_last: 0` is floored to `1` so a retention sweep
/// never deletes the just-created release.
pub fn resolved_keep_last(&self) -> Option<usize> {
if let Some(r) = self.retention.as_ref() {
return Some(r.keep_last.max(1));
}
if self.keep_single_release == Some(true) {
return Some(1);
}
None
}
}
/// Validate `nightly.publish_repo` is `"owner/repo"` shaped.
///
/// Returns `Ok(())` when unset or well-formed. A malformed value (missing
/// `/`, empty owner/repo, extra path segments, or whitespace) is a
/// config-time error rather than a confusing 404 at publish time.
pub fn validate_nightly_publish_repo(config: &crate::config::Config) -> Result<(), String> {
let Some(nightly) = config.nightly.as_ref() else {
return Ok(());
};
let Some(repo) = nightly.publish_repo.as_deref() else {
return Ok(());
};
let parts: Vec<&str> = repo.split('/').collect();
let well_formed = parts.len() == 2
&& parts
.iter()
.all(|p| !p.trim().is_empty() && !p.contains(char::is_whitespace));
if well_formed {
Ok(())
} else {
Err(format!(
"nightly.publish_repo must be in \"owner/repo\" form (got {repo:?})"
))
}
}
// ---------------------------------------------------------------------------
// MetadataConfig
// ---------------------------------------------------------------------------
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
#[serde(default, deny_unknown_fields)]
pub struct MetadataConfig {
/// Human-readable project description (exposed as `{{ Metadata.Description }}`).
pub description: Option<String>,
/// Project homepage URL (exposed as `{{ Metadata.Homepage }}`).
pub homepage: Option<String>,
/// Project documentation URL, e.g. a docs.rs or hosted-docs link
/// (exposed as `{{ Metadata.Documentation }}`). Derived from
/// `Cargo.toml [package].documentation` when unset.
pub documentation: Option<String>,
/// Project license identifier, e.g. "MIT" or "Apache-2.0" (exposed as `{{ Metadata.License }}`).
pub license: Option<String>,
/// Project source-repository URL, e.g. a GitHub URL (exposed as
/// `{{ Metadata.Repository }}`). Derived from `Cargo.toml [package].repository`
/// when unset; feeds the npm `package.json` `repository` field, which npm
/// provenance validates against the OIDC-claimed repository.
// Omit-when-None so adding this field leaves `dist/config.yaml` byte-identical
// for configs that don't set it — a republish/backfill of an older tag's
// preserved dist re-renders config.yaml and hash-verifies it against the
// determinism shards, which a new always-emitted `repository: null` line would
// break. The sibling fields predate this invariant and stay as-is.
#[serde(skip_serializing_if = "Option::is_none")]
pub repository: Option<String>,
/// List of project maintainers (exposed as `{{ Metadata.Maintainers }}`).
pub maintainers: Option<Vec<String>>,
/// Global modification timestamp for metadata output files (metadata.json and artifacts.json).
/// Template string (e.g. "{{ CommitTimestamp }}") or unix timestamp.
/// When set, rendered late in the pipeline and applied as file mtime.
/// Exposed as `{{ Metadata.ModTimestamp }}`.
pub mod_timestamp: Option<String>,
/// Long-form project description. Supports inline
/// string, `from_file`, or `from_url`. Exposed as `{{ Metadata.FullDescription }}`.
/// FromUrl is resolved lazily (requires the release stage); FromFile is resolved
/// at context-populate time with template-rendered path.
pub full_description: Option<ContentSource>,
/// Commit author identity for commit workflows.
/// Reuses the shared `CommitAuthorConfig` (name + email + optional signing).
/// Exposed as `{{ Metadata.CommitAuthor.Name }}` / `{{ Metadata.CommitAuthor.Email }}`.
pub commit_author: Option<CommitAuthorConfig>,
}
#[cfg(test)]
mod tests {
use super::*;
use crate::config::Config;
#[test]
fn resolved_keep_last_maps_keep_single_release_alias() {
let n = NightlyConfig {
keep_single_release: Some(true),
..Default::default()
};
assert_eq!(n.resolved_keep_last(), Some(1));
}
#[test]
fn resolved_keep_last_none_when_neither_set() {
let n = NightlyConfig::default();
assert_eq!(n.resolved_keep_last(), None);
let n = NightlyConfig {
keep_single_release: Some(false),
..Default::default()
};
assert_eq!(n.resolved_keep_last(), None);
}
#[test]
fn resolved_keep_last_retention_wins_over_alias() {
// Both set: retention.keep_last wins over the legacy alias.
let n = NightlyConfig {
keep_single_release: Some(true),
retention: Some(RetentionConfig { keep_last: 10 }),
..Default::default()
};
assert_eq!(n.resolved_keep_last(), Some(10));
}
#[test]
fn resolved_keep_last_floors_zero_to_one() {
let n = NightlyConfig {
retention: Some(RetentionConfig { keep_last: 0 }),
..Default::default()
};
assert_eq!(n.resolved_keep_last(), Some(1));
}
#[test]
fn keep_single_release_yaml_alias_round_trips() {
// Back-compat: an existing keep_single_release config still parses
// and resolves to keep_last: 1.
let n: NightlyConfig = serde_yaml_ng::from_str("keep_single_release: true").unwrap();
assert_eq!(n.resolved_keep_last(), Some(1));
}
fn config_with_publish_repo(repo: Option<&str>) -> Config {
Config {
nightly: Some(NightlyConfig {
publish_repo: repo.map(str::to_string),
..Default::default()
}),
..Default::default()
}
}
#[test]
fn validate_publish_repo_accepts_owner_repo() {
let c = config_with_publish_repo(Some("nushell/nightly"));
assert!(validate_nightly_publish_repo(&c).is_ok());
}
#[test]
fn validate_publish_repo_ok_when_unset() {
assert!(validate_nightly_publish_repo(&config_with_publish_repo(None)).is_ok());
assert!(validate_nightly_publish_repo(&Config::default()).is_ok());
}
#[test]
fn validate_publish_repo_rejects_malformed() {
for bad in ["nushell", "a/b/c", "/nightly", "nushell/", "owner repo/x"] {
let c = config_with_publish_repo(Some(bad));
assert!(
validate_nightly_publish_repo(&c).is_err(),
"expected {bad:?} to be rejected"
);
}
}
#[test]
fn metadata_repository_omitted_when_none_keeps_config_yaml_byte_stable() {
// A metadata block that does NOT set repository must serialize WITHOUT a
// `repository` key, so introducing the field leaves dist/config.yaml
// byte-identical and a backfill's hash-verify against older preserved
// determinism shards still passes.
let m = MetadataConfig {
homepage: Some("https://example.com".into()),
..Default::default()
};
let yaml = serde_yaml_ng::to_string(&m).expect("serialize");
assert!(
!yaml.contains("repository"),
"unset repository must be omitted, got:\n{yaml}"
);
// When set, it is emitted (npm provenance / template var still work).
let m2 = MetadataConfig {
repository: Some("https://github.com/x/y".into()),
..Default::default()
};
assert!(
serde_yaml_ng::to_string(&m2)
.expect("serialize")
.contains("repository: https://github.com/x/y"),
);
}
}