@sous-io/sous 0.2.37 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -256
- package/dist/bin.js +11 -0
- package/dist/sous.js +1094 -0
- package/docs/markdown/README.md +5 -4
- package/docs/markdown/_sidebar.md +21 -1
- package/docs/markdown/commands.md +294 -431
- package/docs/markdown/config-discovery.md +25 -14
- package/docs/markdown/config-inspection.md +53 -31
- package/docs/markdown/config-layers.md +168 -66
- package/docs/markdown/config-variables.md +44 -11
- package/docs/markdown/configuration.md +104 -17
- package/docs/markdown/design-principles.md +4 -1
- package/docs/markdown/repositories-authoring.md +30 -0
- package/docs/markdown/repositories-consuming.md +72 -14
- package/docs/markdown/repositories-file-formats.md +31 -13
- package/docs/markdown/repositories-providers.md +48 -57
- package/docs/markdown/repositories-quickstart.md +3 -2
- package/docs/markdown/repositories-troubleshooting.md +27 -1
- package/docs/markdown/repositories-variables.md +6 -1
- package/docs/markdown/repositories.md +18 -8
- package/package.json +48 -107
- package/recipes/core/sous-skills/skills/about-liquid-templates/SKILL.tpl.md +4 -6
- package/recipes/core/sous-skills/skills/about-liquid-templates/references/liquid-filters.tpl.md +2 -0
- package/recipes/core/sous-skills/skills/about-sous/SKILL.tpl.md +10 -9
- package/recipes/core/sous-skills/skills/about-sous-configuration/SKILL.tpl.md +35 -14
- package/recipes/core/sous-skills/skills/about-sous-recipes/SKILL.tpl.md +51 -20
- package/recipes/core/sous-skills/sous.recipe.yaml +1 -1
- package/sous.config.schema.json +351 -132
- package/bin/run.js +0 -51
- package/src/base-command.ts +0 -457
- package/src/commands/build.ts +0 -181
- package/src/commands/clear.ts +0 -79
- package/src/commands/compile.ts +0 -155
- package/src/commands/config/get.ts +0 -110
- package/src/commands/config/show.ts +0 -32
- package/src/commands/config/validate.ts +0 -53
- package/src/commands/help.ts +0 -46
- package/src/commands/init.ts +0 -289
- package/src/commands/launch.ts +0 -139
- package/src/commands/lock/rebuild.ts +0 -239
- package/src/commands/lock/show.ts +0 -115
- package/src/commands/namespace/list.ts +0 -138
- package/src/commands/namespace/show.ts +0 -130
- package/src/commands/prune.ts +0 -43
- package/src/commands/recipe/list.ts +0 -112
- package/src/commands/recipe/show.ts +0 -439
- package/src/commands/repo/add.ts +0 -145
- package/src/commands/repo/contribute.ts +0 -604
- package/src/commands/repo/gc.ts +0 -173
- package/src/commands/repo/init.ts +0 -136
- package/src/commands/repo/link.ts +0 -899
- package/src/commands/repo/list.ts +0 -236
- package/src/commands/repo/release.ts +0 -685
- package/src/commands/repo/remove.ts +0 -194
- package/src/commands/repo/search.ts +0 -243
- package/src/commands/repo/submit.ts +0 -341
- package/src/commands/repo/unlink.ts +0 -461
- package/src/commands/subscription/add.ts +0 -286
- package/src/commands/subscription/list.ts +0 -208
- package/src/commands/subscription/remove.ts +0 -182
- package/src/commands/subscription/update.ts +0 -216
- package/src/commands/update.ts +0 -178
- package/src/commands/vars/ask.ts +0 -417
- package/src/commands/vars/index.ts +0 -79
- package/src/commands/vars/list.ts +0 -67
- package/src/commands/vars/show.ts +0 -77
- package/src/config-command.ts +0 -30
- package/src/lib/build-preparation.ts +0 -128
- package/src/lib/build-service.ts +0 -580
- package/src/lib/config-discovery.ts +0 -378
- package/src/lib/config-inspect.ts +0 -145
- package/src/lib/config-kernel.mjs +0 -379
- package/src/lib/config-schema.ts +0 -401
- package/src/lib/env-file.ts +0 -328
- package/src/lib/env-local.ts +0 -212
- package/src/lib/errors.ts +0 -32
- package/src/lib/glob-pattern.ts +0 -24
- package/src/lib/include-resolver.ts +0 -523
- package/src/lib/interactive.ts +0 -165
- package/src/lib/markdown-compiler.ts +0 -947
- package/src/lib/package-info.ts +0 -25
- package/src/lib/pid-service.ts +0 -99
- package/src/lib/project-install.d.mts +0 -44
- package/src/lib/project-install.mjs +0 -234
- package/src/lib/project-scaffold/index.ts +0 -332
- package/src/lib/project-scaffold/templates.ts +0 -240
- package/src/lib/repos/catalog-display.ts +0 -215
- package/src/lib/repos/catalog-inputs.ts +0 -288
- package/src/lib/repos/catalog.ts +0 -842
- package/src/lib/repos/contribute.ts +0 -452
- package/src/lib/repos/core-recipe.ts +0 -105
- package/src/lib/repos/declarations.ts +0 -187
- package/src/lib/repos/defaults.ts +0 -175
- package/src/lib/repos/formats/common.ts +0 -440
- package/src/lib/repos/formats/index-file.ts +0 -253
- package/src/lib/repos/formats/links-map.ts +0 -98
- package/src/lib/repos/formats/lockfile.ts +0 -169
- package/src/lib/repos/formats/patterns.ts +0 -57
- package/src/lib/repos/formats/recipe-manifest.ts +0 -205
- package/src/lib/repos/formats/repo-manifest.ts +0 -97
- package/src/lib/repos/formats/store-entry.ts +0 -84
- package/src/lib/repos/formats/variable-definition.ts +0 -268
- package/src/lib/repos/freshness.ts +0 -264
- package/src/lib/repos/git-clone.ts +0 -850
- package/src/lib/repos/identity.ts +0 -89
- package/src/lib/repos/index.ts +0 -57
- package/src/lib/repos/links.ts +0 -356
- package/src/lib/repos/load-manifest.ts +0 -237
- package/src/lib/repos/lock-service.ts +0 -454
- package/src/lib/repos/locked-namespace-resolver.ts +0 -232
- package/src/lib/repos/locked-recipe-lookup.ts +0 -123
- package/src/lib/repos/locked-recipes.ts +0 -254
- package/src/lib/repos/managed-layer.ts +0 -422
- package/src/lib/repos/memories-hash-name.ts +0 -33
- package/src/lib/repos/namespace-resolver.ts +0 -527
- package/src/lib/repos/providers/base.ts +0 -268
- package/src/lib/repos/providers/git.ts +0 -245
- package/src/lib/repos/providers/github.ts +0 -589
- package/src/lib/repos/providers/gitlab.ts +0 -332
- package/src/lib/repos/providers/http.ts +0 -128
- package/src/lib/repos/providers/index-cache.ts +0 -421
- package/src/lib/repos/providers/index.ts +0 -106
- package/src/lib/repos/providers/local.ts +0 -410
- package/src/lib/repos/providers/provider.ts +0 -615
- package/src/lib/repos/recipe-config-layers.ts +0 -316
- package/src/lib/repos/recipe-key-matcher.ts +0 -62
- package/src/lib/repos/recipe-memories.ts +0 -178
- package/src/lib/repos/recipe-targets.ts +0 -236
- package/src/lib/repos/ref-search.ts +0 -46
- package/src/lib/repos/release/bump.ts +0 -161
- package/src/lib/repos/release/changelog.ts +0 -461
- package/src/lib/repos/release/git-state.ts +0 -460
- package/src/lib/repos/release/index-builder.ts +0 -1108
- package/src/lib/repos/release/index.ts +0 -19
- package/src/lib/repos/release/plan.ts +0 -521
- package/src/lib/repos/release/settle.ts +0 -154
- package/src/lib/repos/release/submissions.ts +0 -214
- package/src/lib/repos/release/submit-checkout.ts +0 -290
- package/src/lib/repos/release/submit-questions.ts +0 -153
- package/src/lib/repos/release/submit-service.ts +0 -898
- package/src/lib/repos/release/tags.ts +0 -239
- package/src/lib/repos/release/validate.ts +0 -463
- package/src/lib/repos/resolver.ts +0 -1028
- package/src/lib/repos/scaffold/index.ts +0 -245
- package/src/lib/repos/scaffold/templates.ts +0 -517
- package/src/lib/repos/seed.ts +0 -473
- package/src/lib/repos/store/contract.ts +0 -64
- package/src/lib/repos/store/hash.ts +0 -191
- package/src/lib/repos/store/recipe-store.ts +0 -599
- package/src/lib/repos/store/settings.ts +0 -58
- package/src/lib/repos/subscription-service.ts +0 -3859
- package/src/lib/repos/trust.ts +0 -447
- package/src/lib/repos/update-plan.ts +0 -235
- package/src/lib/self-update/index.ts +0 -14
- package/src/lib/self-update/installs.ts +0 -413
- package/src/lib/self-update/managers.ts +0 -126
- package/src/lib/self-update/plan.ts +0 -315
- package/src/lib/self-update/registry.ts +0 -99
- package/src/lib/self-update/run.ts +0 -506
- package/src/lib/self-update/versions.ts +0 -243
- package/src/lib/settings.ts +0 -1107
- package/src/lib/sous-home.ts +0 -104
- package/src/lib/state.ts +0 -167
- package/src/lib/vars/answers.ts +0 -192
- package/src/lib/vars/ask.ts +0 -1152
- package/src/lib/vars/definition-source.ts +0 -261
- package/src/lib/vars/display.ts +0 -231
- package/src/lib/vars/index.ts +0 -20
- package/src/lib/vars/ladder.ts +0 -282
- package/src/lib/vars/mappings.ts +0 -260
- package/src/lib/vars/names.ts +0 -94
- package/src/lib/vars/preanswers.ts +0 -395
- package/src/lib/vars/question-plan.ts +0 -241
- package/src/lib/vars/report.ts +0 -228
- package/src/lib/vars/safe-regex.ts +0 -235
- package/src/lib/vars/secrets.ts +0 -131
- package/src/lib/vars/validate.ts +0 -312
- package/src/lib/version-report.ts +0 -90
- package/src/lib/watch-loop.ts +0 -148
- package/src/lib/watch-service.ts +0 -116
- package/src/services/ref-resolver/container.ts +0 -107
- package/src/services/ref-resolver/dependency.ts +0 -60
- package/src/services/ref-resolver/format.ts +0 -197
- package/src/services/ref-resolver/glob.ts +0 -115
- package/src/services/ref-resolver/hash-names.ts +0 -155
- package/src/services/ref-resolver/index.ts +0 -55
- package/src/services/ref-resolver/injectable.ts +0 -36
- package/src/services/ref-resolver/location.ts +0 -62
- package/src/services/ref-resolver/lookups/cached-index-lookup.ts +0 -53
- package/src/services/ref-resolver/lookups/catalog-lookup.ts +0 -23
- package/src/services/ref-resolver/lookups/catalog-matcher.ts +0 -261
- package/src/services/ref-resolver/lookups/chained-lookup.ts +0 -27
- package/src/services/ref-resolver/lookups/env-var-lookup.ts +0 -65
- package/src/services/ref-resolver/lookups/fetched-index-lookup.ts +0 -150
- package/src/services/ref-resolver/lookups/recorded-dependency-lookup.ts +0 -62
- package/src/services/ref-resolver/lookups/ref-lookup.ts +0 -54
- package/src/services/ref-resolver/lookups/variable-lookup.ts +0 -123
- package/src/services/ref-resolver/named-refs.ts +0 -144
- package/src/services/ref-resolver/parser/env-var-splitter.ts +0 -27
- package/src/services/ref-resolver/parser/location-splitter.ts +0 -239
- package/src/services/ref-resolver/parser/name-path-splitter.ts +0 -200
- package/src/services/ref-resolver/parser/partial-ref.ts +0 -84
- package/src/services/ref-resolver/parser/query-splitter.ts +0 -61
- package/src/services/ref-resolver/parser/range-splitter.ts +0 -52
- package/src/services/ref-resolver/parser/ref-parser.ts +0 -115
- package/src/services/ref-resolver/parser/repo-qualifier-splitter.ts +0 -51
- package/src/services/ref-resolver/parts.ts +0 -115
- package/src/services/ref-resolver/pruners/command-line-pruner.ts +0 -47
- package/src/services/ref-resolver/pruners/include-pruner.ts +0 -66
- package/src/services/ref-resolver/pruners/manifest-pruner.ts +0 -130
- package/src/services/ref-resolver/pruners/ref-pruner.ts +0 -135
- package/src/services/ref-resolver/pruners/rule-helpers.ts +0 -44
- package/src/services/ref-resolver/pruners/stored-key-pruner.ts +0 -136
- package/src/services/ref-resolver/ref-helpers.ts +0 -62
- package/src/services/ref-resolver/ref-picker-service.ts +0 -204
- package/src/services/ref-resolver/ref-report.ts +0 -84
- package/src/services/ref-resolver/ref-resolve-arguments.ts +0 -47
- package/src/services/ref-resolver/ref-resolve-result.ts +0 -36
- package/src/services/ref-resolver/ref-resolver-service.ts +0 -323
- package/src/services/ref-resolver/source.ts +0 -48
- package/src/services/ref-resolver/tokens.ts +0 -25
- package/src/services/ref-resolver/types.ts +0 -155
- package/src/templating/filters/bullet-list.ts +0 -9
- package/src/templating/filters/index.ts +0 -8
- package/src/templating/init-liquid-engine.ts +0 -139
- package/src/templating/lib/glob-files.ts +0 -74
- package/src/templating/lib/import-export.ts +0 -32
- package/src/templating/lib/secret-scope.ts +0 -41
- package/src/templating/lib/tag-args.ts +0 -19
- package/src/templating/tags/exportScalarVarsJs.ts +0 -46
- package/src/templating/tags/getFiles.ts +0 -89
- package/src/templating/tags/index.ts +0 -14
- package/src/templating/tags/listFiles.ts +0 -54
- package/src/templating/tags/showVars.ts +0 -28
- package/src/utils/choice-prompt.ts +0 -143
- package/src/utils/command-errors.ts +0 -186
- package/src/utils/command-help.ts +0 -45
- package/src/utils/confirm-prompt.ts +0 -110
- package/src/utils/flags.ts +0 -177
- package/src/utils/formatting.ts +0 -849
- package/src/utils/prompts.ts +0 -53
- package/src/utils/sous-directory.ts +0 -245
- package/src/utils/table.ts +0 -603
- package/src/utils/value-prompt.ts +0 -119
|
@@ -1,461 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The changelog `sous repo submit` writes under a proposal's description.
|
|
3
|
-
*
|
|
4
|
-
* A maintainer reviewing a proposal needs to know what merging it does to the
|
|
5
|
-
* people who subscribe to the repository: which recipes appear, disappear or
|
|
6
|
-
* change version, which changed their files without raising their version
|
|
7
|
-
* (a release run with `--ci` refuses those), which namespaces come and go, and which
|
|
8
|
-
* variables change. None of that is in a commit message, and all of it can be
|
|
9
|
-
* read from the manifests, so sous reads them: the ones the change carries,
|
|
10
|
-
* compared with the ones on the default branch.
|
|
11
|
-
*
|
|
12
|
-
* The changelog explains; it never refuses. Whether a change is acceptable is
|
|
13
|
-
* the repository's own checks' business, so a change that affects subscribers
|
|
14
|
-
* is described here, with a warning where one is due, and never blocked.
|
|
15
|
-
*
|
|
16
|
-
* Reading the default branch's manifests goes through git and the injectable
|
|
17
|
-
* runner; everything after that is pure, so the comparison is tested without a
|
|
18
|
-
* repository at all.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import path from "node:path";
|
|
22
|
-
import {
|
|
23
|
-
MANIFEST_EXTENSIONS,
|
|
24
|
-
RECIPE_MANIFEST_BASENAME,
|
|
25
|
-
REPO_MANIFEST_BASENAME,
|
|
26
|
-
} from "../formats/common.js";
|
|
27
|
-
import {
|
|
28
|
-
parseRecipeManifest,
|
|
29
|
-
recipeManifestKey,
|
|
30
|
-
type RecipeManifest,
|
|
31
|
-
type VariableDefinition,
|
|
32
|
-
} from "../formats/recipe-manifest.js";
|
|
33
|
-
import { parseRepoManifest, type RepoManifest } from "../formats/repo-manifest.js";
|
|
34
|
-
import { parseJsoncText, parseYamlText } from "../load-manifest.js";
|
|
35
|
-
import type { RunOptions } from "../providers/git.js";
|
|
36
|
-
import { pathsInside } from "./submissions.js";
|
|
37
|
-
import { readFileAtTag } from "./tags.js";
|
|
38
|
-
import type { RepoValidation } from "./validate.js";
|
|
39
|
-
|
|
40
|
-
/** The manifests as they stood at one commit. */
|
|
41
|
-
export type ManifestSnapshot = {
|
|
42
|
-
/** The repo manifest. */
|
|
43
|
-
repo: RepoManifest;
|
|
44
|
-
/** Every recipe manifest that could be read, keyed by recipe key. */
|
|
45
|
-
recipes: Map<string, { path: string; manifest: RecipeManifest }>;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/** One recipe that appeared or disappeared. */
|
|
49
|
-
export type RecipeEntry = { key: string; version: string };
|
|
50
|
-
|
|
51
|
-
/** One recipe whose declared version moved. */
|
|
52
|
-
export type VersionChange = { key: string; from: string; to: string };
|
|
53
|
-
|
|
54
|
-
/** One recipe whose files changed while its version stayed where it was. */
|
|
55
|
-
export type UnraisedChange = { key: string; version: string };
|
|
56
|
-
|
|
57
|
-
/** One variable that was added, removed or changed. */
|
|
58
|
-
export type VariableChange = {
|
|
59
|
-
/** The recipe that declares it. */
|
|
60
|
-
recipe: string;
|
|
61
|
-
/** The variable's name. */
|
|
62
|
-
name: string;
|
|
63
|
-
/** What happened to it. */
|
|
64
|
-
change: "added" | "removed" | "changed";
|
|
65
|
-
/** The fields that changed, for a changed variable. */
|
|
66
|
-
fields?: string[];
|
|
67
|
-
/** True when the change usually breaks a subscriber: a removal, or a tighter rule. */
|
|
68
|
-
breaking: boolean;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/** Everything merging a change would do, as the manifests describe it. */
|
|
72
|
-
export type Changelog = {
|
|
73
|
-
/** The branch the change was compared with. */
|
|
74
|
-
baseBranch: string;
|
|
75
|
-
/** False when there was nothing to compare with; every list is then empty. */
|
|
76
|
-
compared: boolean;
|
|
77
|
-
namespacesAdded: string[];
|
|
78
|
-
namespacesRemoved: string[];
|
|
79
|
-
recipesAdded: RecipeEntry[];
|
|
80
|
-
recipesRemoved: RecipeEntry[];
|
|
81
|
-
versionChanges: VersionChange[];
|
|
82
|
-
unraised: UnraisedChange[];
|
|
83
|
-
variables: VariableChange[];
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Reads the repo manifest and every recipe manifest it lists as they stood at
|
|
88
|
-
* one commit. Returns undefined when that commit holds no repo manifest sous
|
|
89
|
-
* can read; a recipe manifest it cannot read is left out rather than failing
|
|
90
|
-
* the whole comparison.
|
|
91
|
-
*
|
|
92
|
-
* @param rootDir - The repository's root directory.
|
|
93
|
-
* @param commit - The commit to read at.
|
|
94
|
-
* @param options - The command runner to use.
|
|
95
|
-
*/
|
|
96
|
-
export async function readManifestsAt(
|
|
97
|
-
rootDir: string,
|
|
98
|
-
commit: string,
|
|
99
|
-
options: RunOptions = {}
|
|
100
|
-
): Promise<ManifestSnapshot | undefined> {
|
|
101
|
-
const repoRaw = await readManifestAt(rootDir, commit, "", REPO_MANIFEST_BASENAME, options);
|
|
102
|
-
if (repoRaw === undefined) return undefined;
|
|
103
|
-
|
|
104
|
-
let repo: RepoManifest;
|
|
105
|
-
try {
|
|
106
|
-
repo = parseRepoManifest(repoRaw.value, `${repoRaw.file} at ${commit.slice(0, 12)}`);
|
|
107
|
-
} catch {
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const recipes = new Map<string, { path: string; manifest: RecipeManifest }>();
|
|
112
|
-
for (const recipePath of repo.recipes) {
|
|
113
|
-
const raw = await readManifestAt(rootDir, commit, recipePath, RECIPE_MANIFEST_BASENAME, options);
|
|
114
|
-
if (raw === undefined) continue;
|
|
115
|
-
try {
|
|
116
|
-
const manifest = parseRecipeManifest(raw.value, `${raw.file} at ${commit.slice(0, 12)}`);
|
|
117
|
-
recipes.set(recipeManifestKey(manifest), { path: recipePath, manifest });
|
|
118
|
-
} catch {
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return { repo, recipes };
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* The manifests the working tree holds, in the same shape a commit's are read
|
|
128
|
-
* into, so the two can be compared.
|
|
129
|
-
*
|
|
130
|
-
* @param validation - The validated repository.
|
|
131
|
-
*/
|
|
132
|
-
export function snapshotOf(validation: RepoValidation): ManifestSnapshot {
|
|
133
|
-
const recipes = new Map<string, { path: string; manifest: RecipeManifest }>();
|
|
134
|
-
for (const recipe of validation.recipes) {
|
|
135
|
-
recipes.set(recipe.key, { path: recipe.path, manifest: recipe.manifest });
|
|
136
|
-
}
|
|
137
|
-
return { repo: validation.manifest, recipes };
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Compares the manifests a change carries with the ones on the default branch.
|
|
142
|
-
*
|
|
143
|
-
* @param input.baseBranch - The branch the change is compared with, for the record.
|
|
144
|
-
* @param input.base - The manifests on that branch, or undefined when there was nothing to read.
|
|
145
|
-
* @param input.head - The manifests the change carries.
|
|
146
|
-
* @param input.changedPaths - Every path the change touched, relative to the repository root.
|
|
147
|
-
*/
|
|
148
|
-
export function buildChangelog(input: {
|
|
149
|
-
baseBranch: string;
|
|
150
|
-
base: ManifestSnapshot | undefined;
|
|
151
|
-
head: ManifestSnapshot;
|
|
152
|
-
changedPaths: ReadonlyArray<string>;
|
|
153
|
-
}): Changelog {
|
|
154
|
-
const { baseBranch, base, head, changedPaths } = input;
|
|
155
|
-
const changelog: Changelog = {
|
|
156
|
-
baseBranch,
|
|
157
|
-
compared: base !== undefined,
|
|
158
|
-
namespacesAdded: [],
|
|
159
|
-
namespacesRemoved: [],
|
|
160
|
-
recipesAdded: [],
|
|
161
|
-
recipesRemoved: [],
|
|
162
|
-
versionChanges: [],
|
|
163
|
-
unraised: [],
|
|
164
|
-
variables: [],
|
|
165
|
-
};
|
|
166
|
-
if (base === undefined) return changelog;
|
|
167
|
-
|
|
168
|
-
const baseNamespaces = Object.keys(base.repo.namespaces);
|
|
169
|
-
const headNamespaces = Object.keys(head.repo.namespaces);
|
|
170
|
-
changelog.namespacesAdded = headNamespaces.filter((name) => !baseNamespaces.includes(name)).sort();
|
|
171
|
-
changelog.namespacesRemoved = baseNamespaces
|
|
172
|
-
.filter((name) => !headNamespaces.includes(name))
|
|
173
|
-
.sort();
|
|
174
|
-
|
|
175
|
-
for (const [key, entry] of sortedEntries(head.recipes)) {
|
|
176
|
-
const before = base.recipes.get(key);
|
|
177
|
-
if (before === undefined) {
|
|
178
|
-
changelog.recipesAdded.push({ key, version: entry.manifest.version });
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const from = before.manifest.version;
|
|
183
|
-
const to = entry.manifest.version;
|
|
184
|
-
if (from !== to) {
|
|
185
|
-
changelog.versionChanges.push({ key, from, to });
|
|
186
|
-
} else if (pathsInside(entry.path, changedPaths).length > 0) {
|
|
187
|
-
changelog.unraised.push({ key, version: to });
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
changelog.variables.push(
|
|
191
|
-
...compareVariables(key, before.manifest.variables ?? [], entry.manifest.variables ?? [])
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
for (const [key, entry] of sortedEntries(base.recipes)) {
|
|
196
|
-
if (!head.recipes.has(key)) {
|
|
197
|
-
changelog.recipesRemoved.push({ key, version: entry.manifest.version });
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return changelog;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/** True when the changelog found nothing that merging would change. */
|
|
205
|
-
export function changelogIsEmpty(changelog: Changelog): boolean {
|
|
206
|
-
return (
|
|
207
|
-
changelog.namespacesAdded.length === 0 &&
|
|
208
|
-
changelog.namespacesRemoved.length === 0 &&
|
|
209
|
-
changelog.recipesAdded.length === 0 &&
|
|
210
|
-
changelog.recipesRemoved.length === 0 &&
|
|
211
|
-
changelog.versionChanges.length === 0 &&
|
|
212
|
-
changelog.unraised.length === 0 &&
|
|
213
|
-
changelog.variables.length === 0
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* The warning a change to a recipe's files without a version raise carries.
|
|
219
|
-
* It is a warning and not a refusal: whether the merge's release raises the
|
|
220
|
-
* version, refuses the change, or runs some other way is the repository's own
|
|
221
|
-
* business, so the changelog states the fact and leaves the decision there.
|
|
222
|
-
*/
|
|
223
|
-
export const UNRAISED_VERSION_WARNING =
|
|
224
|
-
"A recipe listed above changed without raising its version. A release run with `--ci`, " +
|
|
225
|
-
"as the workflow `sous repo init` scaffolds runs it after a merge, refuses a changed " +
|
|
226
|
-
"recipe whose version was not raised, so its version has to be raised in its manifest " +
|
|
227
|
-
"before that release can publish it.";
|
|
228
|
-
|
|
229
|
-
/** The warning a breaking variable change carries. */
|
|
230
|
-
export const BREAKING_VARIABLE_WARNING =
|
|
231
|
-
"Removing a variable or tightening its validation is usually a major change: a " +
|
|
232
|
-
"subscriber's stored answer may no longer be read, or no longer be accepted.";
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* The changelog as Markdown, the way it is appended to a proposal's body and a
|
|
236
|
-
* commit message. Every section is left out when it has nothing to say.
|
|
237
|
-
*
|
|
238
|
-
* @param changelog - The comparison to describe.
|
|
239
|
-
*/
|
|
240
|
-
export function renderChangelog(changelog: Changelog): string {
|
|
241
|
-
const lines = ["## What merging this changes", ""];
|
|
242
|
-
|
|
243
|
-
if (!changelog.compared) {
|
|
244
|
-
lines.push(
|
|
245
|
-
`Sous could not compare this change with the branch '${changelog.baseBranch}', because ` +
|
|
246
|
-
"this checkout holds no copy of it, so no changelog was generated."
|
|
247
|
-
);
|
|
248
|
-
return lines.join("\n");
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
lines.push(
|
|
252
|
-
`Generated by \`sous repo submit\` from the manifests this change carries, compared with ` +
|
|
253
|
-
`the branch '${changelog.baseBranch}'.`
|
|
254
|
-
);
|
|
255
|
-
|
|
256
|
-
if (changelogIsEmpty(changelog)) {
|
|
257
|
-
lines.push("", "Merging changes no recipe, namespace, version or variable.");
|
|
258
|
-
return lines.join("\n");
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const section = (title: string, entries: string[]) => {
|
|
262
|
-
if (entries.length === 0) return;
|
|
263
|
-
lines.push("", `**${title}**`, "", ...entries.map((entry) => `- ${entry}`));
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
section(
|
|
267
|
-
"Recipes added",
|
|
268
|
-
changelog.recipesAdded.map((entry) => `\`${entry.key}\`, at version ${entry.version}`)
|
|
269
|
-
);
|
|
270
|
-
section(
|
|
271
|
-
"Recipes retired",
|
|
272
|
-
changelog.recipesRemoved.map(
|
|
273
|
-
(entry) => `\`${entry.key}\`, last at version ${entry.version}`
|
|
274
|
-
)
|
|
275
|
-
);
|
|
276
|
-
section(
|
|
277
|
-
"Version changes",
|
|
278
|
-
changelog.versionChanges.map(
|
|
279
|
-
(entry) => `\`${entry.key}\`: ${entry.from} becomes ${entry.to}`
|
|
280
|
-
)
|
|
281
|
-
);
|
|
282
|
-
section(
|
|
283
|
-
"Changed without a version raise",
|
|
284
|
-
changelog.unraised.map(
|
|
285
|
-
(entry) =>
|
|
286
|
-
`\`${entry.key}\`: its files changed and its version is still ${entry.version}`
|
|
287
|
-
)
|
|
288
|
-
);
|
|
289
|
-
if (changelog.unraised.length > 0) {
|
|
290
|
-
lines.push("", `**Warning:** ${UNRAISED_VERSION_WARNING}`);
|
|
291
|
-
}
|
|
292
|
-
section("Namespaces added", changelog.namespacesAdded.map((name) => `\`${name}\``));
|
|
293
|
-
section("Namespaces removed", changelog.namespacesRemoved.map((name) => `\`${name}\``));
|
|
294
|
-
section("Variables", changelog.variables.map(describeVariableChange));
|
|
295
|
-
|
|
296
|
-
if (changelog.variables.some((entry) => entry.breaking)) {
|
|
297
|
-
lines.push("", `**Warning:** ${BREAKING_VARIABLE_WARNING}`);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
return lines.join("\n");
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Composes a proposal's body: the contributor's own description, then the
|
|
305
|
-
* changelog sous generated.
|
|
306
|
-
*
|
|
307
|
-
* @param description - What the contributor wrote.
|
|
308
|
-
* @param changelog - The comparison to append.
|
|
309
|
-
*/
|
|
310
|
-
export function composeProposalBody(description: string, changelog: Changelog): string {
|
|
311
|
-
return `${description.trim()}\n\n${renderChangelog(changelog)}\n`;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// --- Variables ----------------------------------------------------------------------------------
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Compares one recipe's variable definitions before and after a change.
|
|
318
|
-
*
|
|
319
|
-
* @param recipe - The recipe key.
|
|
320
|
-
* @param before - The definitions on the default branch.
|
|
321
|
-
* @param after - The definitions the change carries.
|
|
322
|
-
*/
|
|
323
|
-
export function compareVariables(
|
|
324
|
-
recipe: string,
|
|
325
|
-
before: ReadonlyArray<VariableDefinition>,
|
|
326
|
-
after: ReadonlyArray<VariableDefinition>
|
|
327
|
-
): VariableChange[] {
|
|
328
|
-
const changes: VariableChange[] = [];
|
|
329
|
-
const beforeByName = new Map(before.map((definition) => [definition.name, definition]));
|
|
330
|
-
const afterByName = new Map(after.map((definition) => [definition.name, definition]));
|
|
331
|
-
|
|
332
|
-
for (const definition of after) {
|
|
333
|
-
const previous = beforeByName.get(definition.name);
|
|
334
|
-
if (previous === undefined) {
|
|
335
|
-
changes.push({ recipe, name: definition.name, change: "added", breaking: false });
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
const fields = changedFields(previous, definition);
|
|
339
|
-
if (fields.length === 0) continue;
|
|
340
|
-
changes.push({
|
|
341
|
-
recipe,
|
|
342
|
-
name: definition.name,
|
|
343
|
-
change: "changed",
|
|
344
|
-
fields,
|
|
345
|
-
breaking: isTightened(previous, definition),
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
for (const definition of before) {
|
|
350
|
-
if (!afterByName.has(definition.name)) {
|
|
351
|
-
changes.push({ recipe, name: definition.name, change: "removed", breaking: true });
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
return changes;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* True when a changed definition accepts less than it did: a different type, a
|
|
360
|
-
* newly required answer, or a validation rule that rejects something the old
|
|
361
|
-
* one accepted. A changed pattern counts, since sous cannot prove one regular
|
|
362
|
-
* expression accepts everything another did.
|
|
363
|
-
*
|
|
364
|
-
* isTightened({ ..., validate: { maxLength: 10 } }, { ..., validate: { maxLength: 5 } });
|
|
365
|
-
* // -> true
|
|
366
|
-
*
|
|
367
|
-
* @param before - The definition on the default branch.
|
|
368
|
-
* @param after - The definition the change carries.
|
|
369
|
-
*/
|
|
370
|
-
export function isTightened(before: VariableDefinition, after: VariableDefinition): boolean {
|
|
371
|
-
if (before.type !== after.type) return true;
|
|
372
|
-
if (!before.required && after.required) return true;
|
|
373
|
-
|
|
374
|
-
const was = before.validate ?? {};
|
|
375
|
-
const now = after.validate ?? {};
|
|
376
|
-
|
|
377
|
-
if (now.pattern !== undefined && now.pattern !== was.pattern) return true;
|
|
378
|
-
if (raised(was.minLength, now.minLength)) return true;
|
|
379
|
-
if (lowered(was.maxLength, now.maxLength)) return true;
|
|
380
|
-
if (raised(was.min, now.min)) return true;
|
|
381
|
-
if (lowered(was.max, now.max)) return true;
|
|
382
|
-
if (now.enum !== undefined) {
|
|
383
|
-
if (was.enum === undefined) return true;
|
|
384
|
-
if (was.enum.some((option) => !now.enum!.includes(option))) return true;
|
|
385
|
-
}
|
|
386
|
-
return false;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
/** True when a lower bound was added or moved up. */
|
|
390
|
-
function raised(was: number | undefined, now: number | undefined): boolean {
|
|
391
|
-
return now !== undefined && (was === undefined || now > was);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/** True when an upper bound was added or moved down. */
|
|
395
|
-
function lowered(was: number | undefined, now: number | undefined): boolean {
|
|
396
|
-
return now !== undefined && (was === undefined || now < was);
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/** The top-level fields of a definition that differ, by name, in a stable order. */
|
|
400
|
-
function changedFields(before: VariableDefinition, after: VariableDefinition): string[] {
|
|
401
|
-
const keys = new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
402
|
-
const fields: string[] = [];
|
|
403
|
-
for (const key of [...keys].sort()) {
|
|
404
|
-
const was = (before as Record<string, unknown>)[key];
|
|
405
|
-
const now = (after as Record<string, unknown>)[key];
|
|
406
|
-
if (JSON.stringify(was) !== JSON.stringify(now)) fields.push(key);
|
|
407
|
-
}
|
|
408
|
-
return fields;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/** One variable change, as a changelog line. */
|
|
412
|
-
function describeVariableChange(entry: VariableChange): string {
|
|
413
|
-
const subject = `\`${entry.recipe}\`: the variable \`${entry.name}\``;
|
|
414
|
-
if (entry.change === "added") return `${subject} was added`;
|
|
415
|
-
if (entry.change === "removed") return `${subject} was removed (usually a major change)`;
|
|
416
|
-
const fields = (entry.fields ?? []).map((field) => `\`${field}\``).join(", ");
|
|
417
|
-
return (
|
|
418
|
-
`${subject} changed its ${fields}` +
|
|
419
|
-
(entry.breaking ? " and now accepts less than before (usually a major change)" : "")
|
|
420
|
-
);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// --- Reading at a commit ------------------------------------------------------------------------
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Reads one manifest at a commit, trying each supported file name in turn.
|
|
427
|
-
*
|
|
428
|
-
* @param rootDir - The repository's root directory.
|
|
429
|
-
* @param commit - The commit to read at.
|
|
430
|
-
* @param folder - The folder holding it, relative to the repository root ("" for the root).
|
|
431
|
-
* @param basename - The manifest's name without an extension.
|
|
432
|
-
* @param options - The command runner to use.
|
|
433
|
-
*/
|
|
434
|
-
async function readManifestAt(
|
|
435
|
-
rootDir: string,
|
|
436
|
-
commit: string,
|
|
437
|
-
folder: string,
|
|
438
|
-
basename: string,
|
|
439
|
-
options: RunOptions
|
|
440
|
-
): Promise<{ file: string; value: unknown } | undefined> {
|
|
441
|
-
for (const extension of MANIFEST_EXTENSIONS) {
|
|
442
|
-
const file = folder.length === 0 ? `${basename}${extension}` : path.posix.join(folder, `${basename}${extension}`);
|
|
443
|
-
const text = await readFileAtTag(rootDir, commit, file, options);
|
|
444
|
-
if (text === undefined) continue;
|
|
445
|
-
try {
|
|
446
|
-
const value =
|
|
447
|
-
extension === ".yaml" || extension === ".yml"
|
|
448
|
-
? parseYamlText(text, file)
|
|
449
|
-
: parseJsoncText(text, file);
|
|
450
|
-
return { file, value };
|
|
451
|
-
} catch {
|
|
452
|
-
return undefined;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
return undefined;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
/** A map's entries, sorted by key, so the changelog reads the same every time. */
|
|
459
|
-
function sortedEntries<T>(map: Map<string, T>): Array<[string, T]> {
|
|
460
|
-
return [...map.entries()].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
461
|
-
}
|