@adea-ai/app-framework 0.24.0 → 0.25.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.
Files changed (137) hide show
  1. package/README.md +49 -1
  2. package/dist/cli/macos-signing-cli.d.ts +2 -0
  3. package/dist/cli/macos-signing-cli.js +14 -0
  4. package/dist/desktop/channel-proof.js +7 -1
  5. package/dist/framework-source.json +1 -1
  6. package/dist/release/framework-package-publish.js +4 -2
  7. package/dist/release/local-release.d.ts +2 -0
  8. package/dist/release/local-release.js +25 -2
  9. package/dist/release/macos-signing.d.ts +27 -0
  10. package/dist/release/macos-signing.js +101 -0
  11. package/dist/shell/app-shell.js +21 -33
  12. package/dist/shell/navigation-drawer.d.ts +12 -0
  13. package/dist/shell/navigation-drawer.js +42 -0
  14. package/dist/updates/release-feed.d.ts +2 -0
  15. package/dist/updates/release-feed.js +11 -2
  16. package/package.json +16 -4
  17. package/src/shell/app-shell.tsx +29 -20
  18. package/src/shell/navigation-drawer.tsx +36 -0
  19. package/src/app/create-application.ts +0 -245
  20. package/src/app/service-registry.ts +0 -124
  21. package/src/ci/toolchain-identity.ts +0 -244
  22. package/src/cli/cef-helper-cli.ts +0 -21
  23. package/src/cli/cli-runner.ts +0 -29
  24. package/src/cli/create-application-cli.ts +0 -62
  25. package/src/cli/electrobun-shortcut-patch-cli.ts +0 -24
  26. package/src/cli/framework-update-cli.ts +0 -41
  27. package/src/cli/release-assets-plan-cli.ts +0 -14
  28. package/src/cli/release-cut-cli.ts +0 -41
  29. package/src/cli/release-descriptor-staging-cli.ts +0 -57
  30. package/src/cli/release-finalize-cli.ts +0 -34
  31. package/src/cli/release-promote-cli.ts +0 -31
  32. package/src/cli/release-publish-cli.ts +0 -46
  33. package/src/cli/release-sign-cli.ts +0 -24
  34. package/src/cli/release-step-cli.ts +0 -71
  35. package/src/cli/toolchain-identity-cli.ts +0 -12
  36. package/src/cli/update-helper-cli.ts +0 -12
  37. package/src/cli/windows-runtime-patch-cli.ts +0 -17
  38. package/src/desktop/application-command-client.ts +0 -43
  39. package/src/desktop/channel-handshake.ts +0 -136
  40. package/src/desktop/channel-proof.ts +0 -122
  41. package/src/desktop/desktop-client.ts +0 -303
  42. package/src/desktop/desktop-gateway.ts +0 -189
  43. package/src/desktop/desktop-host.ts +0 -335
  44. package/src/desktop/desktop-stream.ts +0 -324
  45. package/src/desktop/loopback-policy.ts +0 -41
  46. package/src/desktop/open-url-channel.ts +0 -79
  47. package/src/desktop/string-policy.ts +0 -9
  48. package/src/installer/archive-entry.ts +0 -32
  49. package/src/installer/command-artifact.ts +0 -307
  50. package/src/installer/command-qualification-command.ts +0 -75
  51. package/src/installer/hosted-runner.ts +0 -11
  52. package/src/installer/installed-payload.ts +0 -408
  53. package/src/installer/installer-ci-bootstrap.ts +0 -199
  54. package/src/installer/installer-ci-preflight.ts +0 -61
  55. package/src/installer/installer-ci-worker.ts +0 -105
  56. package/src/installer/installer-extraction.ts +0 -367
  57. package/src/installer/installer-fetch-guard.ts +0 -75
  58. package/src/installer/installer-identity.ts +0 -331
  59. package/src/installer/installer-layout.ts +0 -167
  60. package/src/installer/installer-observation.ts +0 -671
  61. package/src/installer/installer-process-cleanup.ts +0 -167
  62. package/src/installer/installer-qualification-command.ts +0 -81
  63. package/src/installer/installer-renderer-evidence.ts +0 -268
  64. package/src/installer/installer-upgrade-command.ts +0 -226
  65. package/src/installer/installer-worker-guard.ts +0 -112
  66. package/src/installer/native-executable.ts +0 -37
  67. package/src/installer/upgrade-asset-download.ts +0 -72
  68. package/src/installer/write-all.ts +0 -19
  69. package/src/native/app-bundle.ts +0 -86
  70. package/src/native/cef-helper.ts +0 -471
  71. package/src/native/desktop-build-hook.ts +0 -21
  72. package/src/native/electrobun-source-patch.ts +0 -107
  73. package/src/native/linux-cef-links.ts +0 -14
  74. package/src/native/native-secret-store.ts +0 -99
  75. package/src/native/native-utilities.ts +0 -166
  76. package/src/native/partitioned-window.ts +0 -62
  77. package/src/native/secure-window.ts +0 -115
  78. package/src/native/sidecar-services.ts +0 -71
  79. package/src/native/sidecar.ts +0 -387
  80. package/src/native/window-bootstrap.ts +0 -77
  81. package/src/native/windows-build-hook-internal.ts +0 -49
  82. package/src/native/windows-build-hook.ts +0 -12
  83. package/src/native/windows-runtime-patch-internal.ts +0 -48
  84. package/src/native/windows-runtime-patch.ts +0 -15
  85. package/src/release/feed-release-cut.ts +0 -110
  86. package/src/release/feed-state.ts +0 -135
  87. package/src/release/framework-package-publish.ts +0 -163
  88. package/src/release/framework-update.ts +0 -196
  89. package/src/release/github-cli.ts +0 -27
  90. package/src/release/github-release-assets.ts +0 -36
  91. package/src/release/github-release-cut.ts +0 -237
  92. package/src/release/github-release-lookup.ts +0 -39
  93. package/src/release/github-release-promotion.ts +0 -112
  94. package/src/release/github-release-provenance.ts +0 -65
  95. package/src/release/github-release-publisher.ts +0 -90
  96. package/src/release/github-release-qualification.ts +0 -144
  97. package/src/release/local-provenance.ts +0 -92
  98. package/src/release/local-release.ts +0 -525
  99. package/src/release/macos-dmg.ts +0 -113
  100. package/src/release/release-artifact.ts +0 -53
  101. package/src/release/release-assets-plan.ts +0 -118
  102. package/src/release/release-config.ts +0 -420
  103. package/src/release/release-cut-command.ts +0 -80
  104. package/src/release/release-cut.ts +0 -133
  105. package/src/release/release-descriptor-staging.ts +0 -242
  106. package/src/release/release-finalize.ts +0 -191
  107. package/src/release/release-promotion-command.ts +0 -36
  108. package/src/release/release-promotion.ts +0 -132
  109. package/src/release/release-publication.ts +0 -213
  110. package/src/release/release-publish-command.ts +0 -163
  111. package/src/release/release-qualification.ts +0 -397
  112. package/src/release/release-staging.ts +0 -87
  113. package/src/release/release-steps.ts +0 -173
  114. package/src/release/retained-release-build.ts +0 -217
  115. package/src/shell/application-menu-commands.ts +0 -6
  116. package/src/shell/application-menu.ts +0 -250
  117. package/src/updates/channel-update-manager.ts +0 -127
  118. package/src/updates/desktop-updater.ts +0 -440
  119. package/src/updates/release-feed.ts +0 -187
  120. package/src/updates/release-location.ts +0 -101
  121. package/src/updates/signed-release.ts +0 -311
  122. package/src/updates/stable-file.ts +0 -32
  123. package/src/updates/update-arm.ts +0 -107
  124. package/src/updates/update-channel-store.ts +0 -86
  125. package/src/updates/update-discovery.ts +0 -113
  126. package/src/updates/update-download.ts +0 -82
  127. package/src/updates/update-exclusive-rename.ts +0 -58
  128. package/src/updates/update-extraction.ts +0 -261
  129. package/src/updates/update-handoff-plan.ts +0 -75
  130. package/src/updates/update-helper.ts +0 -87
  131. package/src/updates/update-launch.ts +0 -33
  132. package/src/updates/update-manager.ts +0 -130
  133. package/src/updates/update-process-fence.ts +0 -125
  134. package/src/updates/update-resume.ts +0 -34
  135. package/src/updates/update-shutdown.ts +0 -37
  136. package/src/updates/update-swap-stage.ts +0 -75
  137. package/src/updates/update-swap.ts +0 -30
@@ -1,420 +0,0 @@
1
- import { parseOfflinePolicy, type Requirements } from './release-qualification'
2
- import { assertSidecarNames } from '../native/app-bundle'
3
- import { containsAsciiControl } from '../desktop/string-policy'
4
- import { parseReleaseFeed, type ReleaseFeed } from '../updates/release-feed'
5
-
6
- const object = (value: unknown): value is Record<string, unknown> =>
7
- typeof value === 'object' && value !== null && !Array.isArray(value)
8
- const strings = (value: unknown): value is string[] =>
9
- Array.isArray(value) &&
10
- value.length > 0 &&
11
- value.every(
12
- (item) =>
13
- typeof item === 'string' &&
14
- item.length <= 200 &&
15
- /^[A-Za-z0-9][A-Za-z0-9._{}-]*$/.test(item) &&
16
- !item.replaceAll('{tag}', '').includes('{') &&
17
- !item.replaceAll('{tag}', '').includes('}')
18
- ) &&
19
- new Set(value).size === value.length
20
-
21
- const appIdPattern = /^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+$/
22
- const token = (value: unknown): value is string =>
23
- typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9._=-]{0,63}$/.test(value)
24
- const tokens = (value: unknown, minimum: number): value is string[] =>
25
- Array.isArray(value) && value.length >= minimum && value.length <= 8 && value.every(token)
26
- const relativePath = (value: unknown): value is string =>
27
- typeof value === 'string' &&
28
- value.length <= 200 &&
29
- /^[A-Za-z0-9._/-]+$/.test(value) &&
30
- value.split('/').every((part) => part !== '' && part !== '.' && part !== '..')
31
-
32
- /** The descriptor target each release platform publishes for. */
33
- export const platformTargets = {
34
- 'macos-arm64': ['darwin', 'arm64'],
35
- 'windows-x64': ['win32', 'x64'],
36
- 'linux-x64': ['linux', 'x64'],
37
- } as const
38
- export type ReleasePlatform = keyof typeof platformTargets
39
- const releasePlatforms = Object.keys(platformTargets) as ReleasePlatform[]
40
-
41
- /**
42
- * A portable command-line payload published beside the desktop payloads: a `.tar.gz` holding one
43
- * directory named after the asset, with `bin/<executable>` (`bin/<executable>.cmd` on Windows).
44
- * The build leaves that directory's contents at `build`, relative to the app directory.
45
- */
46
- export type CommandArtifactPolicy = Readonly<{
47
- kind: string
48
- /** Update identity its signed descriptors carry; distinct from the desktop app's. */
49
- appId: string
50
- executable: string
51
- build: string
52
- /** Release asset name template for each release platform. */
53
- platforms: Readonly<Record<ReleasePlatform, string>>
54
- qualification: Readonly<{
55
- /** Extra environment for every qualification command. */
56
- env: Readonly<Record<string, string>>
57
- /** Argument lists that must each exit 0 after `--version` prints the release version. */
58
- probes: readonly (readonly string[])[]
59
- /** The long-running command started, observed alive, then stopped. */
60
- service: readonly string[]
61
- }>
62
- }>
63
-
64
- function parseCommandArtifacts(value: unknown, platforms: readonly string[]) {
65
- if (value === undefined) return []
66
- if (!object(value) || Object.keys(value).length > 4) throw new Error('Invalid command artifacts')
67
- return Object.entries(value).map(([kind, policy]): CommandArtifactPolicy => {
68
- const qualification = object(policy) ? policy.qualification : undefined
69
- const env = object(qualification) ? qualification.env : undefined
70
- if (
71
- !/^[a-z][a-z0-9-]{0,31}$/.test(kind) ||
72
- !object(policy) ||
73
- Object.keys(policy).length !== 5 ||
74
- typeof policy.appId !== 'string' ||
75
- policy.appId.length > 255 ||
76
- !appIdPattern.test(policy.appId) ||
77
- typeof policy.executable !== 'string' ||
78
- !/^[a-z][a-z0-9-]{0,63}$/.test(policy.executable) ||
79
- !relativePath(policy.build) ||
80
- !object(policy.platforms) ||
81
- Object.keys(policy.platforms).length !== platforms.length ||
82
- platforms.some(
83
- (platform) =>
84
- typeof (policy.platforms as Record<string, unknown>)[platform] !== 'string' ||
85
- !strings([(policy.platforms as Record<string, string>)[platform]]) ||
86
- !(policy.platforms as Record<string, string>)[platform]!.endsWith('.tar.gz')
87
- ) ||
88
- !object(qualification) ||
89
- Object.keys(qualification).length !== 3 ||
90
- !object(env) ||
91
- Object.keys(env).length > 16 ||
92
- Object.entries(env).some(
93
- ([name, item]) =>
94
- !/^[A-Z][A-Z0-9_]{0,63}$/.test(name) ||
95
- /^(?:PATH|HOME|USERPROFILE|TMP|TEMP|TMPDIR|SYSTEMROOT|WINDIR|COMSPEC|PATHEXT|LOCALAPPDATA|APPDATA|XDG_[A-Z_]+)$/.test(
96
- name
97
- ) ||
98
- typeof item !== 'string' ||
99
- item.length > 256 ||
100
- containsAsciiControl(item)
101
- ) ||
102
- !Array.isArray(qualification.probes) ||
103
- qualification.probes.length > 8 ||
104
- !qualification.probes.every((probe) => tokens(probe, 1)) ||
105
- !tokens(qualification.service, 1)
106
- )
107
- throw new Error('Invalid command artifact')
108
- return {
109
- kind,
110
- appId: policy.appId,
111
- executable: policy.executable,
112
- build: policy.build,
113
- platforms: Object.fromEntries(
114
- platforms.map((platform) => [
115
- platform,
116
- (policy.platforms as Record<string, string>)[platform],
117
- ])
118
- ) as Record<ReleasePlatform, string>,
119
- qualification: {
120
- env: { ...(env as Record<string, string>) },
121
- probes: (qualification.probes as string[][]).map((probe) => [...probe]),
122
- service: [...(qualification.service as string[])],
123
- },
124
- }
125
- })
126
- }
127
-
128
- const workflowDirectory = '.github/workflows/'
129
- /** Caller workflows whose runs the release CLIs accept as provenance. */
130
- export type ReleaseWorkflows = { control: string; assets: string }
131
- /** The file name GitHub's workflow APIs and `gh workflow run` address a workflow by. */
132
- export const workflowFile = (path: string) => path.slice(workflowDirectory.length)
133
- const workflowPath = (value: unknown): value is string =>
134
- typeof value === 'string' &&
135
- value.length <= 200 &&
136
- value.startsWith(workflowDirectory) &&
137
- /^[A-Za-z0-9][A-Za-z0-9._-]*\.ya?ml$/.test(workflowFile(value))
138
-
139
- /** Validate shared daily, dev and stable asset requirements. */
140
- export function parseReleaseConfig(config: unknown): {
141
- soakHours: number
142
- expectedReads: readonly string[]
143
- versionSource: { kind: 'source-manifest'; path: string }
144
- releasePleaseManifestPath: string
145
- /** Sidecar executables every packaged payload must contain. */
146
- sidecars: readonly string[]
147
- releaseWorkflows: ReleaseWorkflows
148
- /** The HTTPS feed releases are published to and discovered from. */
149
- feed: ReleaseFeed
150
- commandArtifacts: readonly CommandArtifactPolicy[]
151
- requirements(tag: string): Requirements
152
- } {
153
- if (
154
- !object(config) ||
155
- !object(config.platforms) ||
156
- !strings(config.releaseAssets) ||
157
- !strings(config.dailyDiscoveryAssets) ||
158
- !strings(config.stableDiscoveryAssets) ||
159
- !strings(config.devDiscoveryAssets) ||
160
- !Number.isSafeInteger(config.soakHours) ||
161
- Number(config.soakHours) < 0 ||
162
- Number(config.soakHours) > 8760
163
- )
164
- throw new Error('Invalid release configuration')
165
- const workflows = config.releaseWorkflows
166
- if (
167
- !object(workflows) ||
168
- Object.keys(workflows).length !== 2 ||
169
- !workflowPath(workflows.control) ||
170
- !workflowPath(workflows.assets) ||
171
- workflows.control === workflows.assets
172
- )
173
- throw new Error('Invalid release workflows')
174
- const releaseWorkflows = { control: workflows.control, assets: workflows.assets }
175
- const feed = parseReleaseFeed(config.releaseFeed)
176
- let sidecars: readonly string[]
177
- try {
178
- sidecars = assertSidecarNames(config.sidecars ?? [])
179
- } catch {
180
- throw new Error('Invalid release sidecars')
181
- }
182
- const offlinePolicy =
183
- config.offlinePolicy === undefined ? undefined : parseOfflinePolicy(config.offlinePolicy)
184
- const source = config.versionSource
185
- if (
186
- !object(source) ||
187
- Object.keys(source).length !== 2 ||
188
- source.kind !== 'source-manifest' ||
189
- typeof source.path !== 'string' ||
190
- source.path.length > 200 ||
191
- !/^[A-Za-z0-9._/-]+\.json$/.test(source.path) ||
192
- source.path.startsWith('/') ||
193
- !source.path.split('/').every((part) => part !== '' && part !== '.' && part !== '..')
194
- )
195
- throw new Error('Invalid release version source')
196
- // Release Please owns the version: every daily and stable tag is a Release Please
197
- // release of this manifest, and dev builds are -dev.N of the next minor version.
198
- const versionSource = { kind: 'source-manifest' as const, path: source.path }
199
- const releasePleaseManifestPath = source.path
200
- const expectedReads = config.offlineExpectedReads === undefined ? [] : config.offlineExpectedReads
201
- if (
202
- !Array.isArray(expectedReads) ||
203
- expectedReads.length > 32 ||
204
- new Set(expectedReads).size !== expectedReads.length ||
205
- JSON.stringify(expectedReads).length > 8192
206
- )
207
- throw new Error('Invalid offline expected reads')
208
- for (const item of expectedReads) {
209
- if (typeof item !== 'string' || item.length > 2048)
210
- throw new Error('Invalid offline expected read')
211
- let url: URL
212
- try {
213
- url = new URL(item)
214
- } catch {
215
- throw new Error('Invalid offline expected read')
216
- }
217
- if (url.protocol !== 'https:' || url.username || url.password || url.hash || url.href !== item)
218
- throw new Error('Invalid offline expected read')
219
- }
220
- const platforms = config.platforms
221
- for (const required of releasePlatforms)
222
- if (!Object.hasOwn(platforms, required))
223
- throw new Error('Releases require all supported desktop platforms')
224
- for (const [platform, assets] of Object.entries(platforms))
225
- if (!/^[a-z0-9-]+$/.test(platform) || !strings(assets))
226
- throw new Error('Invalid release platform configuration')
227
- // Keep the validated requirements independent of subsequent caller mutations.
228
- const platformSnapshot = Object.fromEntries(
229
- Object.entries(platforms).map(([platform, assets]) => [platform, [...(assets as string[])]])
230
- )
231
- const commandArtifacts = parseCommandArtifacts(config.commandArtifacts, Object.keys(platforms))
232
- const appIds = [config.appId, ...commandArtifacts.map((artifact) => artifact.appId)]
233
- if (new Set(appIds).size !== appIds.length)
234
- throw new Error('Command artifacts need their own update identity')
235
- const releaseAssets = [...config.releaseAssets]
236
- const daily = [...config.dailyDiscoveryAssets]
237
- const stable = [...config.stableDiscoveryAssets]
238
- const dev = [...config.devDiscoveryAssets]
239
- if (
240
- daily.some(
241
- (name) => !releaseAssets.includes(name) || stable.includes(name) || dev.includes(name)
242
- ) ||
243
- stable.some((name) => !releaseAssets.includes(name) || dev.includes(name)) ||
244
- dev.some((name) => !releaseAssets.includes(name))
245
- )
246
- throw new Error('Daily, stable and dev discovery assets must be distinct release assets')
247
- const requirements = (tag: string): Requirements => {
248
- if (!/^v\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(tag) || tag.length > 65)
249
- throw new Error('Invalid release tag')
250
- const isDev = tag.includes('-dev.')
251
- const selectedAssets = releaseAssets.filter((name) =>
252
- isDev ? !daily.includes(name) && !stable.includes(name) : !dev.includes(name)
253
- )
254
- const substitute = (value: string) => value.replaceAll('{tag}', tag)
255
- const result = {
256
- platforms: Object.fromEntries(
257
- Object.entries(platformSnapshot).map(([platform, assets]) => [
258
- platform,
259
- assets.map(substitute),
260
- ])
261
- ),
262
- releaseAssets: selectedAssets.map(substitute),
263
- ...(offlinePolicy ? { offlinePolicy: { ...offlinePolicy } } : {}),
264
- ...(commandArtifacts.length
265
- ? {
266
- commandArtifacts: Object.fromEntries(
267
- commandArtifacts.map((artifact) => [
268
- artifact.kind,
269
- Object.fromEntries(
270
- Object.entries(artifact.platforms).map(([platform, name]) => [
271
- platform,
272
- substitute(name),
273
- ])
274
- ),
275
- ])
276
- ),
277
- }
278
- : {}),
279
- }
280
- const names = releaseAssetNames(result)
281
- if (
282
- new Set(names).size !== names.length ||
283
- names.some((name) => !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(name))
284
- )
285
- throw new Error('Invalid or duplicate release asset names')
286
- return result
287
- }
288
- // Validate names even while held, before a scheduled workflow is enabled.
289
- requirements('v1.0.0')
290
- return {
291
- soakHours: config.soakHours as number,
292
- expectedReads: [...expectedReads],
293
- versionSource,
294
- releasePleaseManifestPath,
295
- sidecars,
296
- releaseWorkflows,
297
- feed,
298
- commandArtifacts,
299
- requirements,
300
- }
301
- }
302
-
303
- /** Every payload and release asset a release's requirements name, desktop payloads first. */
304
- export function releaseAssetNames(requirements: Requirements): string[] {
305
- return [
306
- ...Object.values(requirements.platforms).flat(),
307
- ...Object.values(requirements.commandArtifacts ?? {}).flatMap((byPlatform) =>
308
- Object.values(byPlatform)
309
- ),
310
- ...requirements.releaseAssets,
311
- ]
312
- }
313
-
314
- /** The payloads one platform's build stages: its installer and archive, then its command artifacts. */
315
- export function platformPayloads(requirements: Requirements, platform: string): string[] {
316
- return [
317
- ...(requirements.platforms[platform] ?? []),
318
- ...Object.values(requirements.commandArtifacts ?? {}).map((byPlatform) => {
319
- const name = byPlatform[platform]
320
- if (!name) throw new Error('Command artifact is missing a platform')
321
- return name
322
- }),
323
- ]
324
- }
325
-
326
- export type DiscoveryPolicy = Readonly<{
327
- /** Discovery asset name for this tag. */
328
- name: string
329
- channel: 'dev' | 'daily' | 'stable'
330
- platform: ReleasePlatform
331
- os: (typeof platformTargets)[ReleasePlatform][0]
332
- arch: (typeof platformTargets)[ReleasePlatform][1]
333
- /** The update identity the descriptor carries. */
334
- appId: string
335
- /** The one payload the descriptor may name. */
336
- payload: string
337
- }>
338
-
339
- /**
340
- * Resolve the channel descriptors a tag publishes: one per channel, payload kind (the desktop
341
- * archive and each command artifact) and platform, each naming exactly that payload.
342
- */
343
- export function discoveryPolicies(config: unknown, tag: string): DiscoveryPolicy[] {
344
- const parsed = parseReleaseConfig(config)
345
- const requirements = parsed.requirements(tag)
346
- if (
347
- !object(config) ||
348
- typeof config.appId !== 'string' ||
349
- config.appId.length > 255 ||
350
- !appIdPattern.test(config.appId) ||
351
- !object(config.descriptors)
352
- )
353
- throw new Error('Invalid discovery policy')
354
- const descriptors = config.descriptors
355
- const kinds = [
356
- {
357
- appId: config.appId,
358
- payloads: (platform: ReleasePlatform) => requirements.platforms[platform]![1],
359
- },
360
- ...parsed.commandArtifacts.map((artifact) => ({
361
- appId: artifact.appId,
362
- payloads: (platform: ReleasePlatform) =>
363
- requirements.commandArtifacts![artifact.kind]![platform]!,
364
- })),
365
- ]
366
- const channels = tag.includes('-dev.') ? (['dev'] as const) : (['daily', 'stable'] as const)
367
- const result: DiscoveryPolicy[] = []
368
- for (const channel of channels) {
369
- const configured = config[`${channel}DiscoveryAssets`]
370
- if (!Array.isArray(configured)) throw new Error('Invalid discovery policy')
371
- for (const template of configured) {
372
- const policy = typeof template === 'string' ? descriptors[template] : undefined
373
- const platform = object(policy)
374
- ? releasePlatforms.find(
375
- (value) =>
376
- policy.platform === platformTargets[value][0] &&
377
- policy.arch === platformTargets[value][1]
378
- )
379
- : undefined
380
- const payload =
381
- object(policy) &&
382
- Array.isArray(policy.allowedPayloads) &&
383
- policy.allowedPayloads.length === 1 &&
384
- typeof policy.allowedPayloads[0] === 'string'
385
- ? policy.allowedPayloads[0].replaceAll('{tag}', tag)
386
- : undefined
387
- const kind = platform && kinds.find((value) => value.payloads(platform) === payload)
388
- const name = (template as string).replaceAll('{tag}', tag)
389
- if (
390
- !object(policy) ||
391
- policy.channel !== channel ||
392
- !platform ||
393
- !kind ||
394
- !payload ||
395
- !requirements.releaseAssets.includes(name)
396
- )
397
- throw new Error('Invalid discovery policy')
398
- if (
399
- result.some(
400
- (value) =>
401
- value.name === name ||
402
- (value.channel === channel && value.appId === kind.appId && value.platform === platform)
403
- )
404
- )
405
- throw new Error('Duplicate discovery policy')
406
- const [os, arch] = platformTargets[platform]
407
- result.push({ name, channel, platform, os, arch, appId: kind.appId, payload })
408
- }
409
- for (const kind of kinds)
410
- for (const platform of releasePlatforms)
411
- if (
412
- !result.some(
413
- (value) =>
414
- value.channel === channel && value.appId === kind.appId && value.platform === platform
415
- )
416
- )
417
- throw new Error('Missing platform discovery policy')
418
- }
419
- return result
420
- }
@@ -1,80 +0,0 @@
1
- import { execFile } from 'node:child_process'
2
- import { githubCli } from './github-cli'
3
- import { promisify } from 'node:util'
4
- import { createGitHubReleaseCutProvider } from './github-release-cut'
5
- import { cutRelease } from './release-cut'
6
- import { parseReleaseConfig, workflowFile } from './release-config'
7
- import { readSourceVersion } from './local-provenance'
8
-
9
- const execute = promisify(execFile)
10
- /** Execute release cuts only from the recorded main-branch GitHub workflow. */
11
- export async function runReleaseCutCommand(options: {
12
- env: Record<string, string | undefined>
13
- kind: 'dev' | 'daily'
14
- appName: string
15
- config: unknown
16
- run?: (args: string[], input?: string) => Promise<string>
17
- git?: (args: string[]) => Promise<string>
18
- }) {
19
- const { env, kind } = options
20
- if (
21
- env.GITHUB_ACTIONS !== 'true' ||
22
- env.GITHUB_REF !== 'refs/heads/main' ||
23
- !env.GITHUB_REPOSITORY ||
24
- !/^[a-f0-9]{40}$/.test(env.GITHUB_SHA ?? '') ||
25
- !/^[1-9]\d{0,19}$/.test(env.GITHUB_RUN_ID ?? '') ||
26
- !/^[1-9]\d{0,8}$/.test(env.GITHUB_RUN_ATTEMPT ?? '') ||
27
- (kind === 'daily'
28
- ? !['schedule', 'workflow_dispatch'].includes(env.GITHUB_EVENT_NAME ?? '')
29
- : kind === 'dev'
30
- ? !['push', 'workflow_dispatch'].includes(env.GITHUB_EVENT_NAME ?? '')
31
- : true)
32
- )
33
- throw new Error('Release cut requires a trusted main workflow')
34
- const { requirements, versionSource, releasePleaseManifestPath, releaseWorkflows } =
35
- parseReleaseConfig(options.config)
36
- const run = options.run ?? githubCli()
37
- const git =
38
- options.git ??
39
- (async (args: string[]) =>
40
- (await execute('git', args, { maxBuffer: 1024 * 1024 })).stdout.trim())
41
- const repository = env.GITHUB_REPOSITORY
42
- const sourceSha = env.GITHUB_SHA!
43
- const provider = createGitHubReleaseCutProvider({
44
- repository,
45
- appName: options.appName,
46
- requirements,
47
- assetsWorkflow: releaseWorkflows.assets,
48
- releasePleaseManifestPath,
49
- run,
50
- })
51
- const workflow = JSON.parse(
52
- await run(['api', `repos/${repository}/actions/runs/${env.GITHUB_RUN_ID}`])
53
- ) as {
54
- id?: unknown
55
- run_attempt?: unknown
56
- head_sha?: unknown
57
- event?: unknown
58
- path?: unknown
59
- repository?: { full_name?: unknown }
60
- }
61
- if (
62
- String(workflow?.id) !== env.GITHUB_RUN_ID ||
63
- String(workflow?.run_attempt) !== env.GITHUB_RUN_ATTEMPT ||
64
- workflow?.head_sha !== sourceSha ||
65
- workflow?.event !== env.GITHUB_EVENT_NAME ||
66
- workflow?.path !== releaseWorkflows.control ||
67
- workflow?.repository?.full_name !== repository
68
- )
69
- throw new Error('Release workflow provenance mismatch')
70
- const assetsWorkflow = JSON.parse(
71
- await run([
72
- 'api',
73
- `repos/${repository}/actions/workflows/${workflowFile(releaseWorkflows.assets)}`,
74
- ])
75
- ) as { path?: unknown; state?: unknown }
76
- if (assetsWorkflow?.path !== releaseWorkflows.assets || assetsWorkflow?.state !== 'active')
77
- throw new Error('Release-assets workflow is unavailable')
78
- const releasedVersion = await readSourceVersion(git, sourceSha, versionSource.path)
79
- return cutRelease({ kind, sourceSha, releasedVersion, provider })
80
- }
@@ -1,133 +0,0 @@
1
- /** Release identity selection adapted from adea-ai/adea scripts/release-control.mjs,
2
- * commit 6155d18941acbb14d9099bc2a33a50ee9683a068 (Apache-2.0). */
3
- export type CutRelease = {
4
- tag: string
5
- sourceSha: string
6
- kind: 'dev' | 'daily'
7
- draft: boolean
8
- prerelease: boolean
9
- stageableDraft?: boolean
10
- }
11
- export type ReleaseCutProvider = {
12
- /** Return a release only after independently resolving its tag target and channel marker. */
13
- find(tag: string): Promise<CutRelease | null>
14
- isMainAncestor(sha: string): Promise<boolean>
15
- /** Whether `newer` strictly descends from `older`. */
16
- isAncestor(older: string, newer: string): Promise<boolean>
17
- /** Create a dev prerelease for the tag at the source commit. */
18
- create(identity: Pick<CutRelease, 'tag' | 'sourceSha'>): Promise<void>
19
- qualification(release: CutRelease): Promise<'qualified' | 'not-qualified' | 'unknown'>
20
- pendingBuild(release: CutRelease): Promise<'pending' | 'idle' | 'unknown'>
21
- /** Inspect all existing dev releases of a dev version line; errors must fail closed. */
22
- highestDevCounter(version: string): Promise<number>
23
- /** Check the actual Git tag even when no release exists. */
24
- tagExists(tag: string): Promise<boolean>
25
- dispatch(tag: string): Promise<void>
26
- }
27
-
28
- /**
29
- * The version dev builds after `released` are numbered for: the next minor version.
30
- * Release Please writes a version to the manifest only when it releases it, so the
31
- * source manifest always names a released version (or the one its own commit
32
- * releases). The next release is a patch or minor above it, or a new major, so dev
33
- * builds of the next minor sort above the release they follow, and stay strictly
34
- * increasing across a patch release, which leaves the next minor unchanged.
35
- */
36
- export function nextDevVersion(released: string): string {
37
- const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.exec(released)
38
- if (!match) throw new Error('Invalid release identity')
39
- return `${match[1]}.${BigInt(match[2]!) + 1n}.0`
40
- }
41
-
42
- /**
43
- * Cut or repair a daily/dev release without moving an existing tag. A daily is the
44
- * Release Please release `v<version>` of the source manifest's version. A dev build is
45
- * `v<next>-dev.N` for the next unreleased version (see `nextDevVersion`), where N counts
46
- * that version's dev releases from 1, so it starts again at 1 when a release moves the
47
- * next version: `v0.112.0-dev.15` is followed, after the `v0.112.0` release, by
48
- * `v0.113.0-dev.1`.
49
- */
50
- export async function cutRelease(options: {
51
- kind: 'dev' | 'daily'
52
- sourceSha: string
53
- /** The version in the source manifest at the exact source commit: the latest release. */
54
- releasedVersion: string
55
- provider: ReleaseCutProvider
56
- }): Promise<{ tag: string; sourceSha: string; status: 'qualified' | 'pending' | 'dispatched' }> {
57
- const { kind, sourceSha, releasedVersion, provider } = options
58
- if (
59
- !['daily', 'dev'].includes(kind) ||
60
- !/^[a-f0-9]{40}$/.test(sourceSha) ||
61
- typeof releasedVersion !== 'string' ||
62
- releasedVersion.length > 48 ||
63
- !/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(releasedVersion)
64
- )
65
- throw new Error('Invalid release identity')
66
- const version = kind === 'dev' ? nextDevVersion(releasedVersion) : releasedVersion
67
- if (!(await provider.isMainAncestor(sourceSha)))
68
- throw new Error('Requested source is not on main')
69
- let count = 0
70
- if (kind === 'dev') {
71
- const highest = await provider.highestDevCounter(version)
72
- if (!Number.isSafeInteger(highest) || highest < 0)
73
- throw new Error('Dev release history is invalid')
74
- // A retried cut of the newest dev source repairs that release instead of cutting a
75
- // second tag for the same commit.
76
- const newest = highest > 0 ? await provider.find(`v${version}-dev.${highest}`) : null
77
- if (highest > 0 && !newest) throw new Error('Dev release history changed')
78
- if (
79
- newest &&
80
- newest.sourceSha !== sourceSha &&
81
- !(await provider.isAncestor(newest.sourceSha, sourceSha))
82
- )
83
- throw new Error('Dev release source is not newer than the last dev release')
84
- count = newest?.sourceSha === sourceSha ? highest : highest + 1
85
- }
86
- const tag = `v${version}${kind === 'dev' ? `-dev.${count}` : ''}`
87
- let release = await provider.find(tag)
88
- if (!release) {
89
- // Release Please creates every daily; only dev releases are cut here.
90
- if (kind === 'daily') throw new Error('Release Please has not released this version')
91
- if (await provider.tagExists(tag)) throw new Error('Existing tag has no trusted release')
92
- await provider.create({ tag, sourceSha })
93
- release = await provider.find(tag)
94
- }
95
- if (
96
- !release ||
97
- release.tag !== tag ||
98
- release.kind !== kind ||
99
- (release.draft && !(kind === 'daily' && release.stageableDraft === true)) ||
100
- !/^[a-f0-9]{40}$/.test(release.sourceSha) ||
101
- (kind === 'dev' && release.sourceSha !== sourceSha) ||
102
- !(await provider.isMainAncestor(release.sourceSha))
103
- )
104
- throw new Error('Existing release identity mismatch')
105
- const qualification = await provider.qualification(release)
106
- if (qualification === 'qualified')
107
- return { tag, sourceSha: release.sourceSha, status: 'qualified' }
108
- if (
109
- qualification !== 'not-qualified' ||
110
- !(release.prerelease || (release.draft && release.stageableDraft))
111
- )
112
- throw new Error('Release qualification is unknown or stable')
113
- const pending = await provider.pendingBuild(release)
114
- if (pending === 'pending') return { tag, sourceSha: release.sourceSha, status: 'pending' }
115
- if (pending !== 'idle') throw new Error('Release build state is unknown')
116
- const current = await provider.find(tag)
117
- if (
118
- !current ||
119
- current.sourceSha !== release.sourceSha ||
120
- current.kind !== kind ||
121
- current.draft !== release.draft ||
122
- (current.draft ? current.stageableDraft !== true : !current.prerelease) ||
123
- !(await provider.isMainAncestor(current.sourceSha))
124
- )
125
- throw new Error('Release changed before build dispatch')
126
- if (kind === 'dev') {
127
- const latest = await provider.highestDevCounter(version)
128
- if (!Number.isSafeInteger(latest) || latest !== count)
129
- throw new Error('Dev release history changed before dispatch')
130
- }
131
- await provider.dispatch(tag)
132
- return { tag, sourceSha: release.sourceSha, status: 'dispatched' }
133
- }