@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.
- package/README.md +49 -1
- package/dist/cli/macos-signing-cli.d.ts +2 -0
- package/dist/cli/macos-signing-cli.js +14 -0
- package/dist/desktop/channel-proof.js +7 -1
- package/dist/framework-source.json +1 -1
- package/dist/release/framework-package-publish.js +4 -2
- package/dist/release/local-release.d.ts +2 -0
- package/dist/release/local-release.js +25 -2
- package/dist/release/macos-signing.d.ts +27 -0
- package/dist/release/macos-signing.js +101 -0
- package/dist/shell/app-shell.js +21 -33
- package/dist/shell/navigation-drawer.d.ts +12 -0
- package/dist/shell/navigation-drawer.js +42 -0
- package/dist/updates/release-feed.d.ts +2 -0
- package/dist/updates/release-feed.js +11 -2
- package/package.json +16 -4
- package/src/shell/app-shell.tsx +29 -20
- package/src/shell/navigation-drawer.tsx +36 -0
- package/src/app/create-application.ts +0 -245
- package/src/app/service-registry.ts +0 -124
- package/src/ci/toolchain-identity.ts +0 -244
- package/src/cli/cef-helper-cli.ts +0 -21
- package/src/cli/cli-runner.ts +0 -29
- package/src/cli/create-application-cli.ts +0 -62
- package/src/cli/electrobun-shortcut-patch-cli.ts +0 -24
- package/src/cli/framework-update-cli.ts +0 -41
- package/src/cli/release-assets-plan-cli.ts +0 -14
- package/src/cli/release-cut-cli.ts +0 -41
- package/src/cli/release-descriptor-staging-cli.ts +0 -57
- package/src/cli/release-finalize-cli.ts +0 -34
- package/src/cli/release-promote-cli.ts +0 -31
- package/src/cli/release-publish-cli.ts +0 -46
- package/src/cli/release-sign-cli.ts +0 -24
- package/src/cli/release-step-cli.ts +0 -71
- package/src/cli/toolchain-identity-cli.ts +0 -12
- package/src/cli/update-helper-cli.ts +0 -12
- package/src/cli/windows-runtime-patch-cli.ts +0 -17
- package/src/desktop/application-command-client.ts +0 -43
- package/src/desktop/channel-handshake.ts +0 -136
- package/src/desktop/channel-proof.ts +0 -122
- package/src/desktop/desktop-client.ts +0 -303
- package/src/desktop/desktop-gateway.ts +0 -189
- package/src/desktop/desktop-host.ts +0 -335
- package/src/desktop/desktop-stream.ts +0 -324
- package/src/desktop/loopback-policy.ts +0 -41
- package/src/desktop/open-url-channel.ts +0 -79
- package/src/desktop/string-policy.ts +0 -9
- package/src/installer/archive-entry.ts +0 -32
- package/src/installer/command-artifact.ts +0 -307
- package/src/installer/command-qualification-command.ts +0 -75
- package/src/installer/hosted-runner.ts +0 -11
- package/src/installer/installed-payload.ts +0 -408
- package/src/installer/installer-ci-bootstrap.ts +0 -199
- package/src/installer/installer-ci-preflight.ts +0 -61
- package/src/installer/installer-ci-worker.ts +0 -105
- package/src/installer/installer-extraction.ts +0 -367
- package/src/installer/installer-fetch-guard.ts +0 -75
- package/src/installer/installer-identity.ts +0 -331
- package/src/installer/installer-layout.ts +0 -167
- package/src/installer/installer-observation.ts +0 -671
- package/src/installer/installer-process-cleanup.ts +0 -167
- package/src/installer/installer-qualification-command.ts +0 -81
- package/src/installer/installer-renderer-evidence.ts +0 -268
- package/src/installer/installer-upgrade-command.ts +0 -226
- package/src/installer/installer-worker-guard.ts +0 -112
- package/src/installer/native-executable.ts +0 -37
- package/src/installer/upgrade-asset-download.ts +0 -72
- package/src/installer/write-all.ts +0 -19
- package/src/native/app-bundle.ts +0 -86
- package/src/native/cef-helper.ts +0 -471
- package/src/native/desktop-build-hook.ts +0 -21
- package/src/native/electrobun-source-patch.ts +0 -107
- package/src/native/linux-cef-links.ts +0 -14
- package/src/native/native-secret-store.ts +0 -99
- package/src/native/native-utilities.ts +0 -166
- package/src/native/partitioned-window.ts +0 -62
- package/src/native/secure-window.ts +0 -115
- package/src/native/sidecar-services.ts +0 -71
- package/src/native/sidecar.ts +0 -387
- package/src/native/window-bootstrap.ts +0 -77
- package/src/native/windows-build-hook-internal.ts +0 -49
- package/src/native/windows-build-hook.ts +0 -12
- package/src/native/windows-runtime-patch-internal.ts +0 -48
- package/src/native/windows-runtime-patch.ts +0 -15
- package/src/release/feed-release-cut.ts +0 -110
- package/src/release/feed-state.ts +0 -135
- package/src/release/framework-package-publish.ts +0 -163
- package/src/release/framework-update.ts +0 -196
- package/src/release/github-cli.ts +0 -27
- package/src/release/github-release-assets.ts +0 -36
- package/src/release/github-release-cut.ts +0 -237
- package/src/release/github-release-lookup.ts +0 -39
- package/src/release/github-release-promotion.ts +0 -112
- package/src/release/github-release-provenance.ts +0 -65
- package/src/release/github-release-publisher.ts +0 -90
- package/src/release/github-release-qualification.ts +0 -144
- package/src/release/local-provenance.ts +0 -92
- package/src/release/local-release.ts +0 -525
- package/src/release/macos-dmg.ts +0 -113
- package/src/release/release-artifact.ts +0 -53
- package/src/release/release-assets-plan.ts +0 -118
- package/src/release/release-config.ts +0 -420
- package/src/release/release-cut-command.ts +0 -80
- package/src/release/release-cut.ts +0 -133
- package/src/release/release-descriptor-staging.ts +0 -242
- package/src/release/release-finalize.ts +0 -191
- package/src/release/release-promotion-command.ts +0 -36
- package/src/release/release-promotion.ts +0 -132
- package/src/release/release-publication.ts +0 -213
- package/src/release/release-publish-command.ts +0 -163
- package/src/release/release-qualification.ts +0 -397
- package/src/release/release-staging.ts +0 -87
- package/src/release/release-steps.ts +0 -173
- package/src/release/retained-release-build.ts +0 -217
- package/src/shell/application-menu-commands.ts +0 -6
- package/src/shell/application-menu.ts +0 -250
- package/src/updates/channel-update-manager.ts +0 -127
- package/src/updates/desktop-updater.ts +0 -440
- package/src/updates/release-feed.ts +0 -187
- package/src/updates/release-location.ts +0 -101
- package/src/updates/signed-release.ts +0 -311
- package/src/updates/stable-file.ts +0 -32
- package/src/updates/update-arm.ts +0 -107
- package/src/updates/update-channel-store.ts +0 -86
- package/src/updates/update-discovery.ts +0 -113
- package/src/updates/update-download.ts +0 -82
- package/src/updates/update-exclusive-rename.ts +0 -58
- package/src/updates/update-extraction.ts +0 -261
- package/src/updates/update-handoff-plan.ts +0 -75
- package/src/updates/update-helper.ts +0 -87
- package/src/updates/update-launch.ts +0 -33
- package/src/updates/update-manager.ts +0 -130
- package/src/updates/update-process-fence.ts +0 -125
- package/src/updates/update-resume.ts +0 -34
- package/src/updates/update-shutdown.ts +0 -37
- package/src/updates/update-swap-stage.ts +0 -75
- package/src/updates/update-swap.ts +0 -30
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import { createHash, createPublicKey, type KeyObject } from 'node:crypto'
|
|
2
|
-
import { lstat, open, readFile, writeFile } from 'node:fs/promises'
|
|
3
|
-
import { join, resolve } from 'node:path'
|
|
4
|
-
import { planReleaseAssets } from './release-assets-plan'
|
|
5
|
-
import { commandReceiptName } from '../installer/command-qualification-command'
|
|
6
|
-
import {
|
|
7
|
-
discoveryPolicies,
|
|
8
|
-
parseReleaseConfig,
|
|
9
|
-
platformPayloads,
|
|
10
|
-
platformTargets,
|
|
11
|
-
type DiscoveryPolicy,
|
|
12
|
-
type ReleasePlatform,
|
|
13
|
-
} from './release-config'
|
|
14
|
-
import {
|
|
15
|
-
validateCommandReceipts,
|
|
16
|
-
validateInstallerReceipt,
|
|
17
|
-
type Artifact,
|
|
18
|
-
type CommandReceipt,
|
|
19
|
-
type InstallerReceipt,
|
|
20
|
-
type ReleaseIdentity,
|
|
21
|
-
} from './release-qualification'
|
|
22
|
-
import { feedUrl } from '../updates/release-feed'
|
|
23
|
-
import {
|
|
24
|
-
signReleaseDescriptor,
|
|
25
|
-
verifyReleaseDescriptor,
|
|
26
|
-
type ReleaseDescriptor,
|
|
27
|
-
} from '../updates/signed-release'
|
|
28
|
-
|
|
29
|
-
const object = (value: unknown): value is Record<string, unknown> =>
|
|
30
|
-
typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
31
|
-
async function staged(path: string, name: string): Promise<Artifact> {
|
|
32
|
-
const info = await lstat(path)
|
|
33
|
-
if (!info.isFile() || info.isSymbolicLink() || !Number.isSafeInteger(info.size) || info.size < 1)
|
|
34
|
-
throw new Error('Invalid staged payload')
|
|
35
|
-
const file = await open(path, 'r')
|
|
36
|
-
try {
|
|
37
|
-
const before = await file.stat()
|
|
38
|
-
if (before.dev !== info.dev || before.ino !== info.ino || before.size !== info.size)
|
|
39
|
-
throw new Error('Staged payload changed')
|
|
40
|
-
const hash = createHash('sha256')
|
|
41
|
-
let size = 0
|
|
42
|
-
for await (const chunk of file.createReadStream({ autoClose: false })) {
|
|
43
|
-
size += chunk.length
|
|
44
|
-
if (size > before.size) throw new Error('Staged payload changed')
|
|
45
|
-
hash.update(chunk)
|
|
46
|
-
}
|
|
47
|
-
const after = await file.stat()
|
|
48
|
-
if (
|
|
49
|
-
size !== before.size ||
|
|
50
|
-
after.size !== before.size ||
|
|
51
|
-
after.mtimeMs !== before.mtimeMs ||
|
|
52
|
-
after.dev !== before.dev ||
|
|
53
|
-
after.ino !== before.ino
|
|
54
|
-
)
|
|
55
|
-
throw new Error('Staged payload changed')
|
|
56
|
-
return { name, size, digest: 'sha256:' + hash.digest('hex') }
|
|
57
|
-
} finally {
|
|
58
|
-
await file.close()
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/** Sign and self-verify one descriptor per discovery policy, each naming its staged payload. */
|
|
62
|
-
export function signDiscoveryDescriptors(options: {
|
|
63
|
-
policies: readonly DiscoveryPolicy[]
|
|
64
|
-
assets: readonly Artifact[]
|
|
65
|
-
identity: ReleaseIdentity
|
|
66
|
-
repository: string
|
|
67
|
-
feed: string
|
|
68
|
-
keyId: string
|
|
69
|
-
publicKey: string
|
|
70
|
-
privateKey: KeyObject
|
|
71
|
-
}): { name: string; bytes: string }[] {
|
|
72
|
-
const { identity, repository, feed, keyId, privateKey } = options
|
|
73
|
-
return options.policies.map((policy) => {
|
|
74
|
-
const payload = options.assets.find((value) => value.name === policy.payload)
|
|
75
|
-
if (!payload) throw new Error('Missing staged payload')
|
|
76
|
-
const descriptor: ReleaseDescriptor = {
|
|
77
|
-
schema: 2,
|
|
78
|
-
appId: policy.appId,
|
|
79
|
-
repository,
|
|
80
|
-
channel: policy.channel,
|
|
81
|
-
...identity,
|
|
82
|
-
version: identity.tag.slice(1),
|
|
83
|
-
platform: policy.os,
|
|
84
|
-
arch: policy.arch,
|
|
85
|
-
keyId,
|
|
86
|
-
asset: {
|
|
87
|
-
name: payload.name,
|
|
88
|
-
url: `${feed}${identity.tag}/${payload.name}`,
|
|
89
|
-
size: payload.size,
|
|
90
|
-
sha256: payload.digest.slice(7),
|
|
91
|
-
},
|
|
92
|
-
}
|
|
93
|
-
const value = signReleaseDescriptor(descriptor, privateKey)
|
|
94
|
-
if (
|
|
95
|
-
!verifyReleaseDescriptor(value, {
|
|
96
|
-
appId: policy.appId,
|
|
97
|
-
repository,
|
|
98
|
-
channel: policy.channel,
|
|
99
|
-
platform: policy.os,
|
|
100
|
-
arch: policy.arch,
|
|
101
|
-
feed,
|
|
102
|
-
keys: new Map([[keyId, options.publicKey]]),
|
|
103
|
-
}).ok
|
|
104
|
-
)
|
|
105
|
-
throw new Error('Descriptor verification failed')
|
|
106
|
-
return { name: policy.name, bytes: JSON.stringify(value) + '\n' }
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** Write descriptors beside the payloads, refusing to replace any existing file. */
|
|
111
|
-
export async function writeDescriptors(
|
|
112
|
-
directory: string,
|
|
113
|
-
signed: readonly { name: string; bytes: string }[]
|
|
114
|
-
): Promise<void> {
|
|
115
|
-
for (const value of signed) {
|
|
116
|
-
try {
|
|
117
|
-
await lstat(join(directory, value.name))
|
|
118
|
-
throw new Error('Descriptor already exists')
|
|
119
|
-
} catch (error) {
|
|
120
|
-
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
for (const value of signed)
|
|
124
|
-
await writeFile(join(directory, value.name), value.bytes, { flag: 'wx', mode: 0o600 })
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** The configured public key for `keyId`, which must be the signing key's own. */
|
|
128
|
-
export function configuredSigningKey(
|
|
129
|
-
config: Record<string, unknown>,
|
|
130
|
-
keyId: string,
|
|
131
|
-
privateKey: KeyObject
|
|
132
|
-
): string {
|
|
133
|
-
if (
|
|
134
|
-
!object(config.releaseSigningKeys) ||
|
|
135
|
-
!/^[a-z0-9][a-z0-9._-]{0,63}$/.test(keyId) ||
|
|
136
|
-
privateKey.type !== 'private' ||
|
|
137
|
-
privateKey.asymmetricKeyType !== 'ed25519'
|
|
138
|
-
)
|
|
139
|
-
throw new Error('Invalid descriptor signing context')
|
|
140
|
-
const encoded = config.releaseSigningKeys[keyId]
|
|
141
|
-
const publicKey = createPublicKey(privateKey)
|
|
142
|
-
.export({ type: 'spki', format: 'der' })
|
|
143
|
-
.subarray(-32)
|
|
144
|
-
.toString('base64')
|
|
145
|
-
if (typeof encoded !== 'string' || encoded !== publicKey)
|
|
146
|
-
throw new Error('Signing key does not match configured trust')
|
|
147
|
-
return encoded
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
async function receipt(path: string): Promise<unknown> {
|
|
151
|
-
const info = await lstat(path)
|
|
152
|
-
if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > 262144)
|
|
153
|
-
throw new Error('Invalid receipt')
|
|
154
|
-
const bytes = await readFile(path)
|
|
155
|
-
if (bytes.length !== info.size) throw new Error('Receipt changed')
|
|
156
|
-
return JSON.parse(bytes.toString('utf8'))
|
|
157
|
-
}
|
|
158
|
-
/** Sign descriptors only for payloads verified by every installer and command artifact receipt. */
|
|
159
|
-
export async function stageReleaseDescriptors(options: {
|
|
160
|
-
env: Record<string, string | undefined>
|
|
161
|
-
config: unknown
|
|
162
|
-
directory: string
|
|
163
|
-
tag: string
|
|
164
|
-
keyId: string
|
|
165
|
-
privateKey: KeyObject
|
|
166
|
-
run?: (args: string[], input?: string) => Promise<string>
|
|
167
|
-
}): Promise<string[]> {
|
|
168
|
-
const { env, config, tag, keyId, privateKey } = options
|
|
169
|
-
const plan = await planReleaseAssets({ env, config, tag, run: options.run })
|
|
170
|
-
if (
|
|
171
|
-
env.SOURCE_SHA !== plan.sourceSha ||
|
|
172
|
-
!object(config) ||
|
|
173
|
-
typeof config.appId !== 'string' ||
|
|
174
|
-
!object(config.descriptors)
|
|
175
|
-
)
|
|
176
|
-
throw new Error('Invalid descriptor signing context')
|
|
177
|
-
const encoded = configuredSigningKey(config, keyId, privateKey)
|
|
178
|
-
const parsed = parseReleaseConfig(config),
|
|
179
|
-
requirements = parsed.requirements(tag),
|
|
180
|
-
feed = feedUrl(parsed.feed)
|
|
181
|
-
const policies = discoveryPolicies(config, tag)
|
|
182
|
-
const directory = resolve(options.directory),
|
|
183
|
-
platforms = Object.keys(platformTargets) as ReleasePlatform[]
|
|
184
|
-
if (
|
|
185
|
-
Object.keys(requirements.platforms).length !== platforms.length ||
|
|
186
|
-
platforms.some((platform) => requirements.platforms[platform]?.length !== 2)
|
|
187
|
-
)
|
|
188
|
-
throw new Error('Invalid platform payload policy')
|
|
189
|
-
const names = platforms.flatMap((platform) => platformPayloads(requirements, platform))
|
|
190
|
-
const assets = await Promise.all(names.map((name) => staged(join(directory, name), name)))
|
|
191
|
-
const identity = {
|
|
192
|
-
tag,
|
|
193
|
-
sourceSha: plan.sourceSha,
|
|
194
|
-
workflowSha: plan.workflowSha,
|
|
195
|
-
runId: env.GITHUB_RUN_ID!,
|
|
196
|
-
runAttempt: Number(env.GITHUB_RUN_ATTEMPT),
|
|
197
|
-
}
|
|
198
|
-
for (const platform of platforms)
|
|
199
|
-
validateInstallerReceipt(
|
|
200
|
-
identity,
|
|
201
|
-
(await receipt(join(directory, `installer-test-${platform}.json`))) as InstallerReceipt,
|
|
202
|
-
platform,
|
|
203
|
-
requirements.platforms[platform]!,
|
|
204
|
-
assets,
|
|
205
|
-
requirements.offlinePolicy
|
|
206
|
-
)
|
|
207
|
-
validateCommandReceipts(
|
|
208
|
-
identity,
|
|
209
|
-
requirements.commandArtifacts
|
|
210
|
-
? await Promise.all(
|
|
211
|
-
Object.keys(requirements.commandArtifacts).flatMap((kind) =>
|
|
212
|
-
platforms.map(
|
|
213
|
-
async (platform) =>
|
|
214
|
-
(await receipt(
|
|
215
|
-
join(directory, commandReceiptName(kind, platform))
|
|
216
|
-
)) as CommandReceipt
|
|
217
|
-
)
|
|
218
|
-
)
|
|
219
|
-
)
|
|
220
|
-
: undefined,
|
|
221
|
-
requirements,
|
|
222
|
-
assets
|
|
223
|
-
)
|
|
224
|
-
const signed = signDiscoveryDescriptors({
|
|
225
|
-
policies,
|
|
226
|
-
assets,
|
|
227
|
-
identity,
|
|
228
|
-
repository: env.GITHUB_REPOSITORY!,
|
|
229
|
-
feed,
|
|
230
|
-
keyId,
|
|
231
|
-
publicKey: encoded,
|
|
232
|
-
privateKey,
|
|
233
|
-
})
|
|
234
|
-
for (const asset of assets)
|
|
235
|
-
if (
|
|
236
|
-
JSON.stringify(await staged(join(directory, asset.name), asset.name)) !==
|
|
237
|
-
JSON.stringify(asset)
|
|
238
|
-
)
|
|
239
|
-
throw new Error('Staged payload changed before signing')
|
|
240
|
-
await writeDescriptors(directory, signed)
|
|
241
|
-
return signed.map((value) => value.name)
|
|
242
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { githubCli } from './github-cli'
|
|
2
|
-
import { createGitHubReleaseCutProvider } from './github-release-cut'
|
|
3
|
-
import { qualifyGitHubRelease } from './github-release-qualification'
|
|
4
|
-
import { parseReleaseConfig } from './release-config'
|
|
5
|
-
import { lookupRelease } from './github-release-lookup'
|
|
6
|
-
import { isRepositorySlug } from '../updates/signed-release'
|
|
7
|
-
|
|
8
|
-
/** Treat event payloads as hints; qualification independently checks the GitHub run. */
|
|
9
|
-
export function parseFinalizationEvent(
|
|
10
|
-
event: unknown,
|
|
11
|
-
repository: string,
|
|
12
|
-
eventName = 'workflow_run'
|
|
13
|
-
): { tag: string; runId: string; runAttempt: number } {
|
|
14
|
-
if (typeof event !== 'object' || event === null || Array.isArray(event))
|
|
15
|
-
throw new Error('Invalid workflow event')
|
|
16
|
-
if (eventName === 'workflow_dispatch') {
|
|
17
|
-
const inputs = (event as { inputs?: unknown }).inputs
|
|
18
|
-
if (typeof inputs !== 'object' || inputs === null || Array.isArray(inputs))
|
|
19
|
-
throw new Error('Invalid workflow event')
|
|
20
|
-
const value = inputs as { tag?: unknown; run_id?: unknown; run_attempt?: unknown }
|
|
21
|
-
if (
|
|
22
|
-
typeof value.tag !== 'string' ||
|
|
23
|
-
value.tag.length > 65 ||
|
|
24
|
-
!/^v(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(value.tag) ||
|
|
25
|
-
typeof value.run_id !== 'string' ||
|
|
26
|
-
!/^[1-9]\d{0,19}$/.test(value.run_id) ||
|
|
27
|
-
typeof value.run_attempt !== 'string' ||
|
|
28
|
-
!/^[1-9]\d{0,8}$/.test(value.run_attempt)
|
|
29
|
-
)
|
|
30
|
-
throw new Error('Invalid workflow event')
|
|
31
|
-
return { tag: value.tag, runId: value.run_id, runAttempt: Number(value.run_attempt) }
|
|
32
|
-
}
|
|
33
|
-
if (eventName !== 'workflow_run') throw new Error('Invalid workflow event')
|
|
34
|
-
const workflow = (event as { workflow_run?: unknown }).workflow_run
|
|
35
|
-
if (typeof workflow !== 'object' || workflow === null || Array.isArray(workflow))
|
|
36
|
-
throw new Error('Invalid workflow event')
|
|
37
|
-
const value = workflow as {
|
|
38
|
-
id?: unknown
|
|
39
|
-
run_attempt?: unknown
|
|
40
|
-
event?: unknown
|
|
41
|
-
conclusion?: unknown
|
|
42
|
-
head_branch?: unknown
|
|
43
|
-
head_repository?: { full_name?: unknown }
|
|
44
|
-
display_title?: unknown
|
|
45
|
-
}
|
|
46
|
-
if (
|
|
47
|
-
!Number.isSafeInteger(value.id) ||
|
|
48
|
-
Number(value.id) < 1 ||
|
|
49
|
-
!Number.isSafeInteger(value.run_attempt) ||
|
|
50
|
-
Number(value.run_attempt) < 1 ||
|
|
51
|
-
value.event !== 'workflow_dispatch' ||
|
|
52
|
-
value.conclusion !== 'success' ||
|
|
53
|
-
value.head_branch !== 'main' ||
|
|
54
|
-
value.head_repository?.full_name !== repository ||
|
|
55
|
-
typeof value.display_title !== 'string' ||
|
|
56
|
-
!/^framework-release-assets:v(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(
|
|
57
|
-
value.display_title
|
|
58
|
-
)
|
|
59
|
-
)
|
|
60
|
-
throw new Error('Invalid workflow event')
|
|
61
|
-
return {
|
|
62
|
-
tag: value.display_title.slice('framework-release-assets:'.length),
|
|
63
|
-
runId: String(value.id),
|
|
64
|
-
runAttempt: Number(value.run_attempt),
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** Publish an opted-in Release Please draft only after its exact asset workflow completed. */
|
|
69
|
-
export async function finalizeReleasePleaseDraft(options: {
|
|
70
|
-
env: Record<string, string | undefined>
|
|
71
|
-
config: unknown
|
|
72
|
-
tag: string
|
|
73
|
-
runId: string
|
|
74
|
-
runAttempt: number
|
|
75
|
-
run?: (args: string[], input?: string) => Promise<string>
|
|
76
|
-
sleep?: (milliseconds: number) => Promise<unknown>
|
|
77
|
-
}): Promise<void> {
|
|
78
|
-
const { env, config, tag, runId, runAttempt } = options
|
|
79
|
-
const repository = env.GITHUB_REPOSITORY ?? ''
|
|
80
|
-
if (
|
|
81
|
-
env.GITHUB_ACTIONS !== 'true' ||
|
|
82
|
-
!['workflow_run', 'workflow_dispatch'].includes(env.GITHUB_EVENT_NAME ?? '') ||
|
|
83
|
-
env.GITHUB_REF !== 'refs/heads/main' ||
|
|
84
|
-
!isRepositorySlug(repository) ||
|
|
85
|
-
!/^[a-f0-9]{40}$/.test(env.GITHUB_SHA ?? '') ||
|
|
86
|
-
!/^[1-9]\d{0,19}$/.test(runId) ||
|
|
87
|
-
!Number.isSafeInteger(runAttempt) ||
|
|
88
|
-
runAttempt < 1 ||
|
|
89
|
-
!/^v(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(tag) ||
|
|
90
|
-
tag.length > 65
|
|
91
|
-
)
|
|
92
|
-
throw new Error('Invalid release finalization context')
|
|
93
|
-
const parsed = parseReleaseConfig(config)
|
|
94
|
-
if (
|
|
95
|
-
!parsed.releasePleaseManifestPath ||
|
|
96
|
-
typeof config !== 'object' ||
|
|
97
|
-
config === null ||
|
|
98
|
-
typeof (config as { appName?: unknown }).appName !== 'string'
|
|
99
|
-
)
|
|
100
|
-
throw new Error('Release Please finalization is not configured')
|
|
101
|
-
const run = options.run ?? githubCli()
|
|
102
|
-
const requirements = parsed.requirements(tag),
|
|
103
|
-
provider = createGitHubReleaseCutProvider({
|
|
104
|
-
repository,
|
|
105
|
-
appName: (config as { appName: string }).appName,
|
|
106
|
-
requirements: parsed.requirements,
|
|
107
|
-
assetsWorkflow: parsed.releaseWorkflows.assets,
|
|
108
|
-
releasePleaseManifestPath: parsed.releasePleaseManifestPath,
|
|
109
|
-
run,
|
|
110
|
-
})
|
|
111
|
-
const base = `repos/${repository}`
|
|
112
|
-
const read = async (path: string): Promise<unknown> => JSON.parse(await run(['api', path]))
|
|
113
|
-
const snapshot = await lookupRelease({ tag, base, read, includeDraft: true })
|
|
114
|
-
if (
|
|
115
|
-
!snapshot ||
|
|
116
|
-
!Number.isSafeInteger(snapshot.id) ||
|
|
117
|
-
Number(snapshot.id) < 1 ||
|
|
118
|
-
typeof snapshot.draft !== 'boolean' ||
|
|
119
|
-
typeof snapshot.body !== 'string' ||
|
|
120
|
-
typeof snapshot.prerelease !== 'boolean'
|
|
121
|
-
)
|
|
122
|
-
throw new Error('Release draft is not eligible')
|
|
123
|
-
const before = await provider.find(tag)
|
|
124
|
-
if (
|
|
125
|
-
!before ||
|
|
126
|
-
(before.draft ? !before.stageableDraft : !before.prerelease) ||
|
|
127
|
-
!(await provider.isMainAncestor(env.GITHUB_SHA!))
|
|
128
|
-
)
|
|
129
|
-
throw new Error('Release draft is not eligible')
|
|
130
|
-
const qualify = () =>
|
|
131
|
-
qualifyGitHubRelease({
|
|
132
|
-
repository,
|
|
133
|
-
tag,
|
|
134
|
-
requirements,
|
|
135
|
-
assetsWorkflow: parsed.releaseWorkflows.assets,
|
|
136
|
-
releasePleaseManifestPath: parsed.releasePleaseManifestPath,
|
|
137
|
-
allowDraft: true,
|
|
138
|
-
run,
|
|
139
|
-
})
|
|
140
|
-
// The assets run dispatches this workflow from its last job, so the run can still be
|
|
141
|
-
// finishing when this starts; qualification needs its final conclusion.
|
|
142
|
-
const attempt = `${base}/actions/runs/${runId}/attempts/${runAttempt}`
|
|
143
|
-
for (let check = 0; ; check++) {
|
|
144
|
-
const status = ((await read(attempt)) as { status?: unknown } | null)?.status
|
|
145
|
-
if (status === 'completed') break
|
|
146
|
-
if (check === 40) throw new Error('Release workflow attempt did not complete')
|
|
147
|
-
await (options.sleep ?? Bun.sleep)(15_000)
|
|
148
|
-
}
|
|
149
|
-
const receipt = await qualify()
|
|
150
|
-
if (
|
|
151
|
-
receipt.runId !== runId ||
|
|
152
|
-
receipt.runAttempt !== runAttempt ||
|
|
153
|
-
receipt.sourceSha !== before.sourceSha
|
|
154
|
-
)
|
|
155
|
-
throw new Error('Release workflow attempt mismatch')
|
|
156
|
-
if (!before.draft) return
|
|
157
|
-
const current = await provider.find(tag)
|
|
158
|
-
if (
|
|
159
|
-
!current ||
|
|
160
|
-
!current.draft ||
|
|
161
|
-
!current.stageableDraft ||
|
|
162
|
-
current.sourceSha !== before.sourceSha
|
|
163
|
-
)
|
|
164
|
-
throw new Error('Release draft changed')
|
|
165
|
-
const verified = await qualify()
|
|
166
|
-
if (JSON.stringify(verified) !== JSON.stringify(receipt))
|
|
167
|
-
throw new Error('Release qualification changed')
|
|
168
|
-
const selected = await lookupRelease({ tag, base, read, includeDraft: true })
|
|
169
|
-
if (
|
|
170
|
-
!selected ||
|
|
171
|
-
selected.id !== snapshot.id ||
|
|
172
|
-
selected.tag_name !== tag ||
|
|
173
|
-
selected.draft !== true ||
|
|
174
|
-
selected.body !== snapshot.body ||
|
|
175
|
-
selected.prerelease !== snapshot.prerelease
|
|
176
|
-
)
|
|
177
|
-
throw new Error('Release draft changed')
|
|
178
|
-
await run(
|
|
179
|
-
['api', `${base}/releases/${selected.id}`, '--method', 'PATCH', '--input', '-'],
|
|
180
|
-
JSON.stringify({ draft: false, prerelease: true, make_latest: 'false' })
|
|
181
|
-
)
|
|
182
|
-
const after = await provider.find(tag)
|
|
183
|
-
if (
|
|
184
|
-
!after ||
|
|
185
|
-
after.draft ||
|
|
186
|
-
!after.prerelease ||
|
|
187
|
-
after.sourceSha !== before.sourceSha ||
|
|
188
|
-
JSON.stringify(await qualify()) !== JSON.stringify(receipt)
|
|
189
|
-
)
|
|
190
|
-
throw new Error('Release publication could not be verified')
|
|
191
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { createGitHubPromotionProvider } from './github-release-promotion'
|
|
2
|
-
import { promoteDailyRelease } from './release-promotion'
|
|
3
|
-
import { parseReleaseConfig } from './release-config'
|
|
4
|
-
|
|
5
|
-
/** Execute promotion only from a trusted main-branch GitHub release job. */
|
|
6
|
-
export async function runPromotionCommand(options: {
|
|
7
|
-
env: Record<string, string | undefined>
|
|
8
|
-
config: unknown
|
|
9
|
-
now?: string
|
|
10
|
-
run?: (args: string[], input?: string) => Promise<string>
|
|
11
|
-
}) {
|
|
12
|
-
const { env, config } = options
|
|
13
|
-
if (
|
|
14
|
-
env.GITHUB_ACTIONS !== 'true' ||
|
|
15
|
-
env.GITHUB_REF !== 'refs/heads/main' ||
|
|
16
|
-
!['schedule', 'workflow_dispatch'].includes(env.GITHUB_EVENT_NAME ?? '') ||
|
|
17
|
-
!env.GITHUB_REPOSITORY ||
|
|
18
|
-
!['true', 'false', undefined].includes(env.STABLE_PROMOTION_HELD)
|
|
19
|
-
)
|
|
20
|
-
throw new Error('Promotion requires a trusted main release workflow')
|
|
21
|
-
const { requirements, soakHours, releasePleaseManifestPath, releaseWorkflows } =
|
|
22
|
-
parseReleaseConfig(config)
|
|
23
|
-
const provider = createGitHubPromotionProvider({
|
|
24
|
-
repository: env.GITHUB_REPOSITORY,
|
|
25
|
-
requirements,
|
|
26
|
-
assetsWorkflow: releaseWorkflows.assets,
|
|
27
|
-
releasePleaseManifestPath,
|
|
28
|
-
run: options.run,
|
|
29
|
-
})
|
|
30
|
-
return promoteDailyRelease({
|
|
31
|
-
now: options.now ?? new Date().toISOString(),
|
|
32
|
-
held: env.STABLE_PROMOTION_HELD === 'true',
|
|
33
|
-
soakHours,
|
|
34
|
-
provider,
|
|
35
|
-
})
|
|
36
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { versionLessThan } from '../updates/release-version'
|
|
2
|
-
|
|
3
|
-
/** Daily-to-stable policy adapted from adea-ai/adea scripts/release-policy.mjs,
|
|
4
|
-
* commit 6155d18941acbb14d9099bc2a33a50ee9683a068 (Apache-2.0). */
|
|
5
|
-
export type PromotionRelease = {
|
|
6
|
-
id: number
|
|
7
|
-
tag: string
|
|
8
|
-
body: string
|
|
9
|
-
draft: boolean
|
|
10
|
-
prerelease: boolean
|
|
11
|
-
publishedAt: string
|
|
12
|
-
}
|
|
13
|
-
export type PromotionProvider = {
|
|
14
|
-
list(): Promise<PromotionRelease[]>
|
|
15
|
-
/** Verify immutable installer receipts, payload digests and the exact successful workflow attempt. */
|
|
16
|
-
qualify(release: PromotionRelease): Promise<boolean>
|
|
17
|
-
/** Idempotently mark the already-qualified release stable and record the supplied time. */
|
|
18
|
-
markStable(release: PromotionRelease, at: string): Promise<void>
|
|
19
|
-
}
|
|
20
|
-
function order(a: PromotionRelease, b: PromotionRelease) {
|
|
21
|
-
return Date.parse(a.publishedAt) - Date.parse(b.publishedAt) || a.id - b.id
|
|
22
|
-
}
|
|
23
|
-
function stableTime(release: PromotionRelease): string | undefined {
|
|
24
|
-
const lines = release.body.split(/\r?\n/)
|
|
25
|
-
const markers = lines.filter((line) => line === `<!-- adea-stable:v1 ${release.tag} -->`)
|
|
26
|
-
if (!markers.length) return undefined
|
|
27
|
-
if (markers.length !== 1) throw new Error('Ambiguous stable marker')
|
|
28
|
-
const times = lines.filter((line) => /^<!-- adea-stable-time:[^ ]+ -->$/.test(line))
|
|
29
|
-
if (times.length > 1) throw new Error('Ambiguous stable timestamp')
|
|
30
|
-
const value =
|
|
31
|
-
times[0]?.slice('<!-- adea-stable-time:'.length, -' -->'.length) ?? release.publishedAt
|
|
32
|
-
if (!Number.isFinite(Date.parse(value))) throw new Error('Invalid stable timestamp')
|
|
33
|
-
return value
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const eligibleTag = (tag: string) =>
|
|
37
|
-
tag.length <= 65 && /^v(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(tag)
|
|
38
|
-
|
|
39
|
-
/** Promote only a successfully qualified daily after the configured batch soak. */
|
|
40
|
-
export async function promoteDailyRelease(options: {
|
|
41
|
-
now: string
|
|
42
|
-
held?: boolean
|
|
43
|
-
soakHours?: number
|
|
44
|
-
provider: PromotionProvider
|
|
45
|
-
}): Promise<{ status: 'held' | 'soaking' | 'unqualified' } | { status: 'stable'; tag: string }> {
|
|
46
|
-
if (options.held) return { status: 'held' }
|
|
47
|
-
const now = Date.parse(options.now)
|
|
48
|
-
const hours = options.soakHours ?? 96
|
|
49
|
-
if (!Number.isFinite(now) || !Number.isSafeInteger(hours) || hours < 0 || hours > 24 * 365)
|
|
50
|
-
throw new Error('Invalid promotion clock or soak')
|
|
51
|
-
const releases = await options.provider.list()
|
|
52
|
-
const ids = new Set<number>(),
|
|
53
|
-
tags = new Set<string>()
|
|
54
|
-
for (const release of releases) {
|
|
55
|
-
if (
|
|
56
|
-
!Number.isSafeInteger(release.id) ||
|
|
57
|
-
release.id < 1 ||
|
|
58
|
-
ids.has(release.id) ||
|
|
59
|
-
typeof release.tag !== 'string' ||
|
|
60
|
-
tags.has(release.tag) ||
|
|
61
|
-
!Number.isFinite(Date.parse(release.publishedAt))
|
|
62
|
-
)
|
|
63
|
-
throw new Error('Invalid release listing')
|
|
64
|
-
ids.add(release.id)
|
|
65
|
-
tags.add(release.tag)
|
|
66
|
-
}
|
|
67
|
-
const compareVersion = (a: PromotionRelease, b: PromotionRelease) =>
|
|
68
|
-
versionLessThan(a.tag, b.tag) ? -1 : versionLessThan(b.tag, a.tag) ? 1 : order(a, b)
|
|
69
|
-
const dailies = releases
|
|
70
|
-
.filter(
|
|
71
|
-
(release) =>
|
|
72
|
-
!release.draft &&
|
|
73
|
-
Date.parse(release.publishedAt) <= now &&
|
|
74
|
-
eligibleTag(release.tag) &&
|
|
75
|
-
!release.body
|
|
76
|
-
.split(/\r?\n/)
|
|
77
|
-
.some((line) => line.startsWith('adea-channel:') || line.startsWith('Source: '))
|
|
78
|
-
)
|
|
79
|
-
// The filter creates a new array; keep ES2022 runtime compatibility.
|
|
80
|
-
// oxlint-disable-next-line unicorn/no-array-sort
|
|
81
|
-
.sort(order)
|
|
82
|
-
const stableReleases = dailies.filter(
|
|
83
|
-
(release) => !release.prerelease && stableTime(release) !== undefined
|
|
84
|
-
)
|
|
85
|
-
stableReleases.sort(compareVersion)
|
|
86
|
-
const stable = stableReleases.at(-1)
|
|
87
|
-
// Existing stable releases can predate framework markers. Use them only as a
|
|
88
|
-
// downgrade fence and soak anchor, never as qualification evidence.
|
|
89
|
-
const observedStable = releases
|
|
90
|
-
.filter(
|
|
91
|
-
(release) =>
|
|
92
|
-
!release.draft &&
|
|
93
|
-
!release.prerelease &&
|
|
94
|
-
Date.parse(release.publishedAt) <= now &&
|
|
95
|
-
eligibleTag(release.tag)
|
|
96
|
-
)
|
|
97
|
-
// The filter creates a new array; keep ES2022 runtime compatibility.
|
|
98
|
-
// oxlint-disable-next-line unicorn/no-array-sort
|
|
99
|
-
.sort(compareVersion)
|
|
100
|
-
.at(-1)
|
|
101
|
-
const batch = dailies.filter(
|
|
102
|
-
(release) =>
|
|
103
|
-
release.prerelease &&
|
|
104
|
-
(!stable || order(release, stable) > 0) &&
|
|
105
|
-
(!observedStable || versionLessThan(observedStable.tag, release.tag))
|
|
106
|
-
)
|
|
107
|
-
const anchor =
|
|
108
|
-
stable && (!observedStable || stable.tag === observedStable.tag)
|
|
109
|
-
? stableTime(stable)
|
|
110
|
-
: (observedStable?.publishedAt ?? batch[0]?.publishedAt)
|
|
111
|
-
const elapsed = anchor !== undefined && now - Date.parse(anchor) >= hours * 3600000
|
|
112
|
-
// Reverse a fresh array without requiring Array#toReversed.
|
|
113
|
-
// oxlint-disable-next-line unicorn/no-array-reverse
|
|
114
|
-
const candidates = elapsed ? [...batch].reverse() : []
|
|
115
|
-
candidates.sort((a, b) =>
|
|
116
|
-
versionLessThan(a.tag, b.tag) ? 1 : versionLessThan(b.tag, a.tag) ? -1 : order(b, a)
|
|
117
|
-
)
|
|
118
|
-
if (stable && (!observedStable || stable.tag === observedStable.tag)) candidates.push(stable)
|
|
119
|
-
if (!candidates.length) return { status: 'soaking' }
|
|
120
|
-
for (const candidate of candidates) {
|
|
121
|
-
let qualified = false
|
|
122
|
-
try {
|
|
123
|
-
qualified = (await options.provider.qualify(candidate)) === true
|
|
124
|
-
} catch {
|
|
125
|
-
/* Continue with older candidates. */
|
|
126
|
-
}
|
|
127
|
-
if (!qualified) continue
|
|
128
|
-
await options.provider.markStable(candidate, options.now)
|
|
129
|
-
return { status: 'stable', tag: candidate.tag }
|
|
130
|
-
}
|
|
131
|
-
return { status: 'unqualified' }
|
|
132
|
-
}
|