15
type CandidateFile,
16
} from './artifacts';
17
import { GitHub, REPOSITORY_PATH, Sha, request } from './github';
18
-import { NPM_REGISTRY, REGISTRY_LANES, Language, type Language as Lang } from './lanes';
18
+import { CHANNELS, type Channel } from './channel';
19
+import {
20
+ NPM_REGISTRY,
21
+ REGISTRY_LANES,
22
+ REGISTRY_VERSION,
23
+ Language,
24
+ type Language as Lang,
25
+} from './lanes';
26
import { discoverPythonPackages } from './python-metadata';
27
import {
28
appendFile,
47
readonly sha256: string;
48
}
49
43
-export interface StableTag {
50
+/** An npm dist-tag of the release's channel that should point at `version`. */
51
+export interface ChannelTag {
52
readonly name: string;
53
readonly version: string;
54
+ readonly tag: string;
55
}
56
48
-/** What the registries already serve, what they are missing, and which `latest` tags lag. */
57
+/** What the registries already serve, what they are missing, and which channel tags lag. */
58
export interface RegistryState {
59
readonly existing: ReadonlyArray<Distribution>;
60
readonly missing: ReadonlyArray<Distribution>;
52
- readonly tagsToRepair: ReadonlyArray<StableTag>;
61
+ readonly tagsToRepair: ReadonlyArray<ChannelTag>;
62
}
63
64
const REGISTRY_TIMEOUT = '30 seconds';
134
version: Schema.String,
135
dist: Schema.Struct({ tarball: Url }),
136
});
128
-const NpmLatest = Schema.Struct({ version: Schema.String });
137
+const NpmTagged = Schema.Struct({ version: Schema.String });
138
const PackageIdentity = Schema.Struct({ name: Schema.String, version: Schema.String });
139
140
const pythonDistributionNames = (name: string, version: string) => {
164
sha256: entry.sha256,
165
});
166
158
-/** npm: one tarball per package version and a stable `latest` tag. */
167
+/**
168
+ * npm: one tarball per package version, and the channel's dist-tag moved forward to it. A beta
169
+ * only ever reads and moves its own tag, never `latest`.
170
+ */
171
const npmAdapter = {
160
- reconcileGroup: (group: ReadonlyArray<Distribution>) =>
172
+ reconcileGroup: (group: ReadonlyArray<Distribution>, channel: Channel) =>
173
Effect.gen(function* () {
174
yield* ensure(group.length === 1, 'Expected exactly one npm tarball per package');
175
const [file] = group;
185
);
186
yield* verifyOriginalBytes(dist.tarball, file);
187
}
176
- const latest = yield* registryJson(
177
- `${NPM_REGISTRY}/${encodeURIComponent(file.name)}/latest`,
178
- NpmLatest
188
+ const { npmTag } = CHANNELS[channel];
189
+ const current = yield* registryJson(
190
+ `${NPM_REGISTRY}/${encodeURIComponent(file.name)}/${npmTag}`,
191
+ NpmTagged
192
);
180
- const tagged = Option.getOrUndefined(Option.map(latest, value => value.version));
193
+ const tagged = Option.getOrUndefined(Option.map(current, value => value.version));
194
yield* ensure(
195
tagged === undefined || semver.valid(tagged) !== null,
183
- `Invalid stable npm tag: ${file.name}`
196
+ `Invalid npm ${npmTag} tag: ${file.name}`
197
);
198
return {
199
existing: Option.isSome(metadata) ? [file] : [],
200
missing: Option.isSome(metadata) ? [] : [file],
201
tagsToRepair:
202
tagged === undefined || semver.lt(tagged, file.version)
190
- ? [{ name: file.name, version: file.version }]
203
+ ? [{ name: file.name, version: file.version, tag: npmTag }]
204
: [],
205
} satisfies RegistryState;
206
}),
238
239
/** PyPI: a wheel and sdist for every package of the synchronized Python train. */
240
const pythonAdapter = {
228
- reconcileGroup: (group: ReadonlyArray<Distribution>) =>
241
+ reconcileGroup: (group: ReadonlyArray<Distribution>, _channel: Channel) =>
242
Effect.gen(function* () {
243
const [first] = group;
244
const metadata = yield* registryJson(
271
candidateDistributions: (candidate: LoadedCandidate) =>
272
Effect.gen(function* () {
273
const release = candidate.batch.plan.releases.find(entry => entry.language === 'python');
261
- const version = release?.newVersion ?? '';
274
+ const version = REGISTRY_VERSION.python(release?.newVersion ?? '');
275
const files: Distribution[] = [];
276
for (const pkg of yield* discoverPythonPackages(candidate.cwd))
277
for (const name of pythonDistributionNames(pkg.name, version)) {
290
const REGISTRY_ADAPTERS = { typescript: npmAdapter, python: pythonAdapter } as const;
291
292
/** Splits reviewed files into those the registry already serves and those still missing. */
280
-export const reconcileRegistry = (files: ReadonlyArray<Distribution>) =>
293
+export const reconcileRegistry = (
294
+ files: ReadonlyArray<Distribution>,
295
+ channel: Channel = 'stable'
296
+) =>
297
Effect.gen(function* () {
298
const groups = Map.groupBy(files, file => `${file.language}:${file.name}@${file.version}`);
299
const states: ReadonlyArray<RegistryState> = yield* Effect.forEach(groups.values(), group =>
284
- REGISTRY_ADAPTERS[group[0].language].reconcileGroup(group)
300
+ REGISTRY_ADAPTERS[group[0].language].reconcileGroup(group, channel)
301
);
302
return {
303
existing: states.flatMap(state => state.existing),
306
} satisfies RegistryState;
307
});
308
293
-const incompleteInventory = (state: RegistryState, stableTags: boolean) =>
309
+const incompleteInventory = (state: RegistryState, channelTags: boolean) =>
310
[
311
...state.missing.map(file => `${file.name}@${file.version}/${file.file}`),
296
- ...(stableTags ? state.tagsToRepair : []).map(tag => `${tag.name}@${tag.version} stable tag`),
312
+ ...(channelTags ? state.tagsToRepair : []).map(
313
+ tag => `${tag.name}@${tag.version} ${tag.tag} tag`
314
+ ),
315
].join(', ');
316
317
/**
300
- * Polls the registries until every file is visible, and every stable tag too unless
301
- * `stableTags` is false (right after an upload, before `latest` moves).
318
+ * Polls the registries until every file is visible, and every channel tag too unless
319
+ * `channelTags` is false (right after an upload, before the channel tag moves).
320
*/
321
export const waitForRegistry = (
322
files: ReadonlyArray<Distribution>,
323
options: {
324
readonly attempts?: number;
325
readonly spacing?: Duration.Input;
308
- readonly stableTags?: boolean;
326
+ readonly channelTags?: boolean;
327
+ readonly channel?: Channel;
328
} = {}
329
) => {
330
const attempts = options.attempts ?? 6;
312
- return reconcileRegistry(files).pipe(
331
+ return reconcileRegistry(files, options.channel).pipe(
332
Effect.flatMap(state => {
314
- const missing = incompleteInventory(state, options.stableTags ?? true);
333
+ const missing = incompleteInventory(state, options.channelTags ?? true);
334
return missing
335
? Effect.fail(new RegistryIncomplete({ message: missing }))
336
: Effect.succeed(state);
403
});
404
});
405
387
-/** Publishes under a release-only dist-tag, then moves `latest` once the upload is visible. */
388
-const publishNpm = (cwd: string, batch: ReleaseBatch, files: ReadonlyArray<Distribution>) =>
406
+/**
407
+ * Publishes under a release-only dist-tag, moves the channel's tag once the upload is visible,
408
+ * then drops the release-only tag.
409
+ */
410
+export const publishNpm = (cwd: string, batch: ReleaseBatch, files: ReadonlyArray<Distribution>) =>
411
Effect.gen(function* () {
412
const path = yield* Path.Path;
413
+ const channel = batch.plan.choices.channel;
414
const npm = (args: ReadonlyArray<string>) =>
415
run('npm', args, { cwd, env: withoutReleaseTokens });
393
- for (const file of (yield* reconcileRegistry(files)).missing)
416
+ for (const file of (yield* reconcileRegistry(files, channel)).missing)
417
yield* npm([
418
'publish',
419
path.resolve(cwd, 'sdk-publication/typescript', file.file),
422
'--access=public',
423
`--tag=sdk-release-${batch.id}`,
424
]);
402
- const visible = yield* waitForRegistry(files, { stableTags: false });
425
+ const visible = yield* waitForRegistry(files, { channelTags: false, channel });
426
for (const tag of visible.tagsToRepair)
404
- yield* npm(['dist-tag', 'add', `${tag.name}@${tag.version}`, 'latest']);
405
- yield* waitForRegistry(files);
427
+ yield* npm(['dist-tag', 'add', `${tag.name}@${tag.version}`, tag.tag]);
428
+ yield* waitForRegistry(files, { channel });
429
// The release-only tag only served the upload; a re-run finds it already gone.
430
const releaseOnly = `sdk-release-${batch.id}`;
431
for (const file of files) {
481
const files = yield* loadOriginalDistributions(cwd, batch, env.sha, env.approved, language).pipe(
482
Effect.provide(GitHub.layer(env.token))
483
);
461
- if (mode === 'verify') return yield* waitForRegistry(files);
484
+ if (mode === 'verify')
485
+ return yield* waitForRegistry(files, { channel: batch.plan.choices.channel });
486
if (language === 'typescript') return yield* publishNpm(cwd, batch, files);
487
yield* stageMissingPython(cwd, files, env.output);
488
});