@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,397 +0,0 @@
1
- import { containsAsciiControl } from '../desktop/string-policy'
2
-
3
- /** Release qualification adapted from adea-ai/adea scripts/release-policy.mjs
4
- * and scripts/desktop-renderer-probe.mjs, commit 6155d18941acbb14d9099bc2a33a50ee9683a068 (Apache-2.0). */
5
- export type Artifact = { name: string; size: number; digest: string }
6
- export type ReleaseIdentity = {
7
- tag: string
8
- sourceSha: string
9
- workflowSha: string
10
- runId: string
11
- runAttempt: number
12
- }
13
- export type OfflinePolicy =
14
- | { kind: 'standalone'; marker: string }
15
- | { kind: 'local-bootstrap'; marker: string; path: string }
16
- export type RendererEvidence = {
17
- method: string
18
- origin: string
19
- samples: number
20
- guardInstalled: boolean
21
- bootstrapDenied: boolean
22
- offlineObserved: boolean
23
- unexpectedActivity: boolean
24
- elapsedMs: number
25
- visible: boolean
26
- readyState: string
27
- width: number
28
- height: number
29
- interactiveElements: number
30
- textLength: number
31
- markerObserved?: boolean
32
- browserNetworkRestricted?: boolean
33
- offlinePolicy?: OfflinePolicy
34
- }
35
- export type InstallerReceipt = ReleaseIdentity & {
36
- schema: number
37
- platform: string
38
- installed: boolean
39
- launched: boolean
40
- rendererReady: boolean
41
- rendererEvidence: RendererEvidence
42
- assets: Artifact[]
43
- }
44
- /** One command artifact extracted into a clean location and run there. */
45
- export type CommandReceipt = ReleaseIdentity & {
46
- schema: 1
47
- kind: string
48
- platform: string
49
- installed: boolean
50
- versionMatched: boolean
51
- probesPassed: boolean
52
- serviceStarted: boolean
53
- /** How the service was stopped: SIGTERM with a clean exit, or the Windows process tree. */
54
- serviceStopped: 'sigterm' | 'process-tree'
55
- asset: Artifact
56
- }
57
- export type Qualification = ReleaseIdentity & {
58
- schema: number
59
- platforms: string[]
60
- installerTests: string[]
61
- installerReceipts: InstallerReceipt[]
62
- /** Present exactly when the release requires command artifacts. */
63
- commandReceipts?: CommandReceipt[]
64
- assets: Artifact[]
65
- }
66
- export type Requirements = {
67
- platforms: Record<string, readonly string[]>
68
- releaseAssets: readonly string[]
69
- offlinePolicy?: OfflinePolicy
70
- /** Command artifact asset names by kind, then platform; absent when the app ships none. */
71
- commandArtifacts?: Record<string, Record<string, string>>
72
- }
73
- export type Release = { tag_name: string; draft: boolean; assets: Artifact[] }
74
-
75
- function assert(condition: unknown, message: string): asserts condition {
76
- if (!condition) throw new Error(message)
77
- }
78
- function expectedAssets(requirements: Requirements): string[] {
79
- if (Object.hasOwn(requirements, 'offlinePolicy')) parseOfflinePolicy(requirements.offlinePolicy)
80
- const platforms = Object.entries(requirements.platforms)
81
- assert(platforms.length > 0, 'Missing platforms')
82
- const names = [
83
- ...platforms.flatMap(([platform, artifacts]) => {
84
- assert(/^[a-z0-9-]+$/.test(platform) && artifacts.length > 0, 'Invalid platform requirements')
85
- return artifacts
86
- }),
87
- ...Object.entries(requirements.commandArtifacts ?? {}).flatMap(([kind, byPlatform]) => {
88
- assert(
89
- /^[a-z][a-z0-9-]{0,31}$/.test(kind) &&
90
- Object.keys(byPlatform).length === platforms.length &&
91
- platforms.every(([platform]) => typeof byPlatform[platform] === 'string'),
92
- 'Invalid command artifact requirements'
93
- )
94
- return Object.values(byPlatform)
95
- }),
96
- ...requirements.releaseAssets,
97
- ]
98
- assert(
99
- names.length > 0 &&
100
- names.every((name) => /^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(name)) &&
101
- new Set(names).size === names.length,
102
- 'Invalid or duplicate asset requirements'
103
- )
104
- return names
105
- }
106
- function matches(saved: Artifact, uploaded: Artifact): boolean {
107
- return Boolean(
108
- saved &&
109
- uploaded &&
110
- saved.name === uploaded.name &&
111
- Number.isSafeInteger(saved.size) &&
112
- saved.size > 0 &&
113
- saved.size === uploaded.size &&
114
- /^sha256:[a-f0-9]{64}$/.test(saved.digest) &&
115
- saved.digest === uploaded.digest
116
- )
117
- }
118
- function uniqueAsset(assets: Artifact[], name: string): Artifact {
119
- const found = assets.filter((asset) => asset.name === name)
120
- assert(found.length === 1, `Missing or duplicate asset: ${name}`)
121
- return found[0]!
122
- }
123
- export function parseOfflinePolicy(value: unknown): OfflinePolicy {
124
- assert(
125
- typeof value === 'object' && value !== null && !Array.isArray(value),
126
- 'Invalid offline policy'
127
- )
128
- const policy = value as Record<string, unknown>
129
- assert(
130
- typeof policy.marker === 'string' &&
131
- policy.marker.trim().length > 0 &&
132
- policy.marker.length <= 256 &&
133
- !containsAsciiControl(policy.marker),
134
- 'Invalid offline marker'
135
- )
136
- if (policy.kind === 'standalone') {
137
- assert(Object.keys(policy).length === 2, 'Invalid standalone offline policy')
138
- return { kind: 'standalone', marker: policy.marker }
139
- }
140
- assert(
141
- policy.kind === 'local-bootstrap' &&
142
- Object.keys(policy).length === 3 &&
143
- typeof policy.path === 'string' &&
144
- policy.path.length <= 256 &&
145
- /^\/(?:[A-Za-z0-9_~-]+\/)*[A-Za-z0-9_~-]+$/.test(policy.path) &&
146
- !policy.path.startsWith('/__framework/'),
147
- 'Invalid bootstrap offline policy'
148
- )
149
- return { kind: 'local-bootstrap', marker: policy.marker, path: policy.path }
150
- }
151
- function checkRenderer(value: RendererEvidence, offlinePolicy?: OfflinePolicy): void {
152
- const port = Number(value?.origin?.split(':').at(-1))
153
- const common =
154
- value &&
155
- port >= 1024 &&
156
- port <= 65535 &&
157
- /^http:\/\/127\.0\.0\.1:[1-9]\d{3,4}$/.test(value.origin) &&
158
- value.samples === 2 &&
159
- value.guardInstalled === true &&
160
- value.offlineObserved === true &&
161
- value.unexpectedActivity === false &&
162
- Number.isFinite(value.elapsedMs) &&
163
- value.elapsedMs >= 3000 &&
164
- value.visible === true &&
165
- ['interactive', 'complete'].includes(value.readyState) &&
166
- Number.isFinite(value.width) &&
167
- value.width >= 100 &&
168
- Number.isFinite(value.height) &&
169
- value.height >= 100 &&
170
- Number.isSafeInteger(value.interactiveElements) &&
171
- value.interactiveElements >= 1 &&
172
- Number.isSafeInteger(value.textLength) &&
173
- value.textLength >= 1
174
- if (!offlinePolicy) {
175
- assert(
176
- common && value.method === 'native-dom-raf-v1' && value.bootstrapDenied === true,
177
- 'Incomplete native renderer evidence'
178
- )
179
- return
180
- }
181
- assert(value && value.offlinePolicy, 'Incomplete native renderer evidence')
182
- const policy = parseOfflinePolicy(offlinePolicy),
183
- observed = parseOfflinePolicy(value.offlinePolicy)
184
- assert(
185
- common &&
186
- value.method === 'native-dom-raf-v2' &&
187
- value.markerObserved === true &&
188
- value.browserNetworkRestricted === true &&
189
- observed.kind === policy.kind &&
190
- observed.marker === policy.marker &&
191
- (policy.kind === 'standalone'
192
- ? value.bootstrapDenied === false
193
- : observed.kind === 'local-bootstrap' &&
194
- observed.path === policy.path &&
195
- value.bootstrapDenied === true),
196
- 'Incomplete native renderer evidence'
197
- )
198
- }
199
- /** Validate one installed-app receipt against the exact attempt and payload bytes. */
200
- export function validateInstallerReceipt(
201
- identity: ReleaseIdentity,
202
- entry: InstallerReceipt,
203
- platform: string,
204
- names: readonly string[],
205
- assets: Artifact[],
206
- offlinePolicy?: OfflinePolicy
207
- ): true {
208
- assertIdentity(identity, platform)
209
- assert(
210
- Array.isArray(names) && new Set(names).size === names.length,
211
- 'Invalid installer receipt context'
212
- )
213
- assert(
214
- entry &&
215
- entry.platform === platform &&
216
- entry.schema === 2 &&
217
- entry.installed === true &&
218
- entry.launched === true &&
219
- entry.rendererReady === true &&
220
- (['tag', 'sourceSha', 'workflowSha', 'runId', 'runAttempt'] as const).every(
221
- (key) => entry[key] === identity[key]
222
- ),
223
- 'Installer identity mismatch'
224
- )
225
- checkRenderer(entry.rendererEvidence, offlinePolicy)
226
- assert(
227
- Array.isArray(entry.assets) && names.length > 0 && entry.assets.length === names.length,
228
- 'Incorrect installer asset count'
229
- )
230
- for (const name of names)
231
- assert(
232
- matches(uniqueAsset(entry.assets, name), uniqueAsset(assets, name)),
233
- `Installer asset mismatch: ${name}`
234
- )
235
- return true
236
- }
237
- function assertIdentity(identity: ReleaseIdentity, platform: string) {
238
- assert(
239
- /^v\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(identity.tag) &&
240
- /^[a-f0-9]{40}$/.test(identity.sourceSha) &&
241
- /^[a-f0-9]{40}$/.test(identity.workflowSha) &&
242
- /^[1-9]\d{0,19}$/.test(identity.runId) &&
243
- Number.isSafeInteger(identity.runAttempt) &&
244
- identity.runAttempt > 0 &&
245
- /^[a-z0-9-]+$/.test(platform),
246
- 'Invalid receipt context'
247
- )
248
- }
249
- /** Validate one command artifact receipt against the exact attempt and payload bytes. */
250
- export function validateCommandReceipt(
251
- identity: ReleaseIdentity,
252
- entry: CommandReceipt,
253
- kind: string,
254
- platform: string,
255
- name: string,
256
- assets: Artifact[]
257
- ): true {
258
- assertIdentity(identity, platform)
259
- assert(
260
- entry &&
261
- entry.schema === 1 &&
262
- entry.kind === kind &&
263
- entry.platform === platform &&
264
- entry.installed === true &&
265
- entry.versionMatched === true &&
266
- entry.probesPassed === true &&
267
- entry.serviceStarted === true &&
268
- entry.serviceStopped === (platform === 'windows-x64' ? 'process-tree' : 'sigterm') &&
269
- Object.keys(entry).length === 14 &&
270
- (['tag', 'sourceSha', 'workflowSha', 'runId', 'runAttempt'] as const).every(
271
- (key) => entry[key] === identity[key]
272
- ),
273
- 'Command artifact receipt mismatch'
274
- )
275
- assert(
276
- matches(entry.asset, uniqueAsset(assets, name)),
277
- `Command artifact asset mismatch: ${name}`
278
- )
279
- return true
280
- }
281
- /** Validate that every required command artifact has exactly one receipt for its bytes. */
282
- export function validateCommandReceipts(
283
- identity: ReleaseIdentity,
284
- receipts: CommandReceipt[] | undefined,
285
- requirements: Requirements,
286
- assets: Artifact[]
287
- ): void {
288
- const required = Object.entries(requirements.commandArtifacts ?? {}).flatMap(
289
- ([kind, byPlatform]) =>
290
- Object.entries(byPlatform).map(([platform, name]) => ({ kind, platform, name }))
291
- )
292
- if (!required.length) {
293
- assert(receipts === undefined, 'Unexpected command artifact receipts')
294
- return
295
- }
296
- assert(
297
- Array.isArray(receipts) && receipts.length === required.length,
298
- 'Missing or duplicate command artifact receipts'
299
- )
300
- for (const { kind, platform, name } of required) {
301
- const entries = receipts.filter((entry) => entry?.kind === kind && entry.platform === platform)
302
- assert(entries.length === 1, `Missing or duplicate command artifact receipt: ${kind}`)
303
- validateCommandReceipt(identity, entries[0]!, kind, platform, name, assets)
304
- }
305
- }
306
- export function validateReleaseQualification(
307
- release: Release,
308
- receipt: Qualification,
309
- sourceSha: string,
310
- requirements: Requirements
311
- ): true {
312
- const required = expectedAssets(requirements)
313
- const platforms = Object.keys(requirements.platforms)
314
- assert(
315
- release.draft === false &&
316
- receipt.schema === 2 &&
317
- receipt.tag === release.tag_name &&
318
- receipt.sourceSha === sourceSha &&
319
- /^[a-f0-9]{40}$/.test(sourceSha) &&
320
- /^[a-f0-9]{40}$/.test(receipt.workflowSha) &&
321
- /^[1-9]\d*$/.test(receipt.runId) &&
322
- Number.isSafeInteger(receipt.runAttempt) &&
323
- receipt.runAttempt > 0,
324
- 'Qualification identity mismatch'
325
- )
326
- assert(
327
- receipt.platforms.length === platforms.length &&
328
- receipt.installerTests.length === platforms.length &&
329
- receipt.installerReceipts.length === platforms.length &&
330
- platforms.every(
331
- (platform) =>
332
- receipt.platforms.filter((x) => x === platform).length === 1 &&
333
- receipt.installerTests.filter((x) => x === platform).length === 1
334
- ),
335
- 'Missing or duplicate platform tests'
336
- )
337
- for (const platform of platforms) {
338
- const entries = receipt.installerReceipts.filter((entry) => entry.platform === platform)
339
- assert(entries.length === 1, `Missing or duplicate installer receipt: ${platform}`)
340
- validateInstallerReceipt(
341
- receipt,
342
- entries[0]!,
343
- platform,
344
- requirements.platforms[platform]!,
345
- release.assets,
346
- requirements.offlinePolicy
347
- )
348
- }
349
- validateCommandReceipts(receipt, receipt.commandReceipts, requirements, release.assets)
350
- assert(receipt.assets.length === required.length, 'Incorrect qualification asset count')
351
- for (const name of required)
352
- assert(
353
- matches(uniqueAsset(receipt.assets, name), uniqueAsset(release.assets, name)),
354
- `Qualification asset mismatch: ${name}`
355
- )
356
- return true
357
- }
358
- export function validateQualificationRun(
359
- run: {
360
- id: number
361
- run_attempt: number
362
- conclusion: string
363
- path: string
364
- repository: { full_name: string }
365
- head_sha: string
366
- event: string
367
- },
368
- jobs: { name: string; conclusion: string }[],
369
- receipt: Qualification,
370
- repository: string,
371
- requirements: Requirements,
372
- assetsWorkflow: string
373
- ): true {
374
- expectedAssets(requirements)
375
- assert(
376
- String(run.id) === receipt.runId &&
377
- run.run_attempt === receipt.runAttempt &&
378
- run.conclusion === 'success' &&
379
- run.path === assetsWorkflow &&
380
- run.repository.full_name === repository &&
381
- run.head_sha === receipt.workflowSha &&
382
- ['release', 'workflow_dispatch'].includes(run.event),
383
- 'Qualification run identity mismatch'
384
- )
385
- for (const platform of Object.keys(requirements.platforms)) {
386
- // Called through the reusable assets workflow, GitHub prefixes each job with the
387
- // caller's job id ("assets / Installer / macos-arm64").
388
- const platformJobs = jobs.filter((job) =>
389
- new RegExp(`^(?:[A-Za-z0-9_-]+ / )?Installer / ${platform}$`).test(job.name)
390
- )
391
- assert(
392
- platformJobs.length === 1 && platformJobs[0]!.conclusion === 'success',
393
- `Missing successful installer job: ${platform}`
394
- )
395
- }
396
- return true
397
- }
@@ -1,87 +0,0 @@
1
- import { createHash } from 'node:crypto'
2
- import { lstat, open, rm } from 'node:fs/promises'
3
- import { join, resolve } from 'node:path'
4
- import { parseReleaseConfig, platformPayloads } from './release-config'
5
- import type { Artifact } from './release-qualification'
6
-
7
- /** Stage the platform's configured payloads from the build without replacing existing bytes. */
8
- export async function stagePlatformArtifacts(options: {
9
- config: unknown
10
- tag: string
11
- platform: string
12
- directory: string
13
- sources: Record<string, string>
14
- }): Promise<Artifact[]> {
15
- const requirements = parseReleaseConfig(options.config).requirements(options.tag)
16
- const expected = platformPayloads(requirements, options.platform)
17
- if (
18
- !expected.length ||
19
- Object.keys(options.sources).length !== expected.length ||
20
- expected.some((name) => !Object.hasOwn(options.sources, name))
21
- )
22
- throw new Error('Platform staging sources do not match release configuration')
23
- const directory = resolve(options.directory)
24
- const created: string[] = []
25
- try {
26
- const artifacts: Artifact[] = []
27
- for (const name of expected) {
28
- const sourcePath = options.sources[name]
29
- if (typeof sourcePath !== 'string' || !sourcePath) throw new Error('Invalid staging source')
30
- const sourceInfo = await lstat(sourcePath)
31
- if (
32
- !sourceInfo.isFile() ||
33
- sourceInfo.isSymbolicLink() ||
34
- !Number.isSafeInteger(sourceInfo.size) ||
35
- sourceInfo.size < 1
36
- )
37
- throw new Error('Invalid staging source')
38
- const input = await open(sourcePath, 'r')
39
- try {
40
- const before = await input.stat()
41
- if (
42
- !before.isFile() ||
43
- before.dev !== sourceInfo.dev ||
44
- before.ino !== sourceInfo.ino ||
45
- before.size !== sourceInfo.size
46
- )
47
- throw new Error('Staging source changed')
48
- const target = join(directory, name)
49
- const output = await open(target, 'wx')
50
- created.push(target)
51
- const hash = createHash('sha256')
52
- let size = 0
53
- try {
54
- for await (const chunk of input.createReadStream({ autoClose: false })) {
55
- size += chunk.length
56
- if (size > before.size) throw new Error('Staging source changed')
57
- hash.update(chunk)
58
- let offset = 0
59
- while (offset < chunk.length) {
60
- const { bytesWritten } = await output.write(chunk, offset, chunk.length - offset)
61
- if (!bytesWritten) throw new Error('Unable to stage artifact')
62
- offset += bytesWritten
63
- }
64
- }
65
- } finally {
66
- await output.close()
67
- }
68
- const after = await input.stat()
69
- if (
70
- size !== before.size ||
71
- after.size !== before.size ||
72
- after.mtimeMs !== before.mtimeMs ||
73
- after.dev !== before.dev ||
74
- after.ino !== before.ino
75
- )
76
- throw new Error('Staging source changed')
77
- artifacts.push({ name, size, digest: 'sha256:' + hash.digest('hex') })
78
- } finally {
79
- await input.close()
80
- }
81
- }
82
- return artifacts
83
- } catch (error) {
84
- await Promise.all(created.map((path) => rm(path, { force: true })))
85
- throw error
86
- }
87
- }
@@ -1,173 +0,0 @@
1
- /**
2
- * The per-platform steps the reusable release-assets workflow runs in an app's
3
- * directory (`bun run release:<step> <platform> [directory]`, with
4
- * `RELEASE_TAG`), so an app maps its scripts to `release-step-cli.js` instead
5
- * of keeping its own copies. Each reads `release-config.json` from the app
6
- * directory; an app's own tests keep that file in step with its app identity.
7
- */
8
- import { appendFile, mkdir, mkdtemp, readdir, rm } from 'node:fs/promises'
9
- import { tmpdir } from 'node:os'
10
- import { join } from 'node:path'
11
- import { packCommandArtifact, readCommandArtifact } from '../installer/command-artifact'
12
- import { qualifyCommandArtifactsCommand } from '../installer/command-qualification-command'
13
- import { verifyInstallerPayload } from '../installer/installer-identity'
14
- import { assertPortableAppName, type InstallerPlatform } from '../installer/installer-layout'
15
- import { qualifyInstallerCommand } from '../installer/installer-qualification-command'
16
- import { qualifyUpgradeCommand } from '../installer/installer-upgrade-command'
17
- import { parseReleaseConfig, platformPayloads } from './release-config'
18
- import { stagePlatformArtifacts } from './release-staging'
19
- import { selectRetainedReleaseBuild } from './retained-release-build'
20
-
21
- const PLATFORMS: readonly InstallerPlatform[] = ['macos-arm64', 'windows-x64', 'linux-x64']
22
-
23
- export type ReleaseStepContext = {
24
- env: Record<string, string | undefined>
25
- /** The parsed `release-config.json`. */
26
- config: { appName: string } & Record<string, unknown>
27
- tag: string
28
- platform: InstallerPlatform
29
- }
30
-
31
- export function releasePlatform(value: string | undefined): InstallerPlatform {
32
- if (!value || !PLATFORMS.includes(value as InstallerPlatform))
33
- throw new Error('Expected a release platform')
34
- return value as InstallerPlatform
35
- }
36
-
37
- function platformAssets(context: ReleaseStepContext): [string, string] {
38
- const assets = parseReleaseConfig(context.config).requirements(context.tag).platforms[
39
- context.platform
40
- ]
41
- if (!assets || assets.length !== 2) throw new Error('Expected one installer and one archive')
42
- return [assets[0]!, assets[1]!]
43
- }
44
-
45
- function renderer(env: Record<string, string | undefined>) {
46
- const value = env.ADEA_APP_RENDERER
47
- if (value !== 'native' && value !== 'cef')
48
- throw new Error('ADEA_APP_RENDERER must be native or cef')
49
- return value
50
- }
51
-
52
- /** Reuse this tag's payload from an earlier trusted attempt; writes `reuse`, `artifactId` and `runId` to `GITHUB_OUTPUT`. */
53
- export async function selectRetainedStep(context: ReleaseStepContext): Promise<void> {
54
- const output = context.env.GITHUB_OUTPUT
55
- if (!output) throw new Error('Expected GITHUB_OUTPUT')
56
- const result = await selectRetainedReleaseBuild(context)
57
- await appendFile(
58
- output,
59
- result.reuse
60
- ? `reuse=true\nartifactId=${result.artifactId}\nrunId=${result.runId}\n`
61
- : 'reuse=false\n'
62
- )
63
- }
64
-
65
- /** The installer and update archive a stable Electrobun build leaves in `artifacts`. */
66
- export function electrobunArtifacts(
67
- appName: string,
68
- platform: InstallerPlatform
69
- ): [installer: string, archive: string] {
70
- assertPortableAppName(appName)
71
- const bundle = appName.replaceAll(' ', '')
72
- return {
73
- 'macos-arm64': [`macos-arm64-${bundle}.dmg`, `stable-macos-arm64-${bundle}.app.tar.zst`],
74
- 'windows-x64': [`win-x64-${bundle}-Setup.zip`, `stable-win-x64-${bundle}.tar.zst`],
75
- 'linux-x64': [`linux-x64-${bundle}-Setup.tar.gz`, `stable-linux-x64-${bundle}.tar.zst`],
76
- }[platform] as [string, string]
77
- }
78
-
79
- /**
80
- * Copy the freshly built installer and archive into `directory` under their release asset names,
81
- * and pack each command artifact's built directory into its release archive beside them.
82
- */
83
- export async function stageBuildStep(
84
- context: ReleaseStepContext,
85
- directory: string,
86
- artifacts = 'artifacts'
87
- ) {
88
- const [installerAsset, archiveAsset] = platformAssets(context)
89
- const [installer, archive] = electrobunArtifacts(context.config.appName, context.platform)
90
- const parsed = parseReleaseConfig(context.config)
91
- const requirements = parsed.requirements(context.tag)
92
- await mkdir(directory, { recursive: true })
93
- const packed = await mkdtemp(join(tmpdir(), 'framework-command-pack-'))
94
- try {
95
- const sources: Record<string, string> = {
96
- [installerAsset]: join(artifacts, installer),
97
- [archiveAsset]: join(artifacts, archive),
98
- }
99
- for (const policy of parsed.commandArtifacts) {
100
- const name = requirements.commandArtifacts![policy.kind]![context.platform]!
101
- sources[name] = join(packed, name)
102
- await packCommandArtifact({
103
- source: policy.build,
104
- archive: sources[name],
105
- executable: policy.executable,
106
- platform: context.platform,
107
- })
108
- }
109
- return await stagePlatformArtifacts({ ...context, directory, sources })
110
- } finally {
111
- await rm(packed, { recursive: true, force: true })
112
- }
113
- }
114
-
115
- /**
116
- * Check a staged payload before its installer runs: exactly the configured assets, an installer
117
- * that embeds the staged archive, and command artifacts with only safe entries and a launcher.
118
- */
119
- export async function inspectStagedStep(context: ReleaseStepContext, directory: string) {
120
- const parsed = parseReleaseConfig(context.config)
121
- const requirements = parsed.requirements(context.tag)
122
- const assets = platformPayloads(requirements, context.platform)
123
- const entries = await readdir(directory, { withFileTypes: true })
124
- if (
125
- entries.length !== assets.length ||
126
- entries.some((entry) => !entry.isFile() || !assets.includes(entry.name))
127
- )
128
- throw new Error('Staged platform directory contains unexpected files')
129
- const [installer, archive] = platformAssets(context).map((name) => join(directory, name)) as [
130
- string,
131
- string,
132
- ]
133
- for (const policy of parsed.commandArtifacts)
134
- await readCommandArtifact({
135
- archive: join(directory, requirements.commandArtifacts![policy.kind]![context.platform]!),
136
- executable: policy.executable,
137
- platform: context.platform,
138
- })
139
- return {
140
- archive,
141
- identity: await verifyInstallerPayload({
142
- platform: context.platform,
143
- appName: context.config.appName,
144
- installer,
145
- archive,
146
- env: context.env,
147
- }),
148
- }
149
- }
150
-
151
- /**
152
- * Run each staged command artifact from a clean location and stage its receipt, then run the
153
- * staged installer, observe the installed app and stage the installer receipt.
154
- */
155
- export async function qualifyStep(context: ReleaseStepContext, directory: string): Promise<void> {
156
- const mode = renderer(context.env)
157
- await qualifyCommandArtifactsCommand({ ...context, directory })
158
- await qualifyInstallerCommand({ ...context, renderer: mode, directory })
159
- }
160
-
161
- /** Install the newest earlier release, apply this release's update and observe the new version. */
162
- export function qualifyUpgradeStep(
163
- context: ReleaseStepContext,
164
- directory: string,
165
- onStage?: (stage: string) => void
166
- ) {
167
- return qualifyUpgradeCommand({
168
- ...context,
169
- renderer: renderer(context.env),
170
- directory,
171
- ...(onStage ? { onStage } : {}),
172
- })
173
- }