package-registry-manager 0.26.0 → 0.27.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/CHANGELOG.md +10 -0
- package/package.json +1 -1
- package/src/central-packagist-steps.mjs +538 -0
- package/src/credential-cycle.mjs +7 -0
- package/src/discovery.mjs +21 -36
- package/src/extra-flows.mjs +21 -12
- package/src/gradle-distribution.mjs +410 -0
- package/src/model.mjs +4 -0
- package/src/organization-scan.mjs +34 -2
- package/src/plan.mjs +14 -0
- package/src/publishers.mjs +9 -2
- package/src/scan-sidecars.mjs +132 -0
- package/src/setup.mjs +15 -1
- package/src/swift-distribution.mjs +249 -0
- package/src/swift-release.mjs +180 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import {
|
|
3
|
+
parseSwiftManifest,
|
|
4
|
+
swiftVersionCandidates,
|
|
5
|
+
} from "./swift-distribution.mjs";
|
|
6
|
+
|
|
7
|
+
/** At most this many sidecars per repository; the rest are reported. */
|
|
8
|
+
export const SIDECAR_LIMIT = 200;
|
|
9
|
+
|
|
10
|
+
const SAFE_PATH = /^[\w.+-]+(?:\/[\w.+-]+)*$/;
|
|
11
|
+
const GRADLE_SIDECARS = [
|
|
12
|
+
"gradle.properties",
|
|
13
|
+
"settings.gradle",
|
|
14
|
+
"settings.gradle.kts",
|
|
15
|
+
"gradle/libs.versions.toml",
|
|
16
|
+
];
|
|
17
|
+
const CMAKE_READ =
|
|
18
|
+
/\bfile\s*\(\s*READ\s+"?\$\{CMAKE_CURRENT_(?:SOURCE|LIST)_DIR\}\/([\w./+-]+)"?\s+\w+/gi;
|
|
19
|
+
/** `cat go/VERSION`, `< cpp/VERSION`, `version-file: swift/VERSION` and the like. */
|
|
20
|
+
const WORKFLOW_VERSION =
|
|
21
|
+
/(?:^|[\s"'=:(<])((?:[\w.+-]+\/)*VERSION)(?=$|[\s"')|;])/gm;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Repository-relative version sources local discovery reads next to the
|
|
25
|
+
* fetched manifests: sibling VERSION files (Go, C++, SwiftPM), CMake
|
|
26
|
+
* `file(READ ...)` targets, SwiftPM target-directory VERSION files, Gradle
|
|
27
|
+
* properties/settings/version catalogs, and VERSION files that workflow
|
|
28
|
+
* commands name. Nothing is executed; unsafe or escaping references are
|
|
29
|
+
* rejected, not followed.
|
|
30
|
+
*/
|
|
31
|
+
export function versionSidecars(files) {
|
|
32
|
+
const known = new Set(files.map((file) => file.path));
|
|
33
|
+
const wanted = new Set();
|
|
34
|
+
const rejected = [];
|
|
35
|
+
const add = (base, reference) => {
|
|
36
|
+
const joined = path.posix.normalize(path.posix.join(base, reference));
|
|
37
|
+
if (
|
|
38
|
+
path.posix.isAbsolute(reference) ||
|
|
39
|
+
joined.startsWith("../") ||
|
|
40
|
+
joined === ".." ||
|
|
41
|
+
!SAFE_PATH.test(joined) ||
|
|
42
|
+
joined.split("/").some((part) => part === ".git" || part === "..")
|
|
43
|
+
) {
|
|
44
|
+
rejected.push(path.posix.join(base, reference));
|
|
45
|
+
} else if (!known.has(joined)) {
|
|
46
|
+
wanted.add(joined);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
for (const file of files) {
|
|
50
|
+
const name = path.posix.basename(file.path);
|
|
51
|
+
const directory = path.posix.dirname(file.path);
|
|
52
|
+
const text = file.content ?? "";
|
|
53
|
+
if (name === "go.mod" || name === "CMakeLists.txt") {
|
|
54
|
+
add(directory, "VERSION");
|
|
55
|
+
}
|
|
56
|
+
if (name === "CMakeLists.txt") {
|
|
57
|
+
for (const match of text.matchAll(CMAKE_READ)) {
|
|
58
|
+
add(directory, match[1]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (name === "Package.swift") {
|
|
62
|
+
for (const candidate of swiftVersionCandidates(
|
|
63
|
+
file.path,
|
|
64
|
+
parseSwiftManifest(text),
|
|
65
|
+
)) {
|
|
66
|
+
add(".", candidate);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (name === "build.gradle" || name === "build.gradle.kts") {
|
|
70
|
+
for (const sidecar of GRADLE_SIDECARS) {
|
|
71
|
+
add(directory, sidecar);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (file.path.startsWith(".github/workflows/")) {
|
|
75
|
+
for (const match of text.matchAll(WORKFLOW_VERSION)) {
|
|
76
|
+
add(".", match[1].replace(/^\.\//, ""));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const sorted = [...wanted].sort();
|
|
81
|
+
return {
|
|
82
|
+
paths: sorted.slice(0, SIDECAR_LIMIT),
|
|
83
|
+
skipped: sorted.slice(SIDECAR_LIMIT),
|
|
84
|
+
rejected: [...new Set(rejected)].sort(),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Fetches the version sidecars at the same commit as the manifests. A
|
|
90
|
+
* failed read is an explicit repository error; the peer packages found from
|
|
91
|
+
* the manifests are kept either way.
|
|
92
|
+
*/
|
|
93
|
+
export async function fetchVersionSidecars(github, slug, files, ref, onError) {
|
|
94
|
+
const { paths, skipped, rejected } = versionSidecars(files);
|
|
95
|
+
for (const reference of rejected) {
|
|
96
|
+
onError({
|
|
97
|
+
stage: "sidecar",
|
|
98
|
+
manifest: reference,
|
|
99
|
+
message: "unsafe version file reference was not followed",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (skipped.length) {
|
|
103
|
+
onError({
|
|
104
|
+
stage: "sidecar",
|
|
105
|
+
message: `${skipped.length} version files beyond the ${SIDECAR_LIMIT}-file limit were not fetched; their packages keep unknown versions`,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (!paths.length) {
|
|
109
|
+
return { requested: [], missing: [] };
|
|
110
|
+
}
|
|
111
|
+
let fetched;
|
|
112
|
+
try {
|
|
113
|
+
fetched = await github.repos.files(slug, {
|
|
114
|
+
match: paths,
|
|
115
|
+
content: true,
|
|
116
|
+
ref,
|
|
117
|
+
});
|
|
118
|
+
} catch (error) {
|
|
119
|
+
onError({
|
|
120
|
+
stage: "sidecar",
|
|
121
|
+
message: `version files unavailable (${error.status ? `HTTP ${error.status}: ` : ""}${error.message}); affected versions stay unknown`,
|
|
122
|
+
});
|
|
123
|
+
return { requested: paths, missing: paths, failed: true };
|
|
124
|
+
}
|
|
125
|
+
const exact = fetched.filter((file) => paths.includes(file.path));
|
|
126
|
+
files.push(...exact);
|
|
127
|
+
const found = new Set(exact.map((file) => file.path));
|
|
128
|
+
return {
|
|
129
|
+
requested: paths,
|
|
130
|
+
missing: paths.filter((item) => !found.has(item)),
|
|
131
|
+
};
|
|
132
|
+
}
|
package/src/setup.mjs
CHANGED
|
@@ -32,6 +32,10 @@ import {
|
|
|
32
32
|
} from "./approvals.mjs";
|
|
33
33
|
import { connectAutomation } from "./automation.mjs";
|
|
34
34
|
import { runCratesApiStep } from "./crates-api.mjs";
|
|
35
|
+
import {
|
|
36
|
+
CENTRAL_PACKAGIST_STEPS,
|
|
37
|
+
runCentralPackagistStep,
|
|
38
|
+
} from "./central-packagist-steps.mjs";
|
|
35
39
|
import { detachedRunner, openInUserBrowser } from "./browser.mjs";
|
|
36
40
|
import { detectDefaultBrowser, openWithCommand } from "./default-browser.mjs";
|
|
37
41
|
import { CLEANUP_CONDITIONS } from "./flows.mjs";
|
|
@@ -115,6 +119,9 @@ export class SetupSession {
|
|
|
115
119
|
console.error(`skip ${step.id}: condition ${step.when} does not hold`);
|
|
116
120
|
}
|
|
117
121
|
}
|
|
122
|
+
if (!this.outcome && this.incomplete?.length) {
|
|
123
|
+
this.outcome = { status: "incomplete", incomplete: this.incomplete };
|
|
124
|
+
}
|
|
118
125
|
}
|
|
119
126
|
|
|
120
127
|
/**
|
|
@@ -142,7 +149,11 @@ export class SetupSession {
|
|
|
142
149
|
);
|
|
143
150
|
} else if (this.conditions.has(step.when) && step.kind === "api") {
|
|
144
151
|
this.log(`==> ${step.title}`);
|
|
145
|
-
await
|
|
152
|
+
await (
|
|
153
|
+
CENTRAL_PACKAGIST_STEPS.has(step.id)
|
|
154
|
+
? runCentralPackagistStep(this, step)
|
|
155
|
+
: runCratesApiStep(this, step)
|
|
156
|
+
).catch((error) =>
|
|
146
157
|
console.error(`warning: ${step.id} failed: ${error.message}`),
|
|
147
158
|
);
|
|
148
159
|
} else if (this.conditions.has(step.when)) {
|
|
@@ -184,6 +195,9 @@ export class SetupSession {
|
|
|
184
195
|
}
|
|
185
196
|
|
|
186
197
|
async runStep(step) {
|
|
198
|
+
if (CENTRAL_PACKAGIST_STEPS.has(step.id)) {
|
|
199
|
+
return runCentralPackagistStep(this, step);
|
|
200
|
+
}
|
|
187
201
|
if (step.id === "audit-distribution-channel") {
|
|
188
202
|
const { auditDistributionChannel } =
|
|
189
203
|
await import("./distribution-channel.mjs");
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* SwiftPM distributes a package from semantic-version tags of its Git
|
|
6
|
+
* repository; there is no upload. An optional Swift package registry
|
|
7
|
+
* (SE-0292) is a separate channel and is never assumed.
|
|
8
|
+
*/
|
|
9
|
+
export const SWIFT_DISTRIBUTION = Object.freeze({
|
|
10
|
+
channel: "git-tag",
|
|
11
|
+
registry: "none",
|
|
12
|
+
tag_format: "bare semantic version (SwiftPM ignores prefixed tags)",
|
|
13
|
+
identity: "repository URL",
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const SEMVER = /^v?\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Reads Package.swift as text, never running it: the package name, its
|
|
20
|
+
* library products, target paths, and local path dependencies. A manifest
|
|
21
|
+
* with no library product, or one that depends on an ancestor checkout by
|
|
22
|
+
* path, is a consumer or example rather than a distribution.
|
|
23
|
+
*/
|
|
24
|
+
export function parseSwiftManifest(contents) {
|
|
25
|
+
const code = contents
|
|
26
|
+
.replace(/\/\/[^\n]*/g, "")
|
|
27
|
+
.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
28
|
+
const name = /\bPackage\s*\(\s*name\s*:\s*"([^"]+)"/.exec(code)?.[1] ?? null;
|
|
29
|
+
const libraries = [
|
|
30
|
+
...code.matchAll(/\.library\s*\(\s*name\s*:\s*"([^"]+)"/g),
|
|
31
|
+
].map((match) => match[1]);
|
|
32
|
+
const executables = [
|
|
33
|
+
...code.matchAll(/\.executable\s*\(\s*name\s*:\s*"([^"]+)"/g),
|
|
34
|
+
].map((match) => match[1]);
|
|
35
|
+
const paths = [
|
|
36
|
+
...code.matchAll(
|
|
37
|
+
/\.(?:target|executableTarget|testTarget|binaryTarget)\s*\([^)]*?\bpath\s*:\s*"([^"]+)"/g,
|
|
38
|
+
),
|
|
39
|
+
].map((match) => match[1]);
|
|
40
|
+
const localDependencies = [
|
|
41
|
+
...code.matchAll(/\.package\s*\([^)]*?\bpath\s*:\s*"([^"]+)"/g),
|
|
42
|
+
].map((match) => match[1]);
|
|
43
|
+
const tools = /^\s*\/\/\s*swift-tools-version\s*:\s*([\d.]+)/m.exec(
|
|
44
|
+
contents,
|
|
45
|
+
)?.[1];
|
|
46
|
+
return {
|
|
47
|
+
name,
|
|
48
|
+
libraries,
|
|
49
|
+
executables,
|
|
50
|
+
paths,
|
|
51
|
+
localDependencies,
|
|
52
|
+
tools: tools ?? null,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Version-file candidates for a Swift package: a sibling VERSION, then a
|
|
58
|
+
* VERSION in the one top-level directory that holds every target source.
|
|
59
|
+
* Only repository-relative paths below the manifest are returned.
|
|
60
|
+
*/
|
|
61
|
+
export function swiftVersionCandidates(manifest, parsed) {
|
|
62
|
+
const directory = path.posix.dirname(manifest);
|
|
63
|
+
const join = (...parts) =>
|
|
64
|
+
path.posix.normalize(path.posix.join(...parts)).replace(/^\.\//, "");
|
|
65
|
+
const candidates = [join(directory, "VERSION")];
|
|
66
|
+
const roots = new Set(
|
|
67
|
+
parsed.paths
|
|
68
|
+
.map((item) => path.posix.normalize(item))
|
|
69
|
+
.filter((item) => !item.startsWith("..") && !path.posix.isAbsolute(item))
|
|
70
|
+
.map((item) => item.split("/")[0])
|
|
71
|
+
.filter((item) => item && item !== "."),
|
|
72
|
+
);
|
|
73
|
+
if (roots.size === 1) {
|
|
74
|
+
candidates.push(join(directory, [...roots][0], "VERSION"));
|
|
75
|
+
}
|
|
76
|
+
return [...new Set(candidates)];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Builds the SwiftPM package record for one Package.swift. */
|
|
80
|
+
export async function swiftDistribution(contents, manifest, root, mapping) {
|
|
81
|
+
const parsed = parseSwiftManifest(contents);
|
|
82
|
+
const ancestor = parsed.localDependencies.find((item) =>
|
|
83
|
+
path.posix.normalize(item).startsWith(".."),
|
|
84
|
+
);
|
|
85
|
+
if (ancestor && !mapping) {
|
|
86
|
+
return {
|
|
87
|
+
manifest,
|
|
88
|
+
publishable: false,
|
|
89
|
+
discovery_skip: `Package.swift depends on the checkout at ${ancestor} by path: a consumer example, not a SwiftPM distribution`,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (!parsed.name || (!parsed.libraries.length && !mapping)) {
|
|
93
|
+
return {
|
|
94
|
+
manifest,
|
|
95
|
+
publishable: false,
|
|
96
|
+
discovery_skip:
|
|
97
|
+
"Package.swift declares no library product; SwiftPM consumers can only depend on library products",
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const problems = [];
|
|
101
|
+
let version = null;
|
|
102
|
+
let versionSource = null;
|
|
103
|
+
const candidates = mapping?.version_file
|
|
104
|
+
? [mapping.version_file]
|
|
105
|
+
: swiftVersionCandidates(manifest, parsed);
|
|
106
|
+
const found = [];
|
|
107
|
+
for (const candidate of candidates) {
|
|
108
|
+
const value = await readVersion(root, candidate);
|
|
109
|
+
if (value?.error) {
|
|
110
|
+
problems.push(value.error);
|
|
111
|
+
} else if (value) {
|
|
112
|
+
found.push([candidate, value]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (new Set(found.map(([, value]) => value)).size > 1) {
|
|
116
|
+
problems.push(
|
|
117
|
+
`ambiguous Swift version: ${found.map(([file, value]) => `${file}=${value}`).join(", ")}; list the version file under "swiftpm" in .package-registry-manager.json`,
|
|
118
|
+
);
|
|
119
|
+
} else if (found.length) {
|
|
120
|
+
[versionSource, version] = found[0];
|
|
121
|
+
} else if (!problems.length) {
|
|
122
|
+
problems.push(
|
|
123
|
+
`no Swift version source: none of ${candidates.join(", ")} holds a semantic version; the release tag stays unknown`,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
const item = {
|
|
127
|
+
registry: "swiftpm",
|
|
128
|
+
name: mapping?.name ?? parsed.name,
|
|
129
|
+
version,
|
|
130
|
+
manifest,
|
|
131
|
+
publishable: true,
|
|
132
|
+
swift_package: {
|
|
133
|
+
...SWIFT_DISTRIBUTION,
|
|
134
|
+
products: mapping?.products ?? parsed.libraries,
|
|
135
|
+
...(parsed.executables.length ? { executables: parsed.executables } : {}),
|
|
136
|
+
...(parsed.tools ? { tools_version: parsed.tools } : {}),
|
|
137
|
+
tag: version ? version.replace(/^v/, "") : null,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
if (versionSource) {
|
|
141
|
+
item.version_source = versionSource;
|
|
142
|
+
}
|
|
143
|
+
if (problems.length) {
|
|
144
|
+
item.warnings = problems;
|
|
145
|
+
}
|
|
146
|
+
return item;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function readVersion(root, relative) {
|
|
150
|
+
const normalized = path.posix.normalize(relative);
|
|
151
|
+
if (
|
|
152
|
+
normalized.startsWith("..") ||
|
|
153
|
+
path.posix.isAbsolute(normalized) ||
|
|
154
|
+
normalized.split("/").includes("..")
|
|
155
|
+
) {
|
|
156
|
+
return { error: `unsafe Swift version file reference ${relative}` };
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
const value = (await readFile(path.join(root, normalized), "utf8")).trim();
|
|
160
|
+
return SEMVER.test(value) ? value : null;
|
|
161
|
+
} catch (error) {
|
|
162
|
+
if (error.code === "ENOENT" || error.code === "ENOTDIR") {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
error: `unreadable Swift version file ${relative}: ${error.code}`,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Release evidence for SwiftPM: the job creates a tag or GitHub release and
|
|
173
|
+
* names the Swift package (its manifest, version file or toolchain).
|
|
174
|
+
*/
|
|
175
|
+
export function swiftReleaseEvidence(text) {
|
|
176
|
+
return (
|
|
177
|
+
/\bgh\s+release\s+create\b|\bgit\s+tag\b|\bgit\s+push\b[^\n]*\btags?\b|ensure-[\w-]*tag/.test(
|
|
178
|
+
text,
|
|
179
|
+
) &&
|
|
180
|
+
/Package\.swift|swift\/VERSION|\bswift\s+(?:package|build|run|test)\b/.test(
|
|
181
|
+
text,
|
|
182
|
+
)
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Validation and verification steps for a Git-tag SwiftPM distribution. */
|
|
187
|
+
export function swiftPlan(item, slug) {
|
|
188
|
+
const check = (id, title, description, args) => ({
|
|
189
|
+
id,
|
|
190
|
+
title,
|
|
191
|
+
kind: "check",
|
|
192
|
+
description,
|
|
193
|
+
command: { program: "swift", args },
|
|
194
|
+
});
|
|
195
|
+
const tag = item.swift_package?.tag ?? item.version;
|
|
196
|
+
return [
|
|
197
|
+
check(
|
|
198
|
+
"describe-package",
|
|
199
|
+
"Resolve the Swift package manifest",
|
|
200
|
+
"Let the official toolchain evaluate Package.swift in a reviewed checkout; discovery itself never runs it.",
|
|
201
|
+
["package", "describe", "--type", "json"],
|
|
202
|
+
),
|
|
203
|
+
check("build-package", "Build the Swift package", "Build every product.", [
|
|
204
|
+
"build",
|
|
205
|
+
]),
|
|
206
|
+
check("test-package", "Test the Swift package", "Run the package tests.", [
|
|
207
|
+
"test",
|
|
208
|
+
]),
|
|
209
|
+
{
|
|
210
|
+
id: "verify-swift-release",
|
|
211
|
+
title: `Verify tag ${tag ?? "(unresolved)"}, tagged Package.swift and GitHub release`,
|
|
212
|
+
kind: "api",
|
|
213
|
+
description: `SwiftPM publishes by tag: read the exact tag ${tag ?? "(unresolved)"}${slug ? ` of ${slug}` : ""}, its commit, the tagged Package.swift and the public GitHub release. Missing tag, wrong commit, missing or incorrect manifest and missing release are distinct; an existing tag is never moved. ${item.workflow ? `The existing ${item.workflow} workflow creates the tag with its GITHUB_TOKEN; no SwiftPM OIDC, token or registry upload exists.` : "No workflow creates the tag yet; add the release job in a reviewed pull request."}`,
|
|
214
|
+
...(tag ? { tag } : {}),
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
id: "verify-swift-consumer",
|
|
218
|
+
title: "Verify a downstream consumer resolves the exact version",
|
|
219
|
+
kind: "manual",
|
|
220
|
+
state: "manual-prerequisite",
|
|
221
|
+
description: `Resolve .package(url: ..., exact: "${tag ?? "<version>"}") from a clean consumer and run it (swift run --package-path <consumer>). A skipped or failed consumer job keeps the release unverified.`,
|
|
222
|
+
},
|
|
223
|
+
];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Composer and SwiftPM both read bare semantic-version tags of the same
|
|
228
|
+
* repository, so one tag releases both: record the sharing so neither side
|
|
229
|
+
* moves or recreates the other's tag.
|
|
230
|
+
*/
|
|
231
|
+
export function markSharedTags(items) {
|
|
232
|
+
for (const swift of items.filter((item) => item?.registry === "swiftpm")) {
|
|
233
|
+
const tag = swift.swift_package?.tag;
|
|
234
|
+
const peers = items.filter(
|
|
235
|
+
(item) =>
|
|
236
|
+
item?.registry === "packagist" &&
|
|
237
|
+
item.manifest === "composer.json" &&
|
|
238
|
+
!item.discovery_skip,
|
|
239
|
+
);
|
|
240
|
+
if (tag && peers.length) {
|
|
241
|
+
swift.swift_package.shared_tag = {
|
|
242
|
+
tag,
|
|
243
|
+
with: peers.map((item) => `${item.registry}:${item.name}`),
|
|
244
|
+
policy:
|
|
245
|
+
"create the tag once at the gated commit, verify an existing tag points there, never move it",
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { githubServices } from "./github.mjs";
|
|
2
|
+
import { repositorySlug } from "./repository-identity.mjs";
|
|
3
|
+
import { parseSwiftManifest } from "./swift-distribution.mjs";
|
|
4
|
+
|
|
5
|
+
const CONSUMER_STEP = /consumer|resolves?\b|verify\b.*\b(?:swift|release)/i;
|
|
6
|
+
|
|
7
|
+
function services(session) {
|
|
8
|
+
return session.options.github ?? githubServices(session.options);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function fileAt(github, slug, file, ref) {
|
|
12
|
+
const body = await github.rest.request(
|
|
13
|
+
`/repos/${slug}/contents/${file.split("/").map(encodeURIComponent).join("/")}?ref=${encodeURIComponent(ref)}`,
|
|
14
|
+
{ allowNotFound: true },
|
|
15
|
+
);
|
|
16
|
+
if (!body || typeof body.content !== "string") {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return Buffer.from(body.content, body.encoding ?? "base64").toString("utf8");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Reads the public SwiftPM release of the exact version: the bare tag, the
|
|
24
|
+
* commit it names (its version source must hold the version), the tagged
|
|
25
|
+
* Package.swift and its library products, and a public GitHub release.
|
|
26
|
+
* Each failure is a distinct state, and nothing is ever created or moved.
|
|
27
|
+
*/
|
|
28
|
+
export async function verifySwiftRelease(session, step) {
|
|
29
|
+
const item = session.plan.package;
|
|
30
|
+
const tag = step.tag ?? item.swift_package?.tag;
|
|
31
|
+
const slug = repositorySlug(session.plan.repository);
|
|
32
|
+
if (!tag || !slug) {
|
|
33
|
+
return {
|
|
34
|
+
status: "unknown",
|
|
35
|
+
reason: !tag
|
|
36
|
+
? "the Swift version source is unresolved, so the expected tag is unknown"
|
|
37
|
+
: "no GitHub repository identity",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const github = services(session);
|
|
41
|
+
const ref = await github.rest.request(
|
|
42
|
+
`/repos/${slug}/git/ref/tags/${encodeURIComponent(tag)}`,
|
|
43
|
+
{ allowNotFound: true },
|
|
44
|
+
);
|
|
45
|
+
if (!ref) {
|
|
46
|
+
return {
|
|
47
|
+
status: "missing-tag",
|
|
48
|
+
tag,
|
|
49
|
+
reason: `the bare tag ${tag} does not exist; the release workflow creates it at the gated commit`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
let commit = ref.object?.sha;
|
|
53
|
+
if (ref.object?.type === "tag") {
|
|
54
|
+
commit = (await github.rest.request(`/repos/${slug}/git/tags/${commit}`))
|
|
55
|
+
.object?.sha;
|
|
56
|
+
}
|
|
57
|
+
if (step.commit && step.commit !== commit) {
|
|
58
|
+
return {
|
|
59
|
+
status: "wrong-commit",
|
|
60
|
+
tag,
|
|
61
|
+
commit,
|
|
62
|
+
reason: `the tag names ${commit}, not ${step.commit}; existing tags are never moved`,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (item.version_source) {
|
|
66
|
+
const declared = (await fileAt(github, slug, item.version_source, commit))
|
|
67
|
+
?.trim()
|
|
68
|
+
.replace(/^v/, "");
|
|
69
|
+
if (declared !== tag.replace(/^v/, "")) {
|
|
70
|
+
return {
|
|
71
|
+
status: "wrong-commit",
|
|
72
|
+
tag,
|
|
73
|
+
commit,
|
|
74
|
+
reason: `${item.version_source} at the tagged commit declares ${declared ?? "nothing"}, not ${tag}; existing tags are never moved`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const manifest = await fileAt(github, slug, item.manifest, commit);
|
|
79
|
+
if (manifest === null) {
|
|
80
|
+
return {
|
|
81
|
+
status: "manifest-missing",
|
|
82
|
+
tag,
|
|
83
|
+
commit,
|
|
84
|
+
reason: `${item.manifest} is absent at the tagged commit`,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const parsed = parseSwiftManifest(manifest);
|
|
88
|
+
const products = item.swift_package?.products ?? [];
|
|
89
|
+
const absent = products.filter((name) => !parsed.libraries.includes(name));
|
|
90
|
+
if (parsed.name !== item.name || absent.length) {
|
|
91
|
+
return {
|
|
92
|
+
status: "manifest-incorrect",
|
|
93
|
+
tag,
|
|
94
|
+
commit,
|
|
95
|
+
reason: `the tagged Package.swift declares ${parsed.name ?? "no package"} with products ${parsed.libraries.join(", ") || "none"}; expected ${item.name} with ${products.join(", ")}`,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const release = await github.rest.request(
|
|
99
|
+
`/repos/${slug}/releases/tags/${encodeURIComponent(tag)}`,
|
|
100
|
+
{ allowNotFound: true },
|
|
101
|
+
);
|
|
102
|
+
if (!release || release.draft) {
|
|
103
|
+
return {
|
|
104
|
+
status: "release-missing",
|
|
105
|
+
tag,
|
|
106
|
+
commit,
|
|
107
|
+
reason: release
|
|
108
|
+
? "the GitHub release is still a draft"
|
|
109
|
+
: `no public GitHub release for ${tag}`,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
session.conditions.add("swift-release-verified");
|
|
113
|
+
return { status: "verified", tag, commit, url: release.html_url };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The exact-version consumer gate runs inside the release workflow: its
|
|
118
|
+
* latest main run's consumer step is the only evidence. Skipped, failed,
|
|
119
|
+
* missing or unreadable steps keep the release unverified.
|
|
120
|
+
*/
|
|
121
|
+
export async function verifySwiftConsumer(session, step) {
|
|
122
|
+
const workflow = session.plan.package.workflow;
|
|
123
|
+
const slug = repositorySlug(session.plan.repository);
|
|
124
|
+
if (!session.conditions.has("swift-release-verified")) {
|
|
125
|
+
return {
|
|
126
|
+
status: "manual-prerequisite",
|
|
127
|
+
reason:
|
|
128
|
+
"the exact tag and release are unverified, so no consumer can resolve them",
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
if (!workflow || !slug) {
|
|
132
|
+
return {
|
|
133
|
+
status: "manual-prerequisite",
|
|
134
|
+
reason: step.description,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const github = services(session);
|
|
138
|
+
const repo = await github.rest.request(`/repos/${slug}`);
|
|
139
|
+
const runs = await github.runs.list(slug, {
|
|
140
|
+
workflow,
|
|
141
|
+
branch: repo.default_branch,
|
|
142
|
+
limit: 10,
|
|
143
|
+
});
|
|
144
|
+
const run = runs
|
|
145
|
+
.filter((entry) => entry.status === "completed")
|
|
146
|
+
.sort((a, b) => b.id - a.id)[0];
|
|
147
|
+
if (!run) {
|
|
148
|
+
return {
|
|
149
|
+
status: "consumer-unknown",
|
|
150
|
+
reason: `no completed ${workflow} run`,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const callee = (session.plan.package.workflow_callees ?? [])
|
|
154
|
+
.at(-1)
|
|
155
|
+
?.split(" -> ")
|
|
156
|
+
.at(-1);
|
|
157
|
+
const jobs = (await github.runs.jobs(slug, run.id)).filter(
|
|
158
|
+
(job) => !callee || job.name === callee || job.name.endsWith(`/ ${callee}`),
|
|
159
|
+
);
|
|
160
|
+
const check = jobs
|
|
161
|
+
.flatMap((job) => job.steps ?? [])
|
|
162
|
+
.find((entry) => CONSUMER_STEP.test(entry.name));
|
|
163
|
+
if (!check) {
|
|
164
|
+
return {
|
|
165
|
+
status: "consumer-unknown",
|
|
166
|
+
run: run.html_url,
|
|
167
|
+
reason: "the run has no readable consumer step",
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
if (check.conclusion === "success") {
|
|
171
|
+
return { status: "verified", run: run.html_url, step: check.name };
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
status:
|
|
175
|
+
check.conclusion === "skipped" ? "consumer-skipped" : "consumer-failed",
|
|
176
|
+
run: run.html_url,
|
|
177
|
+
step: check.name,
|
|
178
|
+
reason: `the consumer step ${check.conclusion ?? check.status}`,
|
|
179
|
+
};
|
|
180
|
+
}
|