@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,92 +0,0 @@
|
|
|
1
|
-
import { execFile } from 'node:child_process'
|
|
2
|
-
|
|
3
|
-
/** Runs `git` with arguments, resolving its trimmed stdout; a failure rejects with the exit
|
|
4
|
-
* status as `code`. */
|
|
5
|
-
export type GitRun = (args: string[]) => Promise<string>
|
|
6
|
-
|
|
7
|
-
export function gitCli(): GitRun {
|
|
8
|
-
return (args) =>
|
|
9
|
-
new Promise<string>((resolve, reject) =>
|
|
10
|
-
execFile('git', args, { maxBuffer: 1024 * 1024 }, (error, stdout) =>
|
|
11
|
-
error
|
|
12
|
-
? reject(Object.assign(new Error('Git command failed'), { code: error.code }))
|
|
13
|
-
: resolve(stdout.trim())
|
|
14
|
-
)
|
|
15
|
-
)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** Whether `older` is `newer` or one of its ancestors; any other failure propagates. */
|
|
19
|
-
export async function gitIsAncestor(git: GitRun, older: string, newer: string): Promise<boolean> {
|
|
20
|
-
if (
|
|
21
|
-
!/^[a-f0-9]{40}$/.test(older) ||
|
|
22
|
-
!/^(?:[a-f0-9]{40}|refs\/remotes\/origin\/main)$/.test(newer)
|
|
23
|
-
)
|
|
24
|
-
return false
|
|
25
|
-
try {
|
|
26
|
-
await git(['merge-base', '--is-ancestor', older, newer])
|
|
27
|
-
return true
|
|
28
|
-
} catch (error) {
|
|
29
|
-
if ((error as { code?: unknown }).code === 1) return false
|
|
30
|
-
throw error
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** The released version in the source manifest at the exact source commit. */
|
|
35
|
-
export async function readSourceVersion(git: GitRun, sourceSha: string, path: string) {
|
|
36
|
-
const bytes = await git(['show', `${sourceSha}:${path}`])
|
|
37
|
-
if (bytes.length > 262144) throw new Error('Invalid source version manifest')
|
|
38
|
-
let manifest: unknown
|
|
39
|
-
try {
|
|
40
|
-
manifest = JSON.parse(bytes)
|
|
41
|
-
} catch {
|
|
42
|
-
throw new Error('Invalid source version manifest')
|
|
43
|
-
}
|
|
44
|
-
if (
|
|
45
|
-
typeof manifest !== 'object' ||
|
|
46
|
-
manifest === null ||
|
|
47
|
-
Array.isArray(manifest) ||
|
|
48
|
-
typeof (manifest as { version?: unknown }).version !== 'string'
|
|
49
|
-
)
|
|
50
|
-
throw new Error('Invalid source version manifest')
|
|
51
|
-
return (manifest as { version: string }).version
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** The `owner/name` of the checkout's GitHub origin, as descriptors record it. */
|
|
55
|
-
export async function originRepository(git: GitRun): Promise<string> {
|
|
56
|
-
const url = await git(['remote', 'get-url', 'origin'])
|
|
57
|
-
const match =
|
|
58
|
-
/^(?:https:\/\/github\.com\/|git@github\.com:)([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+?)(?:\.git)?\/?$/.exec(
|
|
59
|
-
url
|
|
60
|
-
)
|
|
61
|
-
if (!match || match[1]!.split('/').some((part) => part === '.' || part === '..'))
|
|
62
|
-
throw new Error('Origin is not a GitHub repository')
|
|
63
|
-
return match[1]!
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Local release provenance, replacing a trusted workflow run: the working tree is a clean
|
|
68
|
-
* checkout of exactly `sourceSha` (no modified, staged or untracked files), and that commit is
|
|
69
|
-
* on the fetched `origin/main`. Returns the origin repository and the source manifest's version.
|
|
70
|
-
*/
|
|
71
|
-
export async function resolveLocalProvenance(options: {
|
|
72
|
-
git: GitRun
|
|
73
|
-
sourceSha: string
|
|
74
|
-
versionSourcePath: string
|
|
75
|
-
}): Promise<{ sourceSha: string; repository: string; releasedVersion: string }> {
|
|
76
|
-
const { git, sourceSha } = options
|
|
77
|
-
if (!/^[a-f0-9]{40}$/.test(sourceSha)) throw new Error('Invalid source commit')
|
|
78
|
-
if ((await git(['rev-parse', '--verify', 'HEAD^{commit}'])) !== sourceSha)
|
|
79
|
-
throw new Error('Checkout is not at the requested source commit')
|
|
80
|
-
if (
|
|
81
|
-
(await git(['status', '--porcelain=v1', '--untracked-files=all', '--ignore-submodules=none']))
|
|
82
|
-
.length
|
|
83
|
-
)
|
|
84
|
-
throw new Error('Checkout has uncommitted or untracked files')
|
|
85
|
-
if (!(await gitIsAncestor(git, sourceSha, 'refs/remotes/origin/main')))
|
|
86
|
-
throw new Error('Source commit is not on origin/main')
|
|
87
|
-
return {
|
|
88
|
-
sourceSha,
|
|
89
|
-
repository: await originRepository(git),
|
|
90
|
-
releasedVersion: await readSourceVersion(git, sourceSha, options.versionSourcePath),
|
|
91
|
-
}
|
|
92
|
-
}
|
|
@@ -1,525 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local release mode: cut, sign, stage and promote desktop releases from a clean checkout on a
|
|
3
|
-
* developer machine, publishing to the app's HTTPS release feed instead of GitHub Releases.
|
|
4
|
-
* Nothing here uploads. Each publishing step writes a staged tree that mirrors the feed's
|
|
5
|
-
* object keys and an ordered upload plan; the caller uploads it with its own credentials.
|
|
6
|
-
*/
|
|
7
|
-
import { createHash, type KeyObject } from 'node:crypto'
|
|
8
|
-
import { copyFile, constants, mkdir, readdir, readFile, writeFile } from 'node:fs/promises'
|
|
9
|
-
import { dirname, join, resolve } from 'node:path'
|
|
10
|
-
import {
|
|
11
|
-
feedChannelKey,
|
|
12
|
-
feedIndexKey,
|
|
13
|
-
feedReleaseKey,
|
|
14
|
-
feedAssetKey,
|
|
15
|
-
feedUrl,
|
|
16
|
-
MAX_LEDGER_RELEASES,
|
|
17
|
-
parseReleaseLedger,
|
|
18
|
-
type FeedChannel,
|
|
19
|
-
type FeedRelease,
|
|
20
|
-
type LedgerEntry,
|
|
21
|
-
type ReleaseFeed,
|
|
22
|
-
type ReleaseLedger,
|
|
23
|
-
} from '../updates/release-feed'
|
|
24
|
-
import type { FetchFunction } from '../updates/release-location'
|
|
25
|
-
import { versionLessThan } from '../updates/release-version'
|
|
26
|
-
import { verifyReleaseDescriptor } from '../updates/signed-release'
|
|
27
|
-
import { createFeedReleaseCutProvider } from './feed-release-cut'
|
|
28
|
-
import { readFeedLedger, readFeedRelease, verifyFeedRelease } from './feed-state'
|
|
29
|
-
import { resolveLocalProvenance, type GitRun } from './local-provenance'
|
|
30
|
-
import {
|
|
31
|
-
discoveryPolicies,
|
|
32
|
-
parseReleaseConfig,
|
|
33
|
-
platformPayloads,
|
|
34
|
-
platformTargets,
|
|
35
|
-
type ReleasePlatform,
|
|
36
|
-
} from './release-config'
|
|
37
|
-
import { cutRelease, nextDevVersion } from './release-cut'
|
|
38
|
-
import {
|
|
39
|
-
configuredSigningKey,
|
|
40
|
-
signDiscoveryDescriptors,
|
|
41
|
-
writeDescriptors,
|
|
42
|
-
} from './release-descriptor-staging'
|
|
43
|
-
import { fileIdentity } from './release-publication'
|
|
44
|
-
import { promoteDailyRelease, type PromotionProvider } from './release-promotion'
|
|
45
|
-
import type { Artifact } from './release-qualification'
|
|
46
|
-
|
|
47
|
-
/** One object to upload, in plan order; the staged file is `<out>/<key>`. */
|
|
48
|
-
type UploadObject = Readonly<{
|
|
49
|
-
key: string
|
|
50
|
-
size: number
|
|
51
|
-
sha256: string
|
|
52
|
-
contentType: string
|
|
53
|
-
cacheControl: string
|
|
54
|
-
}>
|
|
55
|
-
/** Upload in order: immutable assets, then release.json, then index.json, then channel
|
|
56
|
-
* pointers, so a partial upload is never advertised. */
|
|
57
|
-
export type UploadPlan = Readonly<{ schema: 1; base: string; objects: readonly UploadObject[] }>
|
|
58
|
-
const UPLOAD_PLAN = 'upload-plan.json'
|
|
59
|
-
|
|
60
|
-
const object = (value: unknown): value is Record<string, unknown> =>
|
|
61
|
-
typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
62
|
-
const channelOf = (tag: string): 'dev' | 'daily' => (tag.includes('-dev.') ? 'dev' : 'daily')
|
|
63
|
-
const IMMUTABLE = 'public, max-age=31536000, immutable',
|
|
64
|
-
MUTABLE = 'no-cache'
|
|
65
|
-
|
|
66
|
-
/** The release platform of this machine. */
|
|
67
|
-
export function hostReleasePlatform(
|
|
68
|
-
platform: string = process.platform,
|
|
69
|
-
arch: string = process.arch
|
|
70
|
-
): ReleasePlatform {
|
|
71
|
-
const found = (Object.keys(platformTargets) as ReleasePlatform[]).find(
|
|
72
|
-
(value) => platformTargets[value][0] === platform && platformTargets[value][1] === arch
|
|
73
|
-
)
|
|
74
|
-
if (!found) throw new Error('This machine builds no release platform')
|
|
75
|
-
return found
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function localConfig(config: unknown) {
|
|
79
|
-
const parsed = parseReleaseConfig(config)
|
|
80
|
-
if (
|
|
81
|
-
!object(config) ||
|
|
82
|
-
typeof config.appId !== 'string' ||
|
|
83
|
-
!object(config.releaseSigningKeys) ||
|
|
84
|
-
!object(config.descriptors)
|
|
85
|
-
)
|
|
86
|
-
throw new Error('Invalid release signing configuration')
|
|
87
|
-
const entries = Object.entries(config.releaseSigningKeys)
|
|
88
|
-
if (!entries.length || entries.length > 16) throw new Error('Missing release verification keys')
|
|
89
|
-
const keys = new Map<string, string>()
|
|
90
|
-
for (const [id, encoded] of entries) {
|
|
91
|
-
if (
|
|
92
|
-
!/^[a-z0-9][a-z0-9._-]{0,63}$/.test(id) ||
|
|
93
|
-
typeof encoded !== 'string' ||
|
|
94
|
-
Buffer.from(encoded, 'base64').length !== 32 ||
|
|
95
|
-
Buffer.from(encoded, 'base64').toString('base64') !== encoded
|
|
96
|
-
)
|
|
97
|
-
throw new Error('Invalid release verification key')
|
|
98
|
-
keys.set(id, encoded)
|
|
99
|
-
}
|
|
100
|
-
return { ...parsed, config, keys }
|
|
101
|
-
}
|
|
102
|
-
const timestamp = (value: string) => {
|
|
103
|
-
if (!Number.isFinite(Date.parse(value))) throw new Error('Invalid release clock')
|
|
104
|
-
return new Date(value).toISOString()
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/** The directory must hold exactly `names`, all regular files. */
|
|
108
|
-
async function exactFiles(directory: string, names: readonly string[]) {
|
|
109
|
-
const entries = await readdir(directory, { withFileTypes: true })
|
|
110
|
-
if (
|
|
111
|
-
entries.length !== names.length ||
|
|
112
|
-
entries.some((entry) => !entry.isFile() || !names.includes(entry.name))
|
|
113
|
-
)
|
|
114
|
-
throw new Error('Staged directory does not hold exactly the platform release files')
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** Cut or resume a dev or daily release from a clean local checkout of `sourceSha`, with
|
|
118
|
-
* version state from the feed's ledger. `dispatched` means: build and publish this tag. */
|
|
119
|
-
export async function runLocalReleaseCut(options: {
|
|
120
|
-
kind: 'dev' | 'daily'
|
|
121
|
-
config: unknown
|
|
122
|
-
sourceSha: string
|
|
123
|
-
platform: ReleasePlatform
|
|
124
|
-
git: GitRun
|
|
125
|
-
fetch: FetchFunction
|
|
126
|
-
}) {
|
|
127
|
-
const { kind, git, platform } = options
|
|
128
|
-
const parsed = parseReleaseConfig(options.config)
|
|
129
|
-
const provenance = await resolveLocalProvenance({
|
|
130
|
-
git,
|
|
131
|
-
sourceSha: options.sourceSha,
|
|
132
|
-
versionSourcePath: parsed.versionSource.path,
|
|
133
|
-
})
|
|
134
|
-
const ledger = await readFeedLedger(parsed.feed, options.fetch)
|
|
135
|
-
const provider = createFeedReleaseCutProvider({
|
|
136
|
-
ledger,
|
|
137
|
-
release: (tag) => readFeedRelease(parsed.feed, tag, options.fetch),
|
|
138
|
-
git,
|
|
139
|
-
sourceSha: provenance.sourceSha,
|
|
140
|
-
releasedVersion: provenance.releasedVersion,
|
|
141
|
-
payloads: (tag) => platformPayloads(parsed.requirements(tag), platform),
|
|
142
|
-
})
|
|
143
|
-
const result = await cutRelease({
|
|
144
|
-
kind,
|
|
145
|
-
sourceSha: provenance.sourceSha,
|
|
146
|
-
releasedVersion: provenance.releasedVersion,
|
|
147
|
-
provider,
|
|
148
|
-
})
|
|
149
|
-
return { ...result, version: result.tag.slice(1), platform }
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/** Local provenance for an already cut tag: a clean checkout of `sourceSha` on origin/main whose
|
|
153
|
-
* manifest version the tag belongs to (the daily itself, or a dev build of the next minor). */
|
|
154
|
-
export async function localTagProvenance(options: {
|
|
155
|
-
config: unknown
|
|
156
|
-
tag: string
|
|
157
|
-
sourceSha: string
|
|
158
|
-
git: GitRun
|
|
159
|
-
}): Promise<{ repository: string }> {
|
|
160
|
-
const parsed = parseReleaseConfig(options.config)
|
|
161
|
-
parsed.requirements(options.tag)
|
|
162
|
-
const provenance = await resolveLocalProvenance({
|
|
163
|
-
git: options.git,
|
|
164
|
-
sourceSha: options.sourceSha,
|
|
165
|
-
versionSourcePath: parsed.versionSource.path,
|
|
166
|
-
})
|
|
167
|
-
const expected =
|
|
168
|
-
channelOf(options.tag) === 'dev'
|
|
169
|
-
? `v${nextDevVersion(provenance.releasedVersion)}-dev.`
|
|
170
|
-
: `v${provenance.releasedVersion}`
|
|
171
|
-
if (
|
|
172
|
-
channelOf(options.tag) === 'dev' ? !options.tag.startsWith(expected) : options.tag !== expected
|
|
173
|
-
)
|
|
174
|
-
throw new Error('Release tag does not belong to the source version')
|
|
175
|
-
return { repository: provenance.repository }
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Sign this platform's channel descriptors for payloads staged by `release-step stage-build`.
|
|
180
|
-
* Local provenance takes the place of the workflow run: the source commit is also the commit
|
|
181
|
-
* whose release tooling ran, and `runId` is the caller's local run number with attempt 1.
|
|
182
|
-
* Installer qualification needs a disposable hosted runner and is not part of a local release.
|
|
183
|
-
*/
|
|
184
|
-
export async function stageLocalDescriptors(options: {
|
|
185
|
-
config: unknown
|
|
186
|
-
directory: string
|
|
187
|
-
tag: string
|
|
188
|
-
sourceSha: string
|
|
189
|
-
repository: string
|
|
190
|
-
runId: string
|
|
191
|
-
platform: ReleasePlatform
|
|
192
|
-
keyId: string
|
|
193
|
-
privateKey: KeyObject
|
|
194
|
-
}): Promise<string[]> {
|
|
195
|
-
const { tag, platform } = options
|
|
196
|
-
const local = localConfig(options.config)
|
|
197
|
-
if (!/^[1-9]\d{0,19}$/.test(options.runId) || !/^[a-f0-9]{40}$/.test(options.sourceSha))
|
|
198
|
-
throw new Error('Invalid local release identity')
|
|
199
|
-
const publicKey = configuredSigningKey(local.config, options.keyId, options.privateKey)
|
|
200
|
-
const payloads = platformPayloads(local.requirements(tag), platform)
|
|
201
|
-
const directory = resolve(options.directory)
|
|
202
|
-
await exactFiles(directory, payloads)
|
|
203
|
-
const assets = await Promise.all(
|
|
204
|
-
payloads.map((name) => fileIdentity(join(directory, name), name))
|
|
205
|
-
)
|
|
206
|
-
const signed = signDiscoveryDescriptors({
|
|
207
|
-
policies: discoveryPolicies(local.config, tag).filter((policy) => policy.platform === platform),
|
|
208
|
-
assets,
|
|
209
|
-
identity: {
|
|
210
|
-
tag,
|
|
211
|
-
sourceSha: options.sourceSha,
|
|
212
|
-
workflowSha: options.sourceSha,
|
|
213
|
-
runId: options.runId,
|
|
214
|
-
runAttempt: 1,
|
|
215
|
-
},
|
|
216
|
-
repository: options.repository,
|
|
217
|
-
feed: feedUrl(local.feed),
|
|
218
|
-
keyId: options.keyId,
|
|
219
|
-
publicKey,
|
|
220
|
-
privateKey: options.privateKey,
|
|
221
|
-
})
|
|
222
|
-
for (const asset of assets)
|
|
223
|
-
if (
|
|
224
|
-
JSON.stringify(await fileIdentity(join(directory, asset.name), asset.name)) !==
|
|
225
|
-
JSON.stringify(asset)
|
|
226
|
-
)
|
|
227
|
-
throw new Error('Staged payload changed before signing')
|
|
228
|
-
await writeDescriptors(directory, signed)
|
|
229
|
-
return signed.map((value) => value.name)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/** The channel pointers `tag` should hold: each channel where it is the newest release. */
|
|
233
|
-
function pointerChannels(ledger: ReleaseLedger, tag: string): FeedChannel[] {
|
|
234
|
-
const entry = ledger.releases.find((item) => item.tag === tag)
|
|
235
|
-
if (!entry) return []
|
|
236
|
-
const newest = (kinds: readonly FeedChannel[]) =>
|
|
237
|
-
ledger.releases
|
|
238
|
-
.filter((item) => kinds.includes(item.kind))
|
|
239
|
-
.reduce<LedgerEntry | undefined>(
|
|
240
|
-
(best, item) => (!best || versionLessThan(best.tag, item.tag) ? item : best),
|
|
241
|
-
undefined
|
|
242
|
-
)?.tag === tag
|
|
243
|
-
if (entry.kind === 'dev') return newest(['dev']) ? ['dev'] : []
|
|
244
|
-
return [
|
|
245
|
-
...(newest(['daily', 'stable']) ? (['daily'] as const) : []),
|
|
246
|
-
...(entry.kind === 'stable' && newest(['stable']) ? (['stable'] as const) : []),
|
|
247
|
-
]
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const jsonBytes = (value: unknown) => Buffer.from(JSON.stringify(value, null, 2) + '\n')
|
|
251
|
-
const describe = (key: string, bytes: Buffer, cacheControl: string): UploadObject => ({
|
|
252
|
-
key,
|
|
253
|
-
size: bytes.length,
|
|
254
|
-
sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
255
|
-
contentType: 'application/json',
|
|
256
|
-
cacheControl,
|
|
257
|
-
})
|
|
258
|
-
|
|
259
|
-
/** Write `<out>/<key>` for each object and the plan beside them; `out` must not exist. */
|
|
260
|
-
async function writeStagedTree(
|
|
261
|
-
out: string,
|
|
262
|
-
feed: ReleaseFeed,
|
|
263
|
-
assets: readonly { key: string; path: string; artifact: Artifact }[],
|
|
264
|
-
documents: readonly { key: string; bytes: Buffer }[]
|
|
265
|
-
): Promise<UploadPlan> {
|
|
266
|
-
const root = resolve(out)
|
|
267
|
-
await mkdir(root, { mode: 0o700 })
|
|
268
|
-
const objects: UploadObject[] = []
|
|
269
|
-
for (const { key, path, artifact } of assets) {
|
|
270
|
-
const target = join(root, key)
|
|
271
|
-
await mkdir(dirname(target), { recursive: true, mode: 0o700 })
|
|
272
|
-
await copyFile(path, target, constants.COPYFILE_EXCL)
|
|
273
|
-
if (JSON.stringify(await fileIdentity(target, artifact.name)) !== JSON.stringify(artifact))
|
|
274
|
-
throw new Error('Staged asset changed while copying')
|
|
275
|
-
objects.push({
|
|
276
|
-
key,
|
|
277
|
-
size: artifact.size,
|
|
278
|
-
sha256: artifact.digest.slice(7),
|
|
279
|
-
contentType: key.endsWith('.json') ? 'application/json' : 'application/octet-stream',
|
|
280
|
-
cacheControl: IMMUTABLE,
|
|
281
|
-
})
|
|
282
|
-
}
|
|
283
|
-
for (const { key, bytes } of documents) {
|
|
284
|
-
const target = join(root, key)
|
|
285
|
-
await mkdir(dirname(target), { recursive: true, mode: 0o700 })
|
|
286
|
-
await writeFile(target, bytes, { flag: 'wx', mode: 0o600 })
|
|
287
|
-
objects.push(describe(key, bytes, MUTABLE))
|
|
288
|
-
}
|
|
289
|
-
const plan: UploadPlan = { schema: 1, base: feed.base, objects }
|
|
290
|
-
await writeFile(join(root, UPLOAD_PLAN), jsonBytes(plan), { flag: 'wx', mode: 0o600 })
|
|
291
|
-
return plan
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/** release.json, the ledger and the pointers `tag` now holds, in upload order. */
|
|
295
|
-
function releaseDocuments(feed: ReleaseFeed, ledger: ReleaseLedger, release: FeedRelease) {
|
|
296
|
-
return [
|
|
297
|
-
{ key: feedReleaseKey(feed, release.tag), bytes: jsonBytes(release) },
|
|
298
|
-
{ key: feedIndexKey(feed), bytes: jsonBytes(ledger) },
|
|
299
|
-
...pointerChannels(ledger, release.tag).map((channel) => ({
|
|
300
|
-
key: feedChannelKey(feed, channel),
|
|
301
|
-
bytes: jsonBytes({ ...release, channel }),
|
|
302
|
-
})),
|
|
303
|
-
]
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Stage this platform's signed release for upload. `directory` holds exactly the platform's
|
|
308
|
-
* payloads and the descriptors `stageLocalDescriptors` signed; every descriptor must
|
|
309
|
-
* authenticate against the app's trust and name its staged payload. The release merges with
|
|
310
|
-
* what the feed already publishes for the tag (another platform's build), never replacing an
|
|
311
|
-
* existing asset with different bytes. Writes `<out>/<app>/<tag>/<asset>` for new assets, the
|
|
312
|
-
* merged release.json, the ledger with this release newest first, and the channel pointers
|
|
313
|
-
* the release now holds, plus `<out>/upload-plan.json`.
|
|
314
|
-
*/
|
|
315
|
-
export async function stageLocalRelease(options: {
|
|
316
|
-
config: unknown
|
|
317
|
-
directory: string
|
|
318
|
-
out: string
|
|
319
|
-
tag: string
|
|
320
|
-
sourceSha: string
|
|
321
|
-
repository: string
|
|
322
|
-
platform: ReleasePlatform
|
|
323
|
-
now: string
|
|
324
|
-
fetch: FetchFunction
|
|
325
|
-
}): Promise<UploadPlan> {
|
|
326
|
-
const { tag, sourceSha, platform } = options
|
|
327
|
-
const local = localConfig(options.config)
|
|
328
|
-
const feed = local.feed,
|
|
329
|
-
now = timestamp(options.now)
|
|
330
|
-
const payloads = platformPayloads(local.requirements(tag), platform)
|
|
331
|
-
const policies = discoveryPolicies(local.config, tag).filter(
|
|
332
|
-
(policy) => policy.platform === platform
|
|
333
|
-
)
|
|
334
|
-
const directory = resolve(options.directory)
|
|
335
|
-
const names = [...payloads, ...policies.map((policy) => policy.name)]
|
|
336
|
-
await exactFiles(directory, names)
|
|
337
|
-
const staged = await Promise.all(names.map((name) => fileIdentity(join(directory, name), name)))
|
|
338
|
-
for (const policy of policies) {
|
|
339
|
-
const artifact = staged.find((asset) => asset.name === policy.name)!
|
|
340
|
-
if (artifact.size > 65536) throw new Error('Signed descriptor is too large')
|
|
341
|
-
const bytes = await readFile(join(directory, policy.name))
|
|
342
|
-
if ('sha256:' + createHash('sha256').update(bytes).digest('hex') !== artifact.digest)
|
|
343
|
-
throw new Error('Signed descriptor changed')
|
|
344
|
-
let parsed: unknown
|
|
345
|
-
try {
|
|
346
|
-
parsed = JSON.parse(bytes.toString('utf8'))
|
|
347
|
-
} catch {
|
|
348
|
-
throw new Error('Invalid signed descriptor')
|
|
349
|
-
}
|
|
350
|
-
const verified = verifyReleaseDescriptor(parsed, {
|
|
351
|
-
appId: policy.appId,
|
|
352
|
-
repository: options.repository,
|
|
353
|
-
channel: policy.channel,
|
|
354
|
-
platform: policy.os,
|
|
355
|
-
arch: policy.arch,
|
|
356
|
-
feed: feedUrl(feed),
|
|
357
|
-
keys: local.keys,
|
|
358
|
-
})
|
|
359
|
-
const payload = staged.find((asset) => asset.name === policy.payload)!
|
|
360
|
-
if (
|
|
361
|
-
!verified.ok ||
|
|
362
|
-
verified.descriptor.tag !== tag ||
|
|
363
|
-
verified.descriptor.sourceSha !== sourceSha ||
|
|
364
|
-
verified.descriptor.workflowSha !== sourceSha ||
|
|
365
|
-
verified.descriptor.asset.name !== payload.name ||
|
|
366
|
-
verified.descriptor.asset.size !== payload.size ||
|
|
367
|
-
'sha256:' + verified.descriptor.asset.sha256 !== payload.digest
|
|
368
|
-
)
|
|
369
|
-
throw new Error(`Untrusted signed descriptor: ${policy.name}`)
|
|
370
|
-
}
|
|
371
|
-
const [ledger, remote] = await Promise.all([
|
|
372
|
-
readFeedLedger(feed, options.fetch),
|
|
373
|
-
readFeedRelease(feed, tag, options.fetch),
|
|
374
|
-
])
|
|
375
|
-
const entry = ledger.releases.find((item) => item.tag === tag)
|
|
376
|
-
if (entry && entry.sourceSha !== sourceSha)
|
|
377
|
-
throw new Error('The feed publishes this tag from another source commit')
|
|
378
|
-
const merged = [...(remote?.assets ?? [])]
|
|
379
|
-
const uploads: { key: string; path: string; artifact: Artifact }[] = []
|
|
380
|
-
for (const artifact of staged) {
|
|
381
|
-
const existing = merged.find((asset) => asset.name === artifact.name)
|
|
382
|
-
if (existing) {
|
|
383
|
-
if (existing.size !== artifact.size || 'sha256:' + existing.sha256 !== artifact.digest)
|
|
384
|
-
throw new Error(`Immutable asset conflict: ${artifact.name}`)
|
|
385
|
-
continue
|
|
386
|
-
}
|
|
387
|
-
merged.push({ name: artifact.name, size: artifact.size, sha256: artifact.digest.slice(7) })
|
|
388
|
-
uploads.push({
|
|
389
|
-
key: feedAssetKey(feed, tag, artifact.name),
|
|
390
|
-
path: join(directory, artifact.name),
|
|
391
|
-
artifact,
|
|
392
|
-
})
|
|
393
|
-
}
|
|
394
|
-
const newest = ledger.releases[0]
|
|
395
|
-
if (!entry && newest && Date.parse(newest.publishedAt) > Date.parse(now))
|
|
396
|
-
throw new Error('The feed has a release newer than this clock')
|
|
397
|
-
const updated = parseReleaseLedger(
|
|
398
|
-
{
|
|
399
|
-
schema: 1,
|
|
400
|
-
app: feed.app,
|
|
401
|
-
releases: entry
|
|
402
|
-
? ledger.releases
|
|
403
|
-
: [
|
|
404
|
-
{ tag, kind: channelOf(tag), version: tag.slice(1), sourceSha, publishedAt: now },
|
|
405
|
-
...ledger.releases,
|
|
406
|
-
].slice(0, MAX_LEDGER_RELEASES),
|
|
407
|
-
},
|
|
408
|
-
feed.app
|
|
409
|
-
)
|
|
410
|
-
const release: FeedRelease = {
|
|
411
|
-
tag,
|
|
412
|
-
channel: entry?.kind ?? channelOf(tag),
|
|
413
|
-
publishedAt: remote?.publishedAt ?? now,
|
|
414
|
-
assets: merged,
|
|
415
|
-
}
|
|
416
|
-
return writeStagedTree(options.out, feed, uploads, releaseDocuments(feed, updated, release))
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
/** Check a release the feed publishes: ledger, release.json and every signed descriptor. */
|
|
420
|
-
export async function verifyLocalRelease(options: {
|
|
421
|
-
config: unknown
|
|
422
|
-
tag: string
|
|
423
|
-
repository: string
|
|
424
|
-
fetch: FetchFunction
|
|
425
|
-
}) {
|
|
426
|
-
const local = localConfig(options.config)
|
|
427
|
-
const { release, platforms } = await verifyFeedRelease({
|
|
428
|
-
config: local.config,
|
|
429
|
-
feed: local.feed,
|
|
430
|
-
tag: options.tag,
|
|
431
|
-
repository: options.repository,
|
|
432
|
-
keys: local.keys,
|
|
433
|
-
fetch: options.fetch,
|
|
434
|
-
})
|
|
435
|
-
return {
|
|
436
|
-
tag: release.tag,
|
|
437
|
-
channel: release.channel,
|
|
438
|
-
platforms,
|
|
439
|
-
missing: Object.keys(platformTargets).filter((platform) => !platforms.includes(platform)),
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
* Promote the newest qualified daily after the soak, with the shared promotion policy over the
|
|
445
|
-
* feed's ledger. A daily qualifies when every published platform's stable descriptors verify.
|
|
446
|
-
* Promotion signs nothing (a daily already carries its stable descriptors); it stages the
|
|
447
|
-
* release.json and ledger entry marked stable and the stable channel pointer.
|
|
448
|
-
*/
|
|
449
|
-
export async function runLocalPromotion(options: {
|
|
450
|
-
config: unknown
|
|
451
|
-
out: string
|
|
452
|
-
now: string
|
|
453
|
-
held: boolean
|
|
454
|
-
repository: string
|
|
455
|
-
fetch: FetchFunction
|
|
456
|
-
}) {
|
|
457
|
-
const local = localConfig(options.config)
|
|
458
|
-
const feed = local.feed
|
|
459
|
-
const ledger = await readFeedLedger(feed, options.fetch)
|
|
460
|
-
let plan: UploadPlan | undefined
|
|
461
|
-
const provider: PromotionProvider = {
|
|
462
|
-
async list() {
|
|
463
|
-
return ledger.releases.map((entry, index) => ({
|
|
464
|
-
id: ledger.releases.length - index,
|
|
465
|
-
tag: entry.tag,
|
|
466
|
-
body:
|
|
467
|
-
entry.kind === 'dev'
|
|
468
|
-
? `adea-channel:dev\n\nSource: ${entry.sourceSha}`
|
|
469
|
-
: entry.kind === 'stable'
|
|
470
|
-
? `<!-- adea-stable:v1 ${entry.tag} -->\n<!-- adea-stable-time:${entry.promotedAt} -->`
|
|
471
|
-
: '',
|
|
472
|
-
draft: false,
|
|
473
|
-
prerelease: entry.kind !== 'stable',
|
|
474
|
-
publishedAt: entry.publishedAt,
|
|
475
|
-
}))
|
|
476
|
-
},
|
|
477
|
-
async qualify(release) {
|
|
478
|
-
await verifyFeedRelease({
|
|
479
|
-
config: local.config,
|
|
480
|
-
feed,
|
|
481
|
-
tag: release.tag,
|
|
482
|
-
repository: options.repository,
|
|
483
|
-
keys: local.keys,
|
|
484
|
-
fetch: options.fetch,
|
|
485
|
-
channels: ['stable'],
|
|
486
|
-
})
|
|
487
|
-
return true
|
|
488
|
-
},
|
|
489
|
-
async markStable(selected, at) {
|
|
490
|
-
const entry = ledger.releases.find((item) => item.tag === selected.tag)
|
|
491
|
-
const remote = await readFeedRelease(feed, selected.tag, options.fetch)
|
|
492
|
-
if (!entry || !remote || entry.kind === 'dev')
|
|
493
|
-
throw new Error('Release changed during promotion')
|
|
494
|
-
const promoted: LedgerEntry = {
|
|
495
|
-
tag: entry.tag,
|
|
496
|
-
kind: 'stable',
|
|
497
|
-
version: entry.version,
|
|
498
|
-
sourceSha: entry.sourceSha,
|
|
499
|
-
publishedAt: entry.publishedAt,
|
|
500
|
-
promotedAt: entry.promotedAt ?? timestamp(at),
|
|
501
|
-
}
|
|
502
|
-
const updated = parseReleaseLedger(
|
|
503
|
-
{
|
|
504
|
-
schema: 1,
|
|
505
|
-
app: feed.app,
|
|
506
|
-
releases: ledger.releases.map((item) => (item.tag === entry.tag ? promoted : item)),
|
|
507
|
-
},
|
|
508
|
-
feed.app
|
|
509
|
-
)
|
|
510
|
-
plan = await writeStagedTree(
|
|
511
|
-
options.out,
|
|
512
|
-
feed,
|
|
513
|
-
[],
|
|
514
|
-
releaseDocuments(feed, updated, { ...remote, channel: 'stable' })
|
|
515
|
-
)
|
|
516
|
-
},
|
|
517
|
-
}
|
|
518
|
-
const result = await promoteDailyRelease({
|
|
519
|
-
now: timestamp(options.now),
|
|
520
|
-
held: options.held,
|
|
521
|
-
soakHours: local.soakHours,
|
|
522
|
-
provider,
|
|
523
|
-
})
|
|
524
|
-
return { ...result, ...(plan ? { plan } : {}) }
|
|
525
|
-
}
|