launchset 0.0.1 → 1.2.0
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 +98 -4
- package/dist/appstore-bVSJnUv2.js +143 -0
- package/dist/cli.js +6889 -0
- package/dist/errors-CHdD4g_K.js +58 -0
- package/dist/gitlab-child-girdQprO.js +6071 -0
- package/dist/http-dQt8kfON.js +127 -0
- package/dist/index.d.ts +854 -0
- package/dist/index.js +29 -0
- package/dist/init-Cv748KKZ.js +8222 -0
- package/dist/launchset.schema.json +1473 -0
- package/dist/play-D7nv0n-W.js +123 -0
- package/dist/prompts-S8h8cgml.js +52 -0
- package/dist/schema-CKljQNeI.js +1202 -0
- package/dist/store-BCwWrhhY.js +73 -0
- package/package.json +85 -5
- package/skills/launchset/AGENTS-snippet.md +24 -0
- package/skills/launchset/SKILL.md +205 -0
- package/skills/launchset-adopt/SKILL.md +222 -0
- package/templates/gitlab/child/build.yml +17 -0
- package/templates/gitlab/child/cli.yml +14 -0
- package/templates/gitlab/child/comment.yml +14 -0
- package/templates/gitlab/child/finalize.yml +14 -0
- package/templates/gitlab/child/header.yml +4 -0
- package/templates/gitlab/child/include.yml +6 -0
- package/templates/gitlab/child/nothing.yml +11 -0
- package/templates/gitlab/gitlab-ci.yml +23 -0
- package/templates/gitlab/launchset-preview.yml +62 -0
- package/templates/gitlab/launchset-targets.yml +44 -0
- package/templates/gitlab/launchset.yml +133 -0
- package/templates/gitlab/targets/android.yml +25 -0
- package/templates/gitlab/targets/custom-npm.yml +15 -0
- package/templates/gitlab/targets/custom.yml +23 -0
- package/templates/gitlab/targets/docker.yml +23 -0
- package/templates/gitlab/targets/ios.yml +33 -0
- package/templates/gitlab/targets/web.yml +13 -0
- package/templates/launchset-readme.md +23 -0
- package/templates/workflows/launchset-check.yml +33 -0
- package/templates/workflows/launchset-preview.yml +157 -0
- package/templates/workflows/launchset-release.yml +181 -0
- package/templates/workflows/snippets/android.yml +41 -0
- package/templates/workflows/snippets/custom-example.yml +12 -0
- package/templates/workflows/snippets/custom-npm.yml +19 -0
- package/templates/workflows/snippets/custom.yml +9 -0
- package/templates/workflows/snippets/docker-login.yml +9 -0
- package/templates/workflows/snippets/docker.yml +17 -0
- package/templates/workflows/snippets/ios.yml +46 -0
- package/templates/workflows/snippets/web.yml +20 -0
|
@@ -0,0 +1,1202 @@
|
|
|
1
|
+
import { n as LaunchsetError } from "./errors-CHdD4g_K.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import picomatch from "picomatch";
|
|
4
|
+
import semver from "semver";
|
|
5
|
+
// src/core/regex.ts
|
|
6
|
+
/** Escape a string for use inside a regular expression (also `/`, for patterns in messages). */
|
|
7
|
+
function escapeRegExp(text) {
|
|
8
|
+
return text.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
9
|
+
}
|
|
10
|
+
// src/core/types.ts
|
|
11
|
+
/** Changeset bump types, lowest first. */
|
|
12
|
+
const BUMPS = [
|
|
13
|
+
"none",
|
|
14
|
+
"patch",
|
|
15
|
+
"minor",
|
|
16
|
+
"major"
|
|
17
|
+
];
|
|
18
|
+
// src/core/versions.ts
|
|
19
|
+
/**
|
|
20
|
+
* Versions (spec 8, 10): bumps, next (free) version, maintenance lines, preview and
|
|
21
|
+
* prerelease versions, branch slugs, npm dist-tags. Pure.
|
|
22
|
+
*/
|
|
23
|
+
/** The highest version of a list, or `null`. */
|
|
24
|
+
function highestVersion(versions) {
|
|
25
|
+
let best = null;
|
|
26
|
+
for (const version of versions) if (best === null || semver.gt(version, best)) best = version;
|
|
27
|
+
return best;
|
|
28
|
+
}
|
|
29
|
+
/** A plain `X.Y.Z` version (no prerelease, no build metadata). */
|
|
30
|
+
const PLAIN_VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
31
|
+
/** True for a plain `X.Y.Z` version (no `v`, no prerelease, no build metadata). */
|
|
32
|
+
function isPlainVersion(version) {
|
|
33
|
+
return PLAIN_VERSION.test(version);
|
|
34
|
+
}
|
|
35
|
+
/** `major.minor.patch` of a semver version: `1.5.0-pr.12.3` → `1.5.0`. */
|
|
36
|
+
function baseVersionOf(version) {
|
|
37
|
+
const parsed = semver.parse(version);
|
|
38
|
+
if (!parsed) throw new LaunchsetError("invalid-version", `"${version}" is not a valid semver version`);
|
|
39
|
+
return `${parsed.major}.${parsed.minor}.${parsed.patch}`;
|
|
40
|
+
}
|
|
41
|
+
/** Major, minor and patch of a version. */
|
|
42
|
+
function versionParts(version) {
|
|
43
|
+
const parsed = semver.parse(version);
|
|
44
|
+
if (!parsed) throw new LaunchsetError("invalid-version", `"${version}" is not a valid semver version`);
|
|
45
|
+
return {
|
|
46
|
+
major: parsed.major,
|
|
47
|
+
minor: parsed.minor,
|
|
48
|
+
patch: parsed.patch
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Semver order (prereleases before their release). For `Array.prototype.sort`. */
|
|
52
|
+
function compareVersions(a, b) {
|
|
53
|
+
return semver.compare(a, b);
|
|
54
|
+
}
|
|
55
|
+
/** The highest bump (`major` > `minor` > `patch` > `none`); `none` for an empty list. */
|
|
56
|
+
function highestBump(bumps) {
|
|
57
|
+
let highest = "none";
|
|
58
|
+
for (const bump of bumps) if (BUMPS.indexOf(bump) > BUMPS.indexOf(highest)) highest = bump;
|
|
59
|
+
return highest;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The release bump for pending changesets: the highest bump, or `null` when nothing would
|
|
63
|
+
* be released (no changesets, or only `none` ones).
|
|
64
|
+
*/
|
|
65
|
+
function releaseBump(changesets) {
|
|
66
|
+
const bump = highestBump(Array.from(changesets, (c) => c.bump));
|
|
67
|
+
return bump === "none" ? null : bump;
|
|
68
|
+
}
|
|
69
|
+
function assertPlain(version, what) {
|
|
70
|
+
if (!isPlainVersion(version)) throw new LaunchsetError("invalid-version", `${what} "${version}" is not a plain X.Y.Z version`, { hint: "The root version must look like 1.4.0 (no v prefix, no prerelease suffix)." });
|
|
71
|
+
}
|
|
72
|
+
/** `semver.inc(current, bump)`; `none` returns `current`. `current` must be plain `X.Y.Z`. */
|
|
73
|
+
function nextVersion(current, bump) {
|
|
74
|
+
assertPlain(current, "version");
|
|
75
|
+
if (bump === "none") return current;
|
|
76
|
+
const next = semver.inc(current, bump);
|
|
77
|
+
if (!next) throw new LaunchsetError("invalid-version", `can't bump "${current}" (${bump})`);
|
|
78
|
+
return next;
|
|
79
|
+
}
|
|
80
|
+
function isTaken(taken, version) {
|
|
81
|
+
return typeof taken === "function" ? taken(version) : taken.has(version);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Next free version (spec 8.1): while `version` is taken (it has a release tag or any
|
|
85
|
+
* marker tag, see `takenVersions` in `tags.ts`), increase the patch. Prerelease tags never
|
|
86
|
+
* make a version taken; pass only plain versions.
|
|
87
|
+
*/
|
|
88
|
+
function nextFreeVersion(version, taken) {
|
|
89
|
+
assertPlain(version, "version");
|
|
90
|
+
let candidate = version;
|
|
91
|
+
while (isTaken(taken, candidate)) candidate = semver.inc(candidate, "patch");
|
|
92
|
+
return candidate;
|
|
93
|
+
}
|
|
94
|
+
const DEFAULT_MAINTENANCE_PATTERN = "release/*.x";
|
|
95
|
+
/**
|
|
96
|
+
* The version line of a maintenance branch, or `null` when `branch` isn't one. The single
|
|
97
|
+
* `*` in `pattern` stands for `<major>.<minor>`: `release/1.4.x` → `{ major: 1, minor: 4 }`.
|
|
98
|
+
*/
|
|
99
|
+
function parseMaintenanceBranch(branch, pattern = DEFAULT_MAINTENANCE_PATTERN) {
|
|
100
|
+
const parts = pattern.split("*");
|
|
101
|
+
if (parts.length !== 2) throw new LaunchsetError("invalid-config", `maintenanceBranches "${pattern}" must contain exactly one "*" (it stands for <major>.<minor>)`);
|
|
102
|
+
const match = new RegExp(`^${escapeRegExp(parts[0])}(0|[1-9]\\d*)\\.(0|[1-9]\\d*)${escapeRegExp(parts[1])}$`).exec(branch);
|
|
103
|
+
if (!match) return null;
|
|
104
|
+
return {
|
|
105
|
+
major: Number(match[1]),
|
|
106
|
+
minor: Number(match[2])
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/** The maintenance branch name for a line: `(1, 4)` → `release/1.4.x`. */
|
|
110
|
+
function maintenanceBranchName(line, pattern = DEFAULT_MAINTENANCE_PATTERN) {
|
|
111
|
+
if (pattern.split("*").length !== 2) throw new LaunchsetError("invalid-config", `maintenanceBranches "${pattern}" must contain exactly one "*" (it stands for <major>.<minor>)`);
|
|
112
|
+
return pattern.replace("*", `${line.major}.${line.minor}`);
|
|
113
|
+
}
|
|
114
|
+
/** True when `version` is in the line (`1.4.*` for `{ major: 1, minor: 4 }`). */
|
|
115
|
+
function isInLine(version, line) {
|
|
116
|
+
const parts = versionParts(version);
|
|
117
|
+
return parts.major === line.major && parts.minor === line.minor;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Changesets that aren't allowed on a maintenance branch (spec 8.2: only `patch` and
|
|
121
|
+
* `none`). Used by the PR check; an empty list means everything is fine.
|
|
122
|
+
*/
|
|
123
|
+
function maintenanceViolations(changesets, branch, baseBranch) {
|
|
124
|
+
const violations = [];
|
|
125
|
+
for (const changeset of changesets) if (changeset.bump === "minor" || changeset.bump === "major") violations.push({
|
|
126
|
+
path: changeset.path,
|
|
127
|
+
bump: changeset.bump,
|
|
128
|
+
message: `${changeset.path}: bump "${changeset.bump}" isn't allowed on the maintenance branch ${branch} (only patch and none). A ${changeset.bump} change belongs on ${baseBranch}: open this PR against ${baseBranch} instead.`
|
|
129
|
+
});
|
|
130
|
+
return violations;
|
|
131
|
+
}
|
|
132
|
+
/** Throws when `version` would leave the maintenance line (spec 8.2). */
|
|
133
|
+
function assertInLine(version, line, branch) {
|
|
134
|
+
if (!isInLine(version, line)) throw new LaunchsetError("outside-maintenance-line", `version ${version} is outside the ${line.major}.${line.minor} line of the maintenance branch ${branch}`, { hint: `Releases from ${branch} must stay ${line.major}.${line.minor}.*.` });
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The version a release PR sets (spec 8.1, 8.2): bump, then skip taken versions. On a
|
|
138
|
+
* maintenance branch only `patch` is allowed and the result must stay in the line.
|
|
139
|
+
*/
|
|
140
|
+
function releaseVersion(input) {
|
|
141
|
+
const { maintenance } = input;
|
|
142
|
+
if (maintenance && input.bump !== "patch") throw new LaunchsetError("maintenance-bump", `bump "${input.bump}" isn't allowed on the maintenance branch ${maintenance.branch} (only patch and none)`, { hint: `A ${input.bump} change belongs on ${maintenance.baseBranch}.` });
|
|
143
|
+
const version = nextFreeVersion(nextVersion(input.current, input.bump), input.taken);
|
|
144
|
+
if (maintenance) assertInLine(version, maintenance.line, maintenance.branch);
|
|
145
|
+
return version;
|
|
146
|
+
}
|
|
147
|
+
/** `{next}` for previews and prereleases (spec 8.3): a patch bump when nothing is pending. */
|
|
148
|
+
function previewBaseVersion(input) {
|
|
149
|
+
const bump = input.bump && input.bump !== "none" ? input.bump : "patch";
|
|
150
|
+
const next = nextVersion(input.current, bump);
|
|
151
|
+
return input.taken ? nextFreeVersion(next, input.taken) : next;
|
|
152
|
+
}
|
|
153
|
+
function assertInteger(value, what, min) {
|
|
154
|
+
if (!Number.isSafeInteger(value) || value < min) throw new LaunchsetError("invalid-number", `${what} must be an integer >= ${min}, got ${value}`);
|
|
155
|
+
}
|
|
156
|
+
function assertValid(version, why) {
|
|
157
|
+
if (!semver.valid(version)) throw new LaunchsetError("invalid-version", `"${version}" is not a valid semver version (${why})`);
|
|
158
|
+
return version;
|
|
159
|
+
}
|
|
160
|
+
/** PR preview version: `{next}-pr.{prNumber}.{runNumber}` → `1.5.0-pr.123.4`. */
|
|
161
|
+
function prPreviewVersion(next, prNumber, runNumber) {
|
|
162
|
+
assertPlain(next, "preview base version");
|
|
163
|
+
assertInteger(prNumber, "PR number", 1);
|
|
164
|
+
assertInteger(runNumber, "run number", 1);
|
|
165
|
+
return `${next}-pr.${prNumber}.${runNumber}`;
|
|
166
|
+
}
|
|
167
|
+
/** Branch preview version: `{next}-{branchSlug}.{runNumber}` → `1.5.0-develop.17`. */
|
|
168
|
+
function branchPreviewVersion(next, slug, runNumber) {
|
|
169
|
+
assertPlain(next, "preview base version");
|
|
170
|
+
assertInteger(runNumber, "run number", 1);
|
|
171
|
+
if (slug === "") throw new LaunchsetError("invalid-branch", "the branch name has no letters or digits, so it can't be used in a preview version");
|
|
172
|
+
return assertValid(`${next}-${slug}.${runNumber}`, `branch slug "${slug}"`);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The next prerelease number `n` for `{next}-{preid}.{n}` (spec 9.9): one higher than the
|
|
176
|
+
* highest existing `{next}-{preid}.<n>` version, starting at 0. Gaps are fine.
|
|
177
|
+
*/
|
|
178
|
+
function nextPrereleaseNumber(next, preid, existingVersions) {
|
|
179
|
+
const regex = new RegExp(`^${escapeRegExp(next)}-${escapeRegExp(preid)}\\.(0|[1-9]\\d*)$`);
|
|
180
|
+
let highest = -1;
|
|
181
|
+
for (const version of existingVersions) {
|
|
182
|
+
const match = regex.exec(version);
|
|
183
|
+
if (match) highest = Math.max(highest, Number(match[1]));
|
|
184
|
+
}
|
|
185
|
+
return highest + 1;
|
|
186
|
+
}
|
|
187
|
+
/** Prerelease version `{next}-{preid}.{n}` (spec 8.3, 9.9). */
|
|
188
|
+
function prereleaseVersion(next, preid, n) {
|
|
189
|
+
assertPlain(next, "prerelease base version");
|
|
190
|
+
assertInteger(n, "prerelease number", 0);
|
|
191
|
+
return assertValid(`${next}-${preid}.${n}`, `prerelease id "${preid}"`);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Branch slug (spec 8.3): lowercase, only `[a-z0-9-]` (other characters become dashes,
|
|
195
|
+
* repeated dashes collapse), at most 30 characters, no leading or trailing dash.
|
|
196
|
+
* `feature/New_Form` → `feature-new-form`. An all-digit slug gets a `b-` prefix
|
|
197
|
+
* (`007` → `b-007`): a numeric prerelease identifier with a leading zero isn't valid
|
|
198
|
+
* semver, and a numeric one would sort as a number.
|
|
199
|
+
*/
|
|
200
|
+
function branchSlug(branch) {
|
|
201
|
+
const slug = branch.toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/-{2,}/g, "-").replace(/^-+/, "").slice(0, 30).replace(/-+$/, "");
|
|
202
|
+
return /^\d+$/.test(slug) ? `b-${slug}`.slice(0, 30) : slug;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* npm dist-tag suggestion (spec 10): `latest` for base-branch releases,
|
|
206
|
+
* `release-<major>.<minor>` on maintenance branches, `<preid>` for prereleases,
|
|
207
|
+
* `pr-<n>` / `<branchSlug>` for previews.
|
|
208
|
+
*/
|
|
209
|
+
function distTag(input) {
|
|
210
|
+
switch (input.channel) {
|
|
211
|
+
case "release": {
|
|
212
|
+
if (!input.maintenance) return "latest";
|
|
213
|
+
const { major, minor } = versionParts(input.version);
|
|
214
|
+
return `release-${major}.${minor}`;
|
|
215
|
+
}
|
|
216
|
+
case "prerelease": return input.preid;
|
|
217
|
+
case "preview":
|
|
218
|
+
if (input.prNumber !== void 0) return `pr-${input.prNumber}`;
|
|
219
|
+
if (input.branchSlug) return input.branchSlug;
|
|
220
|
+
throw new LaunchsetError("invalid-preview", "a preview needs a PR number or a branch slug for its dist-tag");
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* The version written into a target's marketing-version fields: the plain base version for
|
|
225
|
+
* iOS (Apple accepts only `X.Y.Z`, spec 6.4), the run version everywhere else.
|
|
226
|
+
*/
|
|
227
|
+
function marketingVersion(type, version) {
|
|
228
|
+
return type === "ios" ? baseVersionOf(version) : version;
|
|
229
|
+
}
|
|
230
|
+
// src/core/branches.ts
|
|
231
|
+
/** Branch-name helpers (pure). */
|
|
232
|
+
const cache = /* @__PURE__ */ new Map();
|
|
233
|
+
/** True when `branch` matches the glob `pattern` (`*` doesn't cross `/`). */
|
|
234
|
+
function matchBranch(branch, pattern) {
|
|
235
|
+
let matcher = cache.get(pattern);
|
|
236
|
+
if (!matcher) {
|
|
237
|
+
matcher = picomatch(pattern, { dot: true });
|
|
238
|
+
cache.set(pattern, matcher);
|
|
239
|
+
}
|
|
240
|
+
return matcher(branch);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* True when `branch` is a maintenance branch: it fits `maintenanceBranches` with a
|
|
244
|
+
* `<major>.<minor>` in place of the `*` (`release/1.4.x`, not `release/foo.x`). The one
|
|
245
|
+
* definition of "maintenance branch"; use it everywhere.
|
|
246
|
+
*/
|
|
247
|
+
function isMaintenanceBranch(config, branch) {
|
|
248
|
+
return parseMaintenanceBranch(branch, config.maintenanceBranches) !== null;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* The `preview.branches` entry that makes a push to `branch` auto-preview (spec 9.7, 9.9),
|
|
252
|
+
* or `null`. The first matching entry wins. Branches matching `maintenanceBranches` never
|
|
253
|
+
* auto-preview, even when a pattern matches them.
|
|
254
|
+
*/
|
|
255
|
+
function findPreviewBranch(config, branch) {
|
|
256
|
+
if (!config.preview.enabled || isMaintenanceBranch(config, branch)) return null;
|
|
257
|
+
return config.preview.branches.find((entry) => matchBranch(branch, entry.branch)) ?? null;
|
|
258
|
+
}
|
|
259
|
+
// src/core/hosts.ts
|
|
260
|
+
/**
|
|
261
|
+
* The code hosts launchset knows, and what differs between them, in one table. Code that
|
|
262
|
+
* behaves differently per host asks for a trait of the host's {@link HostProfile} (does it
|
|
263
|
+
* have a pre-release flag, which CI system runs its pipelines) instead of comparing host names,
|
|
264
|
+
* so a new host (Forgejo, Gitea) is one more entry here plus its adapters, not another branch in
|
|
265
|
+
* every module. Texts per host live in tables keyed by {@link ForgeHost} too
|
|
266
|
+
* (`forge-hints.ts`), so the compiler lists everything a new host must fill in. Pure.
|
|
267
|
+
*
|
|
268
|
+
* What a new host needs is listed in design/GITLAB.md ("More hosts").
|
|
269
|
+
*/
|
|
270
|
+
/** Every host launchset knows, for validation and messages. */
|
|
271
|
+
const FORGE_HOSTS = ["github", "gitlab"];
|
|
272
|
+
/** The host when nothing says otherwise (no CI environment, no recognised remote). */
|
|
273
|
+
const DEFAULT_HOST = "github";
|
|
274
|
+
/** Every host's profile. A `Record`, so a host added to {@link FORGE_HOSTS} must get one. */
|
|
275
|
+
const HOSTS = {
|
|
276
|
+
github: {
|
|
277
|
+
host: "github",
|
|
278
|
+
name: "GitHub",
|
|
279
|
+
defaultServerUrl: "https://github.com",
|
|
280
|
+
ci: "actions",
|
|
281
|
+
prSymbol: "#",
|
|
282
|
+
prName: "PR",
|
|
283
|
+
prRef: (n) => `refs/pull/${n}/head`,
|
|
284
|
+
prPath: (n) => `pull/${n}`,
|
|
285
|
+
releaseName: "GitHub Release",
|
|
286
|
+
prereleaseName: "GitHub pre-release",
|
|
287
|
+
releaseOfTag: "Release",
|
|
288
|
+
releaseNoun: "Release",
|
|
289
|
+
prereleaseFlag: true,
|
|
290
|
+
latestFlag: true,
|
|
291
|
+
lowercaseAlerts: false,
|
|
292
|
+
nestedRepositories: false,
|
|
293
|
+
selfManagedRemotes: false,
|
|
294
|
+
gitTokenUser: "x-access-token",
|
|
295
|
+
noTokenError: "no-github-token"
|
|
296
|
+
},
|
|
297
|
+
gitlab: {
|
|
298
|
+
host: "gitlab",
|
|
299
|
+
name: "GitLab",
|
|
300
|
+
defaultServerUrl: "https://gitlab.com",
|
|
301
|
+
ci: "gitlab-ci",
|
|
302
|
+
remoteMatches: (hostname) => hostname.includes("gitlab"),
|
|
303
|
+
prSymbol: "!",
|
|
304
|
+
prName: "MR",
|
|
305
|
+
prRef: (n) => `refs/merge-requests/${n}/head`,
|
|
306
|
+
prPath: (n) => `-/merge_requests/${n}`,
|
|
307
|
+
releaseName: "GitLab release",
|
|
308
|
+
prereleaseName: "GitLab release",
|
|
309
|
+
releaseOfTag: "GitLab release",
|
|
310
|
+
releaseNoun: "release",
|
|
311
|
+
prereleaseFlag: false,
|
|
312
|
+
latestFlag: false,
|
|
313
|
+
lowercaseAlerts: true,
|
|
314
|
+
nestedRepositories: true,
|
|
315
|
+
selfManagedRemotes: true,
|
|
316
|
+
gitTokenUser: "oauth2",
|
|
317
|
+
skipCiPushOption: "ci.skip",
|
|
318
|
+
noTokenError: "no-gitlab-token"
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
/** Every CI system's profile. A `Record`, so a new {@link CiSystem} must get one. */
|
|
322
|
+
const CI_SYSTEMS = {
|
|
323
|
+
actions: {
|
|
324
|
+
ci: "actions",
|
|
325
|
+
name: "GitHub Actions",
|
|
326
|
+
detect: {
|
|
327
|
+
variable: "GITHUB_ACTIONS",
|
|
328
|
+
value: "true"
|
|
329
|
+
},
|
|
330
|
+
hosts: ["github"],
|
|
331
|
+
runPath: (id) => `actions/runs/${id}`,
|
|
332
|
+
labelEvents: true,
|
|
333
|
+
fallbackListsJobs: true,
|
|
334
|
+
ciFilesByDefault: false
|
|
335
|
+
},
|
|
336
|
+
"gitlab-ci": {
|
|
337
|
+
ci: "gitlab-ci",
|
|
338
|
+
name: "GitLab CI",
|
|
339
|
+
detect: {
|
|
340
|
+
variable: "GITLAB_CI",
|
|
341
|
+
value: "true"
|
|
342
|
+
},
|
|
343
|
+
hosts: ["gitlab"],
|
|
344
|
+
runPath: (id) => `-/pipelines/${id}`,
|
|
345
|
+
labelEvents: false,
|
|
346
|
+
fallbackListsJobs: false,
|
|
347
|
+
ciFilesByDefault: true,
|
|
348
|
+
logSection: (id, title, content, now) => {
|
|
349
|
+
const time = Math.floor(now.getTime() / 1e3);
|
|
350
|
+
return `\u001b[0Ksection_start:${time}:${id}[collapsed=true]\r\u001b[0K${title}\n${content}\u001b[0Ksection_end:${time}:${id}\r\u001b[0K\n`;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
/**
|
|
355
|
+
* The order CI systems are recognised from the environment. A CI that also sets another CI's
|
|
356
|
+
* variable (Forgejo and Gitea runners may set `GITHUB_ACTIONS` as well) must come before it.
|
|
357
|
+
*/
|
|
358
|
+
const CI_DETECTION_ORDER = ["gitlab-ci", "actions"];
|
|
359
|
+
/** The CI system the environment says runs launchset, if any (ignores `LAUNCHSET_HOST`). */
|
|
360
|
+
function ciFromEnv(env) {
|
|
361
|
+
return CI_DETECTION_ORDER.find((ci) => {
|
|
362
|
+
const { variable, value } = CI_SYSTEMS[ci].detect;
|
|
363
|
+
return env[variable] === value;
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* The CI system for a run on `host`: the one the environment names when it serves `host`,
|
|
368
|
+
* else the host's own ({@link HostProfile.ci}).
|
|
369
|
+
*/
|
|
370
|
+
function ciSystemFor(host, env) {
|
|
371
|
+
const detected = ciFromEnv(env);
|
|
372
|
+
return detected && CI_SYSTEMS[detected].hosts.includes(host) ? detected : hostProfile(host).ci;
|
|
373
|
+
}
|
|
374
|
+
/** The profile of CI system `ci`. */
|
|
375
|
+
function ciProfile(ci) {
|
|
376
|
+
return CI_SYSTEMS[ci];
|
|
377
|
+
}
|
|
378
|
+
/** The profile of `host` (default {@link DEFAULT_HOST}). */
|
|
379
|
+
function hostProfile(host = DEFAULT_HOST) {
|
|
380
|
+
return HOSTS[host];
|
|
381
|
+
}
|
|
382
|
+
/** True when `value` names a known host. */
|
|
383
|
+
function isForgeHost(value) {
|
|
384
|
+
return FORGE_HOSTS.includes(value);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* The CI system of a host named by a string (an init answer), the default host's for anything
|
|
388
|
+
* unknown.
|
|
389
|
+
*/
|
|
390
|
+
function ciOf(host) {
|
|
391
|
+
return hostProfile(isForgeHost(host) ? host : DEFAULT_HOST).ci;
|
|
392
|
+
}
|
|
393
|
+
// src/core/config/schema.ts
|
|
394
|
+
/**
|
|
395
|
+
* Config schema (spec 5). Pure: no I/O. `src/config/load.ts` loads the file and checks
|
|
396
|
+
* that referenced files exist.
|
|
397
|
+
*
|
|
398
|
+
* The schema normalizes the input into a `ResolvedConfig`: defaults filled in, shorthand
|
|
399
|
+
* forms expanded (docker `image` and `tags`, `preview.branches` strings, plist `file`),
|
|
400
|
+
* and each target's `buildNumber` merged over the root one.
|
|
401
|
+
*/
|
|
402
|
+
const TARGET_NAME = /^[a-z0-9][a-z0-9-]*$/;
|
|
403
|
+
const DEFAULT_DOCKER_TAGS = {
|
|
404
|
+
release: [
|
|
405
|
+
"{version}",
|
|
406
|
+
"{major}.{minor}",
|
|
407
|
+
"{major}",
|
|
408
|
+
"latest"
|
|
409
|
+
],
|
|
410
|
+
preview: [
|
|
411
|
+
"{version}",
|
|
412
|
+
"pr-{prNumber}",
|
|
413
|
+
"{branchSlug}"
|
|
414
|
+
],
|
|
415
|
+
prerelease: ["{version}", "{branchSlug}"]
|
|
416
|
+
};
|
|
417
|
+
/**
|
|
418
|
+
* Default `check.bots`: Dependabot's and Renovate's GitHub App logins, and Renovate's username
|
|
419
|
+
* on gitlab.com (`renovate-bot`; self-managed GitLab instances name their bots themselves).
|
|
420
|
+
*/
|
|
421
|
+
const DEFAULT_BOTS = [
|
|
422
|
+
"dependabot[bot]",
|
|
423
|
+
"renovate[bot]",
|
|
424
|
+
"renovate-bot"
|
|
425
|
+
];
|
|
426
|
+
const nonEmpty = z.string().min(1, "expected a non-empty string");
|
|
427
|
+
const strategy = z.enum([
|
|
428
|
+
"timestamp",
|
|
429
|
+
"run-number",
|
|
430
|
+
"semver",
|
|
431
|
+
"eas"
|
|
432
|
+
]);
|
|
433
|
+
const epoch = z.iso.datetime({
|
|
434
|
+
offset: true,
|
|
435
|
+
message: "expected an ISO 8601 date-time"
|
|
436
|
+
});
|
|
437
|
+
const offset = z.number().int().min(0, "expected an integer >= 0");
|
|
438
|
+
/** `timestamp` only. No default in the schema, so validation can tell it was set (read it with `?? "second"`). */
|
|
439
|
+
const unit = z.enum(["second", "minute"]);
|
|
440
|
+
const buildNumberSchema = z.strictObject({
|
|
441
|
+
strategy: strategy.default("timestamp"),
|
|
442
|
+
epoch: epoch.default("2020-01-01T00:00:00Z"),
|
|
443
|
+
offset: offset.default(0),
|
|
444
|
+
unit: unit.optional()
|
|
445
|
+
});
|
|
446
|
+
/** A target's override: every field optional, merged over the root `buildNumber`. */
|
|
447
|
+
const buildNumberOverrideSchema = z.strictObject({
|
|
448
|
+
strategy: strategy.optional(),
|
|
449
|
+
epoch: epoch.optional(),
|
|
450
|
+
offset: offset.optional(),
|
|
451
|
+
unit: unit.optional()
|
|
452
|
+
});
|
|
453
|
+
const jsonFileSchema = z.strictObject({
|
|
454
|
+
path: nonEmpty,
|
|
455
|
+
kind: z.literal("json"),
|
|
456
|
+
/** Dotted key path, e.g. `version` or `expo.version`. */
|
|
457
|
+
key: nonEmpty
|
|
458
|
+
});
|
|
459
|
+
const yamlFileSchema = z.strictObject({
|
|
460
|
+
path: nonEmpty,
|
|
461
|
+
kind: z.literal("yaml"),
|
|
462
|
+
key: nonEmpty
|
|
463
|
+
});
|
|
464
|
+
/** Placeholders a regex `replace` may use (spec 6.6). */
|
|
465
|
+
const REGEX_REPLACE_PLACEHOLDERS = [
|
|
466
|
+
"version",
|
|
467
|
+
"major",
|
|
468
|
+
"minor",
|
|
469
|
+
"patch",
|
|
470
|
+
"buildNumber"
|
|
471
|
+
];
|
|
472
|
+
/**
|
|
473
|
+
* Unknown placeholders in a regex `replace`. Other braces (JSON, code) stay literal, so only
|
|
474
|
+
* identifier-like `{name}` not preceded by `$` is checked: typos like `{versoin}` fail at load.
|
|
475
|
+
*/
|
|
476
|
+
function checkReplacePlaceholders(value, ctx) {
|
|
477
|
+
for (const match of value.matchAll(/(?<!\$)\{([A-Za-z_][A-Za-z0-9_]*)\}/g)) if (!REGEX_REPLACE_PLACEHOLDERS.includes(match[1])) ctx.addIssue({
|
|
478
|
+
code: "custom",
|
|
479
|
+
message: `unknown placeholder ${match[0]}: expected ${REGEX_REPLACE_PLACEHOLDERS.map((p) => `{${p}}`).join(", ")}`
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
const regexFileSchema = z.strictObject({
|
|
483
|
+
path: nonEmpty,
|
|
484
|
+
kind: z.literal("regex"),
|
|
485
|
+
/** JavaScript regular expression source. Must match exactly once. */
|
|
486
|
+
pattern: nonEmpty,
|
|
487
|
+
/** Replacement with placeholders `{version}`, `{major}`, `{minor}`, `{patch}`, `{buildNumber}`. */
|
|
488
|
+
replace: z.string().superRefine(checkReplacePlaceholders),
|
|
489
|
+
/** Extra RegExp flags (`g` is not allowed; `m`, `s`, `i`, `u` are). */
|
|
490
|
+
flags: z.string().regex(/^[imsu]*$/, "expected only the RegExp flags i, m, s, u").optional()
|
|
491
|
+
}).superRefine((entry, ctx) => {
|
|
492
|
+
try {
|
|
493
|
+
new RegExp(entry.pattern, entry.flags);
|
|
494
|
+
} catch (error) {
|
|
495
|
+
ctx.addIssue({
|
|
496
|
+
code: "custom",
|
|
497
|
+
path: ["pattern"],
|
|
498
|
+
message: `expected a valid regular expression (${error.message})`
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
const imageFileSchema = z.strictObject({
|
|
503
|
+
/** File path or glob, e.g. `deploy/k8s/*.yaml`. */
|
|
504
|
+
path: nonEmpty,
|
|
505
|
+
kind: z.literal("image")
|
|
506
|
+
});
|
|
507
|
+
const fileEntrySchema = z.discriminatedUnion("kind", [
|
|
508
|
+
jsonFileSchema,
|
|
509
|
+
yamlFileSchema,
|
|
510
|
+
regexFileSchema,
|
|
511
|
+
imageFileSchema
|
|
512
|
+
]);
|
|
513
|
+
/** A target's GitLab settings (ignored on GitHub). */
|
|
514
|
+
const targetGitLabSchema = z.strictObject({
|
|
515
|
+
/**
|
|
516
|
+
* The shell of the runner that runs this target's job: `sh` (default: POSIX sh, bash) or
|
|
517
|
+
* `powershell` (a Windows runner: Windows PowerShell 5.1 or PowerShell 7, `pwsh`). The child
|
|
518
|
+
* pipeline writes launchset's lines of the job in that shell.
|
|
519
|
+
*/
|
|
520
|
+
shell: z.enum(["sh", "powershell"], { error: "expected \"sh\" or \"powershell\" (\"powershell\" covers Windows PowerShell 5.1 and PowerShell 7, pwsh)" }).default("sh") });
|
|
521
|
+
const commonTargetFields = {
|
|
522
|
+
/** `auto` (default): built by every release. `manual`: shipped on demand (spec 9.8). */
|
|
523
|
+
release: z.enum(["auto", "manual"]).default("auto"),
|
|
524
|
+
buildNumber: buildNumberOverrideSchema.optional(),
|
|
525
|
+
files: z.array(fileEntrySchema).default([]),
|
|
526
|
+
/**
|
|
527
|
+
* Targets whose jobs must finish first, in the same pipeline (GitLab only): this target's job
|
|
528
|
+
* gets their artifacts. Validated: known names, no cycles, an auto target only after auto
|
|
529
|
+
* targets.
|
|
530
|
+
*/
|
|
531
|
+
after: z.array(nonEmpty).optional(),
|
|
532
|
+
gitlab: targetGitLabSchema.optional()
|
|
533
|
+
};
|
|
534
|
+
/** Placeholders a Docker tag template may use (spec 6.1). */
|
|
535
|
+
const DOCKER_TAG_PLACEHOLDERS = [
|
|
536
|
+
"version",
|
|
537
|
+
"major",
|
|
538
|
+
"minor",
|
|
539
|
+
"patch",
|
|
540
|
+
"preid",
|
|
541
|
+
"prNumber",
|
|
542
|
+
"branchSlug",
|
|
543
|
+
"sha",
|
|
544
|
+
"shortSha",
|
|
545
|
+
"buildNumber"
|
|
546
|
+
];
|
|
547
|
+
/** Checks that every `{placeholder}` in a template is one of `allowed`. */
|
|
548
|
+
const knownPlaceholders = (allowed) => (value, ctx) => {
|
|
549
|
+
for (const match of value.matchAll(/\{([^{}]*)\}/g)) if (!allowed.includes(match[1])) ctx.addIssue({
|
|
550
|
+
code: "custom",
|
|
551
|
+
message: `unknown placeholder ${match[0]}: expected ${allowed.map((p) => `{${p}}`).join(", ")}`
|
|
552
|
+
});
|
|
553
|
+
};
|
|
554
|
+
/** OCI tag grammar. */
|
|
555
|
+
const DOCKER_TAG = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$/;
|
|
556
|
+
/** Placeholders must be known, and the literal parts must fit the OCI tag grammar. */
|
|
557
|
+
const dockerTagTemplate = nonEmpty.superRefine((value, ctx) => {
|
|
558
|
+
const allowed = DOCKER_TAG_PLACEHOLDERS;
|
|
559
|
+
if ([...value.matchAll(/\{([^{}]*)\}/g)].some((m) => !allowed.includes(m[1]))) {
|
|
560
|
+
knownPlaceholders(allowed)(value, ctx);
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
const sample = renderSample(value);
|
|
564
|
+
if (!DOCKER_TAG.test(sample)) ctx.addIssue({
|
|
565
|
+
code: "custom",
|
|
566
|
+
message: `"${value}" can't become a valid Docker tag (it renders like "${sample}"): use only letters, digits, _ . and -, don't start with . or -, and keep it under 128 characters`
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
const dockerTagListSchema = z.array(dockerTagTemplate).min(1, "expected at least one tag template");
|
|
570
|
+
/** An image name without tag or digest; `localhost:5000/app` has a port, not a tag. */
|
|
571
|
+
const imageName = nonEmpty.superRefine((value, ctx) => {
|
|
572
|
+
const lastSegment = value.slice(value.lastIndexOf("/") + 1);
|
|
573
|
+
if (value.includes("@") || lastSegment.includes(":")) ctx.addIssue({
|
|
574
|
+
code: "custom",
|
|
575
|
+
message: `expected an image name without tag or digest, like "ghcr.io/org/app" (got "${value}"); set tags with "tags"`
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
const dockerTargetSchema = z.strictObject({
|
|
579
|
+
type: z.literal("docker"),
|
|
580
|
+
image: z.union([imageName, z.array(imageName).min(1, "expected at least one image")], { error: "expected an image name like \"ghcr.io/org/app\", or a list of image names" }),
|
|
581
|
+
tags: z.union([dockerTagListSchema, z.strictObject({
|
|
582
|
+
release: dockerTagListSchema.optional(),
|
|
583
|
+
preview: dockerTagListSchema.optional(),
|
|
584
|
+
prerelease: dockerTagListSchema.optional()
|
|
585
|
+
})], { error: "expected a list of tag templates (the release list), or an object with release, preview and/or prerelease lists" }).optional(),
|
|
586
|
+
verify: z.array(z.literal("registry")).default([]),
|
|
587
|
+
...commonTargetFields
|
|
588
|
+
});
|
|
589
|
+
const webTargetSchema = z.strictObject({
|
|
590
|
+
type: z.literal("web"),
|
|
591
|
+
verify: z.array(z.never({ error: "web targets have no verify checks: remove this entry" })).default([]),
|
|
592
|
+
...commonTargetFields
|
|
593
|
+
});
|
|
594
|
+
const androidSourceSchema = z.discriminatedUnion("kind", [
|
|
595
|
+
z.strictObject({
|
|
596
|
+
kind: z.literal("gradle"),
|
|
597
|
+
file: nonEmpty
|
|
598
|
+
}),
|
|
599
|
+
z.strictObject({
|
|
600
|
+
kind: z.literal("gradle-properties"),
|
|
601
|
+
file: nonEmpty,
|
|
602
|
+
versionNameKey: nonEmpty.default("VERSION_NAME"),
|
|
603
|
+
versionCodeKey: nonEmpty.default("VERSION_CODE")
|
|
604
|
+
}),
|
|
605
|
+
z.strictObject({
|
|
606
|
+
kind: z.literal("capacitor"),
|
|
607
|
+
dir: nonEmpty
|
|
608
|
+
}),
|
|
609
|
+
z.strictObject({
|
|
610
|
+
kind: z.literal("expo"),
|
|
611
|
+
file: nonEmpty.default("app.json")
|
|
612
|
+
})
|
|
613
|
+
]);
|
|
614
|
+
const androidTargetSchema = z.strictObject({
|
|
615
|
+
type: z.literal("android"),
|
|
616
|
+
source: androidSourceSchema,
|
|
617
|
+
store: z.strictObject({ packageName: nonEmpty }).optional(),
|
|
618
|
+
verify: z.array(z.literal("store")).default([]),
|
|
619
|
+
...commonTargetFields
|
|
620
|
+
});
|
|
621
|
+
const xcodeTargets = z.array(nonEmpty).min(1, "expected at least one Xcode target name");
|
|
622
|
+
const iosSourceSchema = z.discriminatedUnion("kind", [
|
|
623
|
+
z.strictObject({
|
|
624
|
+
kind: z.literal("xcodeproj"),
|
|
625
|
+
/** Path to the `.xcodeproj` directory (the stamper edits `<file>/project.pbxproj`). */
|
|
626
|
+
file: nonEmpty,
|
|
627
|
+
xcodeTargets: xcodeTargets.optional()
|
|
628
|
+
}),
|
|
629
|
+
z.strictObject({
|
|
630
|
+
kind: z.literal("plist"),
|
|
631
|
+
/** One plist (`file`) or several (`files`). */
|
|
632
|
+
file: nonEmpty.optional(),
|
|
633
|
+
files: z.array(nonEmpty).min(1, "expected at least one Info.plist path").optional()
|
|
634
|
+
}).superRefine((source, ctx) => {
|
|
635
|
+
if (source.file !== void 0 && source.files !== void 0) ctx.addIssue({
|
|
636
|
+
code: "custom",
|
|
637
|
+
message: "use either file (one Info.plist) or files (several), not both"
|
|
638
|
+
});
|
|
639
|
+
}),
|
|
640
|
+
z.strictObject({
|
|
641
|
+
kind: z.literal("xcconfig"),
|
|
642
|
+
file: nonEmpty
|
|
643
|
+
}),
|
|
644
|
+
z.strictObject({
|
|
645
|
+
kind: z.literal("capacitor"),
|
|
646
|
+
dir: nonEmpty,
|
|
647
|
+
xcodeTargets: xcodeTargets.optional()
|
|
648
|
+
}),
|
|
649
|
+
z.strictObject({
|
|
650
|
+
kind: z.literal("expo"),
|
|
651
|
+
file: nonEmpty.default("app.json")
|
|
652
|
+
})
|
|
653
|
+
]);
|
|
654
|
+
const iosTargetSchema = z.strictObject({
|
|
655
|
+
type: z.literal("ios"),
|
|
656
|
+
source: iosSourceSchema,
|
|
657
|
+
store: z.strictObject({ appId: z.string().regex(/^\d+$/, "expected the numeric Apple ID of the app") }).optional(),
|
|
658
|
+
verify: z.array(z.literal("store")).default([]),
|
|
659
|
+
...commonTargetFields
|
|
660
|
+
});
|
|
661
|
+
const customTargetSchema = z.strictObject({
|
|
662
|
+
type: z.literal("custom"),
|
|
663
|
+
/** For `verify: ["npm"]` (spec 7.5). */
|
|
664
|
+
npm: z.strictObject({ package: nonEmpty.default("package.json") }).optional(),
|
|
665
|
+
verify: z.array(z.literal("npm")).default([]),
|
|
666
|
+
...commonTargetFields
|
|
667
|
+
});
|
|
668
|
+
const targetSchema = z.discriminatedUnion("type", [
|
|
669
|
+
dockerTargetSchema,
|
|
670
|
+
webTargetSchema,
|
|
671
|
+
androidTargetSchema,
|
|
672
|
+
iosTargetSchema,
|
|
673
|
+
customTargetSchema
|
|
674
|
+
]);
|
|
675
|
+
const previewTargetsSchema = z.union([z.literal("all"), z.array(nonEmpty)], { error: "expected \"all\" or a list of target names" });
|
|
676
|
+
const previewBranchSchema = z.union([nonEmpty, z.strictObject({
|
|
677
|
+
/** Branch glob, e.g. `feature/*`. */
|
|
678
|
+
branch: nonEmpty,
|
|
679
|
+
targets: previewTargetsSchema.optional(),
|
|
680
|
+
/** Prerelease id (e.g. `alpha`): makes this a prerelease branch (spec 9.9). */
|
|
681
|
+
prerelease: z.string().regex(/^[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*$/, "expected a prerelease id like alpha, beta or rc (letters, digits and dashes, not only digits)").optional()
|
|
682
|
+
})], { error: "expected a branch glob like \"develop\" or \"feature/*\", or an object { branch, targets?, prerelease? }" });
|
|
683
|
+
const previewSchema = z.strictObject({
|
|
684
|
+
label: nonEmpty.default("launchset:preview"),
|
|
685
|
+
rebuildOnPush: z.boolean().default(true),
|
|
686
|
+
branches: z.array(previewBranchSchema).default([]),
|
|
687
|
+
targets: previewTargetsSchema.default("all")
|
|
688
|
+
});
|
|
689
|
+
const placeholderTemplate = (required) => nonEmpty.refine((value) => required.every((p) => value.includes(`{${p}}`)), { message: `expected a template containing ${required.map((p) => `{${p}}`).join(" and ")}` }).superRefine(knownPlaceholders(required));
|
|
690
|
+
/**
|
|
691
|
+
* `changelog`. `links` (PR / MR links and authors, spec 12) was called `github`; the old name
|
|
692
|
+
* is still accepted and mapped onto `links`. Giving both with different values is an error.
|
|
693
|
+
*/
|
|
694
|
+
const changelogSchema = z.strictObject({
|
|
695
|
+
file: nonEmpty.default("CHANGELOG.md"),
|
|
696
|
+
/** Add PR links and authors (spec 12); default true. */
|
|
697
|
+
links: z.boolean().optional().meta({ default: true }),
|
|
698
|
+
/** Deprecated alias of `links`. */
|
|
699
|
+
github: z.boolean().optional().meta({
|
|
700
|
+
deprecated: true,
|
|
701
|
+
description: "Deprecated: the old name of \"links\"."
|
|
702
|
+
})
|
|
703
|
+
}).superRefine((value, ctx) => {
|
|
704
|
+
if (value.links !== void 0 && value.github !== void 0 && value.links !== value.github) ctx.addIssue({
|
|
705
|
+
code: "custom",
|
|
706
|
+
path: ["github"],
|
|
707
|
+
message: `"github" is the old name of "links", which is set to ${value.links}: keep only "links"`
|
|
708
|
+
});
|
|
709
|
+
}).transform(({ file, links, github }) => ({
|
|
710
|
+
file,
|
|
711
|
+
links: links ?? github ?? true
|
|
712
|
+
}));
|
|
713
|
+
/** A literal repo-relative path of a `.yml` / `.yaml` file (for `gitlab.include`). */
|
|
714
|
+
const localYamlPath = nonEmpty.superRefine((value, ctx) => {
|
|
715
|
+
if (value.includes("$") || /[*?[\]{}]/.test(value)) ctx.addIssue({
|
|
716
|
+
code: "custom",
|
|
717
|
+
message: `expected a literal path (no variables or wildcards: a generated child pipeline can't use them in include), got "${value}"`
|
|
718
|
+
});
|
|
719
|
+
else if (!/\.ya?ml$/i.test(value)) ctx.addIssue({
|
|
720
|
+
code: "custom",
|
|
721
|
+
message: `expected a .yml or .yaml file, got "${value}"`
|
|
722
|
+
});
|
|
723
|
+
else if (/^[a-z][a-z0-9+.-]*:/i.test(value) || value.split(/[\\/]/).includes("..")) ctx.addIssue({
|
|
724
|
+
code: "custom",
|
|
725
|
+
message: `expected a path inside the repository, got "${value}"`
|
|
726
|
+
});
|
|
727
|
+
});
|
|
728
|
+
/** GitLab settings (ignored on GitHub). */
|
|
729
|
+
const gitlabSchema = z.strictObject({
|
|
730
|
+
/**
|
|
731
|
+
* Extra local files the child pipeline includes before the targets file: hidden job
|
|
732
|
+
* templates (names starting with `.`), `variables` and `default`, which the
|
|
733
|
+
* `.launchset-<target>` jobs extend. Checked when the child pipeline is written.
|
|
734
|
+
*/
|
|
735
|
+
include: z.array(localYamlPath).default([]),
|
|
736
|
+
/**
|
|
737
|
+
* Let launchset's release and prerelease tags start tag pipelines. Default false: every tag
|
|
738
|
+
* launchset pushes on GitLab is pushed with `-o ci.skip` (marker and partial tags always).
|
|
739
|
+
*/
|
|
740
|
+
tagPipelines: z.boolean().default(false)
|
|
741
|
+
});
|
|
742
|
+
const configSchema = z.strictObject({
|
|
743
|
+
version: z.strictObject({ file: nonEmpty.default("package.json") }).prefault({}),
|
|
744
|
+
changelog: changelogSchema.prefault({}),
|
|
745
|
+
baseBranch: nonEmpty.default("main"),
|
|
746
|
+
/** Branch pattern; its single `*` stands for `<major>.<minor>` (spec 8.2). */
|
|
747
|
+
maintenanceBranches: nonEmpty.refine((value) => value.split("*").length === 2, { message: "expected a branch pattern with exactly one \"*\", which stands for <major>.<minor> (default \"release/*.x\")" }).default("release/*.x"),
|
|
748
|
+
tags: z.strictObject({
|
|
749
|
+
release: placeholderTemplate(["version"]).default("v{version}"),
|
|
750
|
+
marker: placeholderTemplate(["target", "version"]).default("launchset/{target}@{version}"),
|
|
751
|
+
partial: placeholderTemplate(["version"]).default("launchset/partial/{version}")
|
|
752
|
+
}).prefault({}),
|
|
753
|
+
buildNumber: buildNumberSchema.prefault({}),
|
|
754
|
+
check: z.strictObject({ bots: z.array(nonEmpty).default(DEFAULT_BOTS) }).prefault({}),
|
|
755
|
+
/** `false` disables previews and prerelease branches (needed for the `semver` strategy). */
|
|
756
|
+
preview: z.union([z.literal(false), previewSchema], { error: "expected false (to disable previews) or an object with preview settings" }).prefault({}),
|
|
757
|
+
gitlab: gitlabSchema.optional(),
|
|
758
|
+
targets: z.record(z.string(), targetSchema)
|
|
759
|
+
});
|
|
760
|
+
var ConfigError = class extends LaunchsetError {
|
|
761
|
+
issues;
|
|
762
|
+
file;
|
|
763
|
+
constructor(issues, file) {
|
|
764
|
+
const where = file ? ` in ${file}` : "";
|
|
765
|
+
super("invalid-config", `Invalid launchset config${where}:\n${issues.map((i) => ` - ${i.path || "(root)"}: ${i.message}`).join("\n")}`, { hint: "See the configuration reference in the launchset docs." });
|
|
766
|
+
this.name = "ConfigError";
|
|
767
|
+
this.issues = issues;
|
|
768
|
+
if (file !== void 0) this.file = file;
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
const PLAIN_VERSION_TAG = /^v?\d+\.\d+\.\d+$/;
|
|
772
|
+
/** Sample values used to check that preview/prerelease templates never render a plain version. */
|
|
773
|
+
const SAMPLE_PLACEHOLDERS = {
|
|
774
|
+
version: "1.5.0-pr.1.1",
|
|
775
|
+
major: "1",
|
|
776
|
+
minor: "5",
|
|
777
|
+
patch: "0",
|
|
778
|
+
preid: "alpha",
|
|
779
|
+
prNumber: "1",
|
|
780
|
+
branchSlug: "feature-x",
|
|
781
|
+
sha: "0123456789abcdef0123456789abcdef01234567",
|
|
782
|
+
shortSha: "0123456",
|
|
783
|
+
buildNumber: "100"
|
|
784
|
+
};
|
|
785
|
+
function renderSample(template) {
|
|
786
|
+
return template.replace(/\{(\w+)\}/g, (match, key) => SAMPLE_PLACEHOLDERS[key] ?? match);
|
|
787
|
+
}
|
|
788
|
+
function pathToString(path) {
|
|
789
|
+
return path.map((p) => String(p)).join(".");
|
|
790
|
+
}
|
|
791
|
+
const UNKNOWN_KEY_MESSAGE = "unknown key (check the spelling; see the configuration reference)";
|
|
792
|
+
const TYPE_NAMES = {
|
|
793
|
+
string: "a string",
|
|
794
|
+
number: "a number",
|
|
795
|
+
int: "an integer",
|
|
796
|
+
boolean: "true or false",
|
|
797
|
+
array: "a list",
|
|
798
|
+
object: "an object",
|
|
799
|
+
record: "an object",
|
|
800
|
+
null: "null",
|
|
801
|
+
undefined: "nothing"
|
|
802
|
+
};
|
|
803
|
+
function typeOf(value) {
|
|
804
|
+
if (value === null) return "null";
|
|
805
|
+
if (Array.isArray(value)) return "a list";
|
|
806
|
+
switch (typeof value) {
|
|
807
|
+
case "string": return `the string ${JSON.stringify(value)}`;
|
|
808
|
+
case "number": return `the number ${value}`;
|
|
809
|
+
case "boolean": return String(value);
|
|
810
|
+
case "object": return "an object";
|
|
811
|
+
default: return typeof value;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
function formatValues(values) {
|
|
815
|
+
const shown = values.map((v) => JSON.stringify(v));
|
|
816
|
+
return shown.length === 1 ? shown[0] : `one of ${shown.join(", ")}`;
|
|
817
|
+
}
|
|
818
|
+
/** Zod's own default messages start like this; anything else was written in this file. */
|
|
819
|
+
const isDefaultMessage = (message) => /^Invalid (input|option|discriminator)/.test(message);
|
|
820
|
+
/** True when a union branch failed only because the value has the wrong type. */
|
|
821
|
+
function failedAtRoot(branch) {
|
|
822
|
+
return branch.every((i) => i.path.length === 0 && (i.code === "invalid_type" || i.code === "invalid_value"));
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* Turn zod issues into `ConfigIssue`s with readable messages and full paths. Parse with
|
|
826
|
+
* `{ reportInput: true }`: the input tells "missing" apart from "wrong value".
|
|
827
|
+
*/
|
|
828
|
+
function formatZodIssues(issues, base = []) {
|
|
829
|
+
const out = [];
|
|
830
|
+
for (const issue of issues) {
|
|
831
|
+
const path = [...base, ...issue.path];
|
|
832
|
+
const at = pathToString(path);
|
|
833
|
+
const missing = issue.input === void 0;
|
|
834
|
+
switch (issue.code) {
|
|
835
|
+
case "unrecognized_keys":
|
|
836
|
+
for (const key of issue.keys) out.push({
|
|
837
|
+
path: pathToString([...path, key]),
|
|
838
|
+
message: UNKNOWN_KEY_MESSAGE
|
|
839
|
+
});
|
|
840
|
+
break;
|
|
841
|
+
case "invalid_union": {
|
|
842
|
+
if ("options" in issue && issue.discriminator && issue.options) {
|
|
843
|
+
const value = issue.input?.[issue.discriminator];
|
|
844
|
+
const expected = formatValues(issue.options);
|
|
845
|
+
out.push({
|
|
846
|
+
path: at,
|
|
847
|
+
message: value === void 0 ? `required: expected ${expected}` : `expected ${expected}, got ${typeOf(value)}`
|
|
848
|
+
});
|
|
849
|
+
break;
|
|
850
|
+
}
|
|
851
|
+
const progressed = issue.errors.filter((branch) => !failedAtRoot(branch));
|
|
852
|
+
if (progressed.length === 1) {
|
|
853
|
+
out.push(...formatZodIssues(progressed[0], path));
|
|
854
|
+
break;
|
|
855
|
+
}
|
|
856
|
+
const message = isDefaultMessage(issue.message) ? `expected ${issue.errors.flat().map((i) => i.code === "invalid_type" ? TYPE_NAMES[i.expected] ?? i.expected : i.code === "invalid_value" ? formatValues(i.values) : i.message).join(" or ")}` : issue.message;
|
|
857
|
+
out.push({
|
|
858
|
+
path: at,
|
|
859
|
+
message: missing ? `required: ${message}` : `${message}, got ${typeOf(issue.input)}`
|
|
860
|
+
});
|
|
861
|
+
break;
|
|
862
|
+
}
|
|
863
|
+
case "invalid_type": {
|
|
864
|
+
if (!isDefaultMessage(issue.message)) {
|
|
865
|
+
out.push({
|
|
866
|
+
path: at,
|
|
867
|
+
message: issue.message
|
|
868
|
+
});
|
|
869
|
+
break;
|
|
870
|
+
}
|
|
871
|
+
const expected = TYPE_NAMES[issue.expected] ?? issue.expected;
|
|
872
|
+
out.push({
|
|
873
|
+
path: at,
|
|
874
|
+
message: missing ? `required: expected ${expected}` : `expected ${expected}, got ${typeOf(issue.input)}`
|
|
875
|
+
});
|
|
876
|
+
break;
|
|
877
|
+
}
|
|
878
|
+
case "invalid_value": {
|
|
879
|
+
if (!isDefaultMessage(issue.message)) {
|
|
880
|
+
out.push({
|
|
881
|
+
path: at,
|
|
882
|
+
message: issue.message
|
|
883
|
+
});
|
|
884
|
+
break;
|
|
885
|
+
}
|
|
886
|
+
const expected = formatValues(issue.values);
|
|
887
|
+
out.push({
|
|
888
|
+
path: at,
|
|
889
|
+
message: missing ? `required: expected ${expected}` : `expected ${expected}, got ${typeOf(issue.input)}`
|
|
890
|
+
});
|
|
891
|
+
break;
|
|
892
|
+
}
|
|
893
|
+
default: out.push({
|
|
894
|
+
path: at,
|
|
895
|
+
message: isDefaultMessage(issue.message) ? issue.message.replace(/^Invalid (input|option): /, "") : issue.message
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
return out;
|
|
900
|
+
}
|
|
901
|
+
function resolveTarget(name, target, root) {
|
|
902
|
+
const buildNumber = {
|
|
903
|
+
strategy: target.buildNumber?.strategy ?? root.strategy,
|
|
904
|
+
epoch: target.buildNumber?.epoch ?? root.epoch,
|
|
905
|
+
offset: target.buildNumber?.offset ?? root.offset
|
|
906
|
+
};
|
|
907
|
+
const unit = target.buildNumber?.unit ?? root.unit;
|
|
908
|
+
if (unit !== void 0) buildNumber.unit = unit;
|
|
909
|
+
const common = {
|
|
910
|
+
name,
|
|
911
|
+
release: target.release,
|
|
912
|
+
buildNumber,
|
|
913
|
+
files: target.files
|
|
914
|
+
};
|
|
915
|
+
switch (target.type) {
|
|
916
|
+
case "docker": {
|
|
917
|
+
const tags = Array.isArray(target.tags) ? {
|
|
918
|
+
release: target.tags,
|
|
919
|
+
preview: [...DEFAULT_DOCKER_TAGS.preview],
|
|
920
|
+
prerelease: [...DEFAULT_DOCKER_TAGS.prerelease]
|
|
921
|
+
} : {
|
|
922
|
+
release: target.tags?.release ?? [...DEFAULT_DOCKER_TAGS.release],
|
|
923
|
+
preview: target.tags?.preview ?? [...DEFAULT_DOCKER_TAGS.preview],
|
|
924
|
+
prerelease: target.tags?.prerelease ?? [...DEFAULT_DOCKER_TAGS.prerelease]
|
|
925
|
+
};
|
|
926
|
+
const image = Array.isArray(target.image) ? target.image : [target.image];
|
|
927
|
+
return {
|
|
928
|
+
...target,
|
|
929
|
+
...common,
|
|
930
|
+
image,
|
|
931
|
+
tags
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
case "ios": {
|
|
935
|
+
const source = target.source.kind === "plist" ? {
|
|
936
|
+
kind: "plist",
|
|
937
|
+
files: target.source.files ?? (target.source.file ? [target.source.file] : [])
|
|
938
|
+
} : target.source;
|
|
939
|
+
return {
|
|
940
|
+
...target,
|
|
941
|
+
...common,
|
|
942
|
+
source
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
case "web": return {
|
|
946
|
+
...target,
|
|
947
|
+
...common,
|
|
948
|
+
verify: []
|
|
949
|
+
};
|
|
950
|
+
default: return {
|
|
951
|
+
...target,
|
|
952
|
+
...common
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Targets previews can build (spec 9.7): `preview.targets` and every `preview.branches`
|
|
958
|
+
* entry's `targets` (an entry without them uses `preview.targets`); `"all"` is every target.
|
|
959
|
+
* Empty when previews are disabled.
|
|
960
|
+
*/
|
|
961
|
+
function previewBuildTargets(config) {
|
|
962
|
+
if (!config.preview.enabled) return /* @__PURE__ */ new Set();
|
|
963
|
+
const lists = [config.preview.targets, ...config.preview.branches.map((b) => b.targets)];
|
|
964
|
+
if (lists.includes("all")) return new Set(Object.keys(config.targets));
|
|
965
|
+
return new Set(lists.flatMap((list) => Array.isArray(list) ? list : []));
|
|
966
|
+
}
|
|
967
|
+
const SEMVER_ROOT_WITH_PREVIEWS = "the \"semver\" build-number strategy can't be the repo-wide strategy while previews are enabled: previews get their build number from it, and a preview of 1.5.0 and the real 1.5.0 would compete for the same numbers. Use \"timestamp\" here and set buildNumber: { strategy: \"semver\" } on the targets previews don't build, or set preview: false";
|
|
968
|
+
const semverPreviewTarget = (name) => `target "${name}" can't use the "semver" build-number strategy: previews build it, and a preview of 1.5.0 and the real 1.5.0 would compete for the same numbers. Take "${name}" out of preview.targets (and the targets of preview.branches), use "timestamp", or set preview: false`;
|
|
969
|
+
/**
|
|
970
|
+
* `buildNumber.unit` only goes with the `timestamp` strategy (spec 7.2): an error where it is
|
|
971
|
+
* written next to another strategy (repo-wide, or in a target's override, whose strategy may
|
|
972
|
+
* come from the root). A repo-wide unit inherited by a target with another strategy is fine.
|
|
973
|
+
*/
|
|
974
|
+
function unitIssues(data) {
|
|
975
|
+
const issues = [];
|
|
976
|
+
const message = (strategy) => `"unit" only applies to the "timestamp" build-number strategy, not "${strategy}": remove it`;
|
|
977
|
+
if (data.buildNumber.unit !== void 0 && data.buildNumber.strategy !== "timestamp") issues.push({
|
|
978
|
+
path: "buildNumber.unit",
|
|
979
|
+
message: message(data.buildNumber.strategy)
|
|
980
|
+
});
|
|
981
|
+
for (const [name, target] of Object.entries(data.targets)) {
|
|
982
|
+
const own = target.buildNumber;
|
|
983
|
+
const strategy = own?.strategy ?? data.buildNumber.strategy;
|
|
984
|
+
if (own?.unit !== void 0 && strategy !== "timestamp") issues.push({
|
|
985
|
+
path: `targets.${name}.buildNumber.unit`,
|
|
986
|
+
message: message(strategy)
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
return issues;
|
|
990
|
+
}
|
|
991
|
+
/** Cross-field rules from spec 5 that zod's per-field checks can't express. */
|
|
992
|
+
function semanticIssues(config) {
|
|
993
|
+
const issues = [];
|
|
994
|
+
const names = Object.keys(config.targets);
|
|
995
|
+
if (names.length === 0) issues.push({
|
|
996
|
+
path: "targets",
|
|
997
|
+
message: "expected at least one target"
|
|
998
|
+
});
|
|
999
|
+
for (const name of names) if (!TARGET_NAME.test(name)) issues.push({
|
|
1000
|
+
path: `targets.${name}`,
|
|
1001
|
+
message: "invalid target name: expected lowercase letters, digits and dashes, starting with a letter or digit"
|
|
1002
|
+
});
|
|
1003
|
+
if (names.length > 0 && !names.some((n) => config.targets[n]?.release === "auto")) issues.push({
|
|
1004
|
+
path: "targets",
|
|
1005
|
+
message: "expected at least one target with release: \"auto\" (otherwise no release completes)"
|
|
1006
|
+
});
|
|
1007
|
+
if (config.tags.partial === config.tags.release) issues.push({
|
|
1008
|
+
path: "tags.partial",
|
|
1009
|
+
message: "must differ from tags.release (a partial release must never look like a release)"
|
|
1010
|
+
});
|
|
1011
|
+
if (isMaintenanceBranch(config, config.baseBranch)) issues.push({
|
|
1012
|
+
path: "maintenanceBranches",
|
|
1013
|
+
message: `pattern "${config.maintenanceBranches}" matches the base branch "${config.baseBranch}"`
|
|
1014
|
+
});
|
|
1015
|
+
const rootSemver = config.preview.enabled && config.buildNumber.strategy === "semver";
|
|
1016
|
+
if (rootSemver) issues.push({
|
|
1017
|
+
path: "buildNumber.strategy",
|
|
1018
|
+
message: SEMVER_ROOT_WITH_PREVIEWS
|
|
1019
|
+
});
|
|
1020
|
+
const previewBuilt = previewBuildTargets(config);
|
|
1021
|
+
for (const target of Object.values(config.targets)) {
|
|
1022
|
+
const base = `targets.${target.name}`;
|
|
1023
|
+
if (!rootSemver && previewBuilt.has(target.name) && target.buildNumber.strategy === "semver") issues.push({
|
|
1024
|
+
path: `${base}.buildNumber.strategy`,
|
|
1025
|
+
message: semverPreviewTarget(target.name)
|
|
1026
|
+
});
|
|
1027
|
+
target.files.forEach((file, index) => {
|
|
1028
|
+
if (file.kind === "image" && target.type !== "docker") issues.push({
|
|
1029
|
+
path: `${base}.files.${index}.kind`,
|
|
1030
|
+
message: "kind \"image\" is only allowed in docker targets"
|
|
1031
|
+
});
|
|
1032
|
+
});
|
|
1033
|
+
if (target.type === "docker") {
|
|
1034
|
+
if (!target.tags.release.some((t) => t.includes("{version}"))) issues.push({
|
|
1035
|
+
path: `${base}.tags.release`,
|
|
1036
|
+
message: "expected at least one template containing {version} (used by verify)"
|
|
1037
|
+
});
|
|
1038
|
+
for (const list of ["preview", "prerelease"]) target.tags[list].forEach((template, index) => {
|
|
1039
|
+
if (template === "latest" || PLAIN_VERSION_TAG.test(renderSample(template))) issues.push({
|
|
1040
|
+
path: `${base}.tags.${list}.${index}`,
|
|
1041
|
+
message: `"${template}" isn't allowed in ${list} tags: it would look like a release (latest or a plain X.Y.Z)`
|
|
1042
|
+
});
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
if (target.type === "android" && target.verify.includes("store") && !target.store) issues.push({
|
|
1046
|
+
path: `${base}.store.packageName`,
|
|
1047
|
+
message: "verify: [\"store\"] needs store.packageName"
|
|
1048
|
+
});
|
|
1049
|
+
if (target.type === "ios") {
|
|
1050
|
+
if (target.verify.includes("store") && !target.store) issues.push({
|
|
1051
|
+
path: `${base}.store.appId`,
|
|
1052
|
+
message: "verify: [\"store\"] needs store.appId"
|
|
1053
|
+
});
|
|
1054
|
+
if (target.source.kind === "plist" && target.source.files.length === 0) issues.push({
|
|
1055
|
+
path: `${base}.source`,
|
|
1056
|
+
message: "expected file or files with at least one Info.plist path"
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
const checkTargetRefs = (list, path) => {
|
|
1061
|
+
if (!Array.isArray(list)) return;
|
|
1062
|
+
list.forEach((name, index) => {
|
|
1063
|
+
if (!config.targets[name]) issues.push({
|
|
1064
|
+
path: `${path}.${index}`,
|
|
1065
|
+
message: `unknown target "${name}"`
|
|
1066
|
+
});
|
|
1067
|
+
});
|
|
1068
|
+
};
|
|
1069
|
+
issues.push(...afterIssues(config));
|
|
1070
|
+
checkTargetRefs(config.preview.targets, "preview.targets");
|
|
1071
|
+
config.preview.branches.forEach((entry, index) => {
|
|
1072
|
+
checkTargetRefs(entry.targets, `preview.branches.${index}.targets`);
|
|
1073
|
+
});
|
|
1074
|
+
return issues;
|
|
1075
|
+
}
|
|
1076
|
+
/**
|
|
1077
|
+
* `after` of every target: known target names, not the target itself, no duplicates, no
|
|
1078
|
+
* cycles, and an auto target only after auto targets (a release never builds a manual target,
|
|
1079
|
+
* so the auto target would wait for nothing). A manual target may come after any target: the
|
|
1080
|
+
* order applies when both are built in the same pipeline (a ship of several targets, previews).
|
|
1081
|
+
*/
|
|
1082
|
+
function afterIssues(config) {
|
|
1083
|
+
const issues = [];
|
|
1084
|
+
const valid = /* @__PURE__ */ new Map();
|
|
1085
|
+
for (const target of Object.values(config.targets)) {
|
|
1086
|
+
const list = target.after ?? [];
|
|
1087
|
+
const base = `targets.${target.name}.after`;
|
|
1088
|
+
const kept = [];
|
|
1089
|
+
list.forEach((name, index) => {
|
|
1090
|
+
const other = config.targets[name];
|
|
1091
|
+
if (!other) issues.push({
|
|
1092
|
+
path: `${base}.${index}`,
|
|
1093
|
+
message: `unknown target "${name}"`
|
|
1094
|
+
});
|
|
1095
|
+
else if (name === target.name) issues.push({
|
|
1096
|
+
path: `${base}.${index}`,
|
|
1097
|
+
message: "a target can't come after itself"
|
|
1098
|
+
});
|
|
1099
|
+
else if (list.indexOf(name) !== index) issues.push({
|
|
1100
|
+
path: `${base}.${index}`,
|
|
1101
|
+
message: `"${name}" is listed twice`
|
|
1102
|
+
});
|
|
1103
|
+
else if (target.release === "auto" && other.release === "manual") issues.push({
|
|
1104
|
+
path: `${base}.${index}`,
|
|
1105
|
+
message: `"${name}" is a manual target: a release doesn't build it, so the auto target ${target.name} can only come after auto targets`
|
|
1106
|
+
});
|
|
1107
|
+
else kept.push(name);
|
|
1108
|
+
});
|
|
1109
|
+
valid.set(target.name, kept);
|
|
1110
|
+
}
|
|
1111
|
+
const state = /* @__PURE__ */ new Map();
|
|
1112
|
+
const reported = /* @__PURE__ */ new Set();
|
|
1113
|
+
const visit = (name, path) => {
|
|
1114
|
+
if (state.get(name) === "done") return;
|
|
1115
|
+
if (state.get(name) === "visiting") {
|
|
1116
|
+
const cycle = [...path.slice(path.indexOf(name)), name];
|
|
1117
|
+
const key = [...cycle.slice(0, -1)].sort().join(",");
|
|
1118
|
+
if (!reported.has(key)) {
|
|
1119
|
+
reported.add(key);
|
|
1120
|
+
issues.push({
|
|
1121
|
+
path: `targets.${cycle[0]}.after`,
|
|
1122
|
+
message: `targets can't wait for each other in a circle: ${cycle.join(" -> ")}`
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
state.set(name, "visiting");
|
|
1128
|
+
for (const next of valid.get(name) ?? []) visit(next, [...path, name]);
|
|
1129
|
+
state.set(name, "done");
|
|
1130
|
+
};
|
|
1131
|
+
for (const name of Object.keys(config.targets)) visit(name, []);
|
|
1132
|
+
return issues;
|
|
1133
|
+
}
|
|
1134
|
+
/** The GitLab shell of a target's build job (default `sh`). */
|
|
1135
|
+
function targetShell(target) {
|
|
1136
|
+
return target.gitlab?.shell ?? "sh";
|
|
1137
|
+
}
|
|
1138
|
+
/** The GitLab settings with their defaults. */
|
|
1139
|
+
function gitlabSettings(config) {
|
|
1140
|
+
return {
|
|
1141
|
+
include: config.gitlab?.include ?? [],
|
|
1142
|
+
tagPipelines: config.gitlab?.tagPipelines ?? false
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
* Settings the GitHub Actions workflows can't follow, as config issues (empty for GitLab CI).
|
|
1147
|
+
* The release workflow builds every target in one matrix job, so `after` can't order them
|
|
1148
|
+
* there.
|
|
1149
|
+
*/
|
|
1150
|
+
function hostConfigIssues(config, host, ci = hostProfile(host).ci) {
|
|
1151
|
+
if (ci !== "actions") return [];
|
|
1152
|
+
return Object.values(config.targets).filter((t) => (t.after ?? []).length > 0).map((t) => ({
|
|
1153
|
+
path: `targets.${t.name}.after`,
|
|
1154
|
+
message: "is GitLab only: the GitHub workflows build every target in one matrix job, which can't run one target after another. Remove \"after\" (or do the dependent steps in one target)"
|
|
1155
|
+
}));
|
|
1156
|
+
}
|
|
1157
|
+
/** A top-level `$schema` key (for editor support in `launchset.config.json`) is allowed. */
|
|
1158
|
+
function withoutSchemaKey(input) {
|
|
1159
|
+
if (input === null || typeof input !== "object" || Array.isArray(input) || !("$schema" in input)) return input;
|
|
1160
|
+
const { $schema: _schema, ...rest } = input;
|
|
1161
|
+
return rest;
|
|
1162
|
+
}
|
|
1163
|
+
/**
|
|
1164
|
+
* Validate and normalize a config object. Throws `ConfigError` listing every problem.
|
|
1165
|
+
*/
|
|
1166
|
+
function resolveConfig(input, options = {}) {
|
|
1167
|
+
const parsed = configSchema.safeParse(withoutSchemaKey(input), { reportInput: true });
|
|
1168
|
+
if (!parsed.success) throw new ConfigError(formatZodIssues(parsed.error.issues), options.file);
|
|
1169
|
+
const data = parsed.data;
|
|
1170
|
+
const preview = data.preview === false ? {
|
|
1171
|
+
enabled: false,
|
|
1172
|
+
label: "launchset:preview",
|
|
1173
|
+
rebuildOnPush: true,
|
|
1174
|
+
branches: [],
|
|
1175
|
+
targets: "all"
|
|
1176
|
+
} : {
|
|
1177
|
+
enabled: true,
|
|
1178
|
+
...data.preview,
|
|
1179
|
+
branches: data.preview.branches.map((b) => typeof b === "string" ? { branch: b } : b)
|
|
1180
|
+
};
|
|
1181
|
+
const targets = {};
|
|
1182
|
+
for (const [name, target] of Object.entries(data.targets)) targets[name] = resolveTarget(name, target, data.buildNumber);
|
|
1183
|
+
const config = {
|
|
1184
|
+
...data,
|
|
1185
|
+
preview,
|
|
1186
|
+
targets
|
|
1187
|
+
};
|
|
1188
|
+
const issues = [...semanticIssues(config), ...unitIssues(data)];
|
|
1189
|
+
config.preview.branches.forEach((entry, index) => {
|
|
1190
|
+
if (entry.prerelease && matchBranch(config.baseBranch, entry.branch)) issues.push({
|
|
1191
|
+
path: `preview.branches.${index}.branch`,
|
|
1192
|
+
message: `prerelease branch pattern "${entry.branch}" matches the base branch "${config.baseBranch}"`
|
|
1193
|
+
});
|
|
1194
|
+
});
|
|
1195
|
+
if (issues.length > 0) throw new ConfigError(issues, options.file);
|
|
1196
|
+
return config;
|
|
1197
|
+
}
|
|
1198
|
+
/** Type helper for `launchset.config.ts`. */
|
|
1199
|
+
function defineConfig(config) {
|
|
1200
|
+
return config;
|
|
1201
|
+
}
|
|
1202
|
+
export { isPlainVersion as A, releaseVersion as B, matchBranch as C, compareVersions as D, branchSlug as E, parseMaintenanceBranch as F, BUMPS as H, prPreviewVersion as I, prereleaseVersion as L, maintenanceViolations as M, marketingVersion as N, distTag as O, nextPrereleaseNumber as P, previewBaseVersion as R, isMaintenanceBranch as S, branchPreviewVersion as T, escapeRegExp as U, versionParts as V, ciProfile as _, configSchema as a, isForgeHost as b, hostConfigIssues as c, CI_SYSTEMS as d, DEFAULT_HOST as f, ciOf as g, ciFromEnv as h, TARGET_NAME as i, maintenanceBranchName as j, highestVersion as k, resolveConfig as l, HOSTS as m, DEFAULT_DOCKER_TAGS as n, defineConfig as o, FORGE_HOSTS as p, DOCKER_TAG_PLACEHOLDERS as r, gitlabSettings as s, ConfigError as t, targetShell as u, ciSystemFor as v, baseVersionOf as w, findPreviewBranch as x, hostProfile as y, releaseBump as z };
|