@adea-ai/app-framework 0.38.1 → 0.39.1
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/ci/desktop-release-feed.sh +100 -0
- package/ci/desktop-release.sh +46 -42
- package/dist/framework-source.json +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# shellcheck shell=bash
|
|
2
|
+
# Release-feed steps (an S3-compatible bucket such as Cloudflare R2) of adea-desktop-release,
|
|
3
|
+
# sourced by ci/desktop-release.sh and by its tests. The caller defines `say` and `sha256` and sets
|
|
4
|
+
# bucket, work, out and dry, plus R2_ENDPOINT or CLOUDFLARE_ACCOUNT_ID, R2_ACCESS_KEY_ID and
|
|
5
|
+
# R2_SECRET_ACCESS_KEY.
|
|
6
|
+
|
|
7
|
+
feed_s3() {
|
|
8
|
+
AWS_ACCESS_KEY_ID="$R2_ACCESS_KEY_ID" AWS_SECRET_ACCESS_KEY="$R2_SECRET_ACCESS_KEY" \
|
|
9
|
+
AWS_DEFAULT_REGION=auto AWS_REQUEST_CHECKSUM_CALCULATION=when_required \
|
|
10
|
+
aws s3api "$@" --bucket "$bucket" \
|
|
11
|
+
--endpoint-url "${R2_ENDPOINT:-https://$CLOUDFLARE_ACCOUNT_ID.r2.cloudflarestorage.com}" --output text
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
# Prints "<size> <sha256>" for the stored <key> (the digest from its sha256 metadata, or "None"
|
|
15
|
+
# for an object uploaded without it), or nothing when the feed has no such object. Any other HEAD
|
|
16
|
+
# failure (credentials, network, throttling) is not evidence of absence, so it fails.
|
|
17
|
+
feed_object_head() { # <key>
|
|
18
|
+
local head err
|
|
19
|
+
if head=$(feed_s3 head-object --key "$1" --query '[ContentLength, Metadata.sha256]' 2>"$work/head.err"); then
|
|
20
|
+
printf '%s\n' "$head" | tr '\t' ' '
|
|
21
|
+
return 0
|
|
22
|
+
fi
|
|
23
|
+
err=$(cat "$work/head.err")
|
|
24
|
+
case "$err" in
|
|
25
|
+
*'(404)'* | *'Not Found'* | *NoSuchKey*) return 0 ;;
|
|
26
|
+
esac
|
|
27
|
+
say "refusing: could not tell whether $1 exists: $err" >&2
|
|
28
|
+
return 1
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# True only when the stored <key> holds exactly <size> bytes whose SHA-256 is <digest>. An object
|
|
32
|
+
# of the same size from an interrupted or different upload is not the staged file: the digest is
|
|
33
|
+
# compared from the object's sha256 metadata, or from its downloaded bytes when it has none.
|
|
34
|
+
feed_object_matches() { # <key> <size> <digest>
|
|
35
|
+
local head stored_size stored_digest copy="$work/existing-object" actual
|
|
36
|
+
head=$(feed_object_head "$1") || return 1
|
|
37
|
+
[ -n "$head" ] || return 1
|
|
38
|
+
read -r stored_size stored_digest <<<"$head"
|
|
39
|
+
[ "$stored_size" = "$2" ] || return 1
|
|
40
|
+
if [ -n "$stored_digest" ] && [ "$stored_digest" != None ]; then
|
|
41
|
+
[ "$stored_digest" = "$3" ]
|
|
42
|
+
return
|
|
43
|
+
fi
|
|
44
|
+
rm -f "$copy"
|
|
45
|
+
feed_s3 get-object --key "$1" "$copy" >/dev/null || { say "refusing: could not read the existing $1"; return 1; }
|
|
46
|
+
actual=$(sha256 "$copy")
|
|
47
|
+
rm -f "$copy"
|
|
48
|
+
[ "$actual" = "$3" ]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
# What clients follow to find a release: the channel pointers and any installers. They go up
|
|
52
|
+
# only after the release they name has verified from the feed.
|
|
53
|
+
feed_live_key() { # <key>
|
|
54
|
+
case "$1" in */channels/* | */install/*) return 0 ;; *) return 1 ;; esac
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
# Uploads one phase of the staged plan, in plan order. `content` is the release itself (immutable
|
|
58
|
+
# files, release.json and the ledger); `live` is the channel pointers and installers, uploaded
|
|
59
|
+
# after the content verified. An immutable file is written only if absent (If-None-Match), and an
|
|
60
|
+
# existing one must already hold the same bytes. Every write stores its SHA-256 as metadata and is
|
|
61
|
+
# read back by size and digest.
|
|
62
|
+
upload() { # <content|live>
|
|
63
|
+
local phase=${1:?content|live} plan="$out/upload-plan.json" key size digest type cache file put_err
|
|
64
|
+
bun -e '
|
|
65
|
+
const plan = JSON.parse(require("node:fs").readFileSync(process.argv[1], "utf8"))
|
|
66
|
+
for (const o of plan.objects) console.log([o.key, o.size, o.sha256, o.contentType, o.cacheControl].join("\t"))' "$plan" |
|
|
67
|
+
while IFS=$'\t' read -r key rest; do
|
|
68
|
+
if feed_live_key "$key"; then [ "$phase" = live ] || continue; else [ "$phase" = content ] || continue; fi
|
|
69
|
+
printf '%s\t%s\n' "$key" "$rest"
|
|
70
|
+
done > "$work/objects-$phase.tsv"
|
|
71
|
+
say "upload $phase ($(wc -l < "$work/objects-$phase.tsv" | tr -d ' ') objects, in order) to s3://$bucket via R2 S3 API:"
|
|
72
|
+
cut -f1,2 "$work/objects-$phase.tsv" | sed 's/^/ /'
|
|
73
|
+
[ -z "$dry" ] || { say "dry run: nothing uploaded"; return 0; }
|
|
74
|
+
while IFS=$'\t' read -r key size digest type cache; do
|
|
75
|
+
file="$out/$key"
|
|
76
|
+
[ "$(wc -c < "$file" | tr -d ' ')" = "$size" ] && [ "$(sha256 "$file")" = "$digest" ] ||
|
|
77
|
+
{ say "refusing: $key changed after staging"; exit 1; }
|
|
78
|
+
if [ "$cache" != no-cache ]; then
|
|
79
|
+
if feed_s3 put-object --key "$key" --body "$file" --content-type "$type" --cache-control "$cache" \
|
|
80
|
+
--metadata "sha256=$digest" --if-none-match '*' >/dev/null 2>"$work/put.err"; then
|
|
81
|
+
say " uploaded $key"
|
|
82
|
+
else
|
|
83
|
+
put_err=$(cat "$work/put.err")
|
|
84
|
+
case "$put_err" in
|
|
85
|
+
*'(412)'* | *PreconditionFailed*) ;;
|
|
86
|
+
*) say "refusing: upload of $key failed: $put_err"; exit 1 ;;
|
|
87
|
+
esac
|
|
88
|
+
feed_object_matches "$key" "$size" "$digest" ||
|
|
89
|
+
{ say "refusing: immutable $key exists with other bytes"; exit 1; }
|
|
90
|
+
say " exists $key"
|
|
91
|
+
continue
|
|
92
|
+
fi
|
|
93
|
+
else
|
|
94
|
+
feed_s3 put-object --key "$key" --body "$file" --content-type "$type" --cache-control "$cache" \
|
|
95
|
+
--metadata "sha256=$digest" >/dev/null
|
|
96
|
+
say " uploaded $key"
|
|
97
|
+
fi
|
|
98
|
+
feed_object_matches "$key" "$size" "$digest" || { say "upload of $key did not verify"; exit 1; }
|
|
99
|
+
done < "$work/objects-$phase.tsv"
|
|
100
|
+
}
|
package/ci/desktop-release.sh
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# adea-desktop-release: publish a desktop release from a
|
|
3
|
-
# framework's local release mode. It builds this machine's platform (macOS arm64 or Linux x64),
|
|
2
|
+
# adea-desktop-release: publish a desktop release from a release tag pipeline (GitLab CI, CircleCI or
|
|
3
|
+
# GitHub Actions) with the framework's local release mode. It builds this machine's platform (macOS arm64 or Linux x64),
|
|
4
4
|
# signs the channel descriptors, uploads the staged tree to the app's release feed (an
|
|
5
|
-
# S3-compatible bucket such as Cloudflare R2)
|
|
6
|
-
#
|
|
5
|
+
# S3-compatible bucket such as Cloudflare R2), verifies the release from the feed, then uploads the
|
|
6
|
+
# channel pointers clients follow, and links every published file on the GitLab release.
|
|
7
7
|
#
|
|
8
8
|
# adea-desktop-release daily build and publish the tag's daily (CI_COMMIT_TAG = v<version>)
|
|
9
9
|
# adea-desktop-release stable promote the newest qualified daily after the soak
|
|
@@ -17,12 +17,17 @@
|
|
|
17
17
|
# release:extend-plan <channel> <tag> <platform> <out> <source-sha>
|
|
18
18
|
# adds app files to the staged plan
|
|
19
19
|
#
|
|
20
|
-
#
|
|
20
|
+
# The tag, commit and run id come from GitLab's CI variables, else CircleCI's or GitHub Actions'.
|
|
21
|
+
#
|
|
22
|
+
# Environment (protected CI variables or contexts):
|
|
21
23
|
# DESKTOP_RELEASE_APP_DIR the app directory, relative to the repository (default .)
|
|
22
24
|
# DESKTOP_UPDATE_SIGNING_KEY_B64 base64 of the Ed25519 update key PEM (daily; refused when missing)
|
|
23
25
|
# R2_ENDPOINT or CLOUDFLARE_ACCOUNT_ID, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY bucket credentials
|
|
24
26
|
# R2_BUCKET (default adea-releases), STABLE_PROMOTION_HELD (true holds promotion)
|
|
25
27
|
# DESKTOP_RELEASE_DRY_RUN=1 cut and plan only: builds, signs and uploads nothing
|
|
28
|
+
# GITLAB_RELEASE_TOKEN links the files on the GitLab release outside GitLab CI (which
|
|
29
|
+
# uses CI_JOB_TOKEN); GITLAB_PROJECT overrides the project path
|
|
30
|
+
# taken from the origin remote
|
|
26
31
|
# The update key is decoded into the signing process's environment only, never to disk.
|
|
27
32
|
set -euo pipefail
|
|
28
33
|
channel=${1:?daily|stable}
|
|
@@ -30,12 +35,25 @@ case "$channel" in daily|stable) ;; *) echo "channel must be daily or stable"; e
|
|
|
30
35
|
dry=${DESKTOP_RELEASE_DRY_RUN:-}
|
|
31
36
|
bucket=${R2_BUCKET:-adea-releases}
|
|
32
37
|
say() { printf '%s\n' "$*"; }
|
|
38
|
+
if [ -z "${CI_COMMIT_TAG:-}" ]; then
|
|
39
|
+
CI_COMMIT_TAG=${CIRCLE_TAG:-}
|
|
40
|
+
[ -n "$CI_COMMIT_TAG" ] || [ "${GITHUB_REF_TYPE:-}" != tag ] || CI_COMMIT_TAG=${GITHUB_REF_NAME:-}
|
|
41
|
+
fi
|
|
42
|
+
CI_COMMIT_SHA=${CI_COMMIT_SHA:-${CIRCLE_SHA1:-${GITHUB_SHA:-}}}
|
|
43
|
+
# The run id signs into the descriptors and must be a positive integer: CircleCI's build number,
|
|
44
|
+
# not its workflow id (a UUID).
|
|
45
|
+
CI_PIPELINE_ID=${CI_PIPELINE_ID:-${CIRCLE_BUILD_NUM:-${GITHUB_RUN_ID:-}}}
|
|
33
46
|
sha256() { if command -v shasum >/dev/null; then shasum -a 256 "$1"; else sha256sum "$1"; fi | cut -d' ' -f1; }
|
|
34
47
|
b64d() { printf '%s' "$1" | base64 -d 2>/dev/null || printf '%s' "$1" | base64 -D; }
|
|
35
48
|
|
|
49
|
+
# upload and the feed's other bucket steps, beside this script in the installed package.
|
|
50
|
+
# shellcheck source=ci/desktop-release-feed.sh
|
|
51
|
+
source "$(dirname "$(readlink -f "$0")")/desktop-release-feed.sh"
|
|
52
|
+
|
|
36
53
|
root=$(git rev-parse --show-toplevel)
|
|
37
54
|
cd "$root"
|
|
38
|
-
sha=${CI_COMMIT_SHA
|
|
55
|
+
sha=${CI_COMMIT_SHA:-}
|
|
56
|
+
[ -n "$sha" ] || sha=$(git rev-parse HEAD)
|
|
39
57
|
[ "$sha" = "$(git rev-parse HEAD)" ] || { say "refusing: checkout is not at $sha"; exit 1; }
|
|
40
58
|
# Provenance is checked against origin/main of this project (the framework records the GitLab
|
|
41
59
|
# project as owner/name). The runner's insteadOf rewrite can still put its job token into
|
|
@@ -82,50 +100,34 @@ extend_plan() { # <channel> <tag> <released sha>
|
|
|
82
100
|
else rc=$?; [ "$rc" = 3 ] || exit "$rc"; fi
|
|
83
101
|
}
|
|
84
102
|
|
|
85
|
-
# Uploads the staged plan in order: immutable files first (an existing one must already hold the
|
|
86
|
-
# same bytes), channel pointers last, each verified by size after the upload.
|
|
87
|
-
upload() {
|
|
88
|
-
local plan="$out/upload-plan.json"
|
|
89
|
-
bun -e '
|
|
90
|
-
const plan = JSON.parse(require("node:fs").readFileSync(process.argv[1], "utf8"))
|
|
91
|
-
for (const o of plan.objects) console.log([o.key, o.size, o.sha256, o.contentType, o.cacheControl].join("\t"))' "$plan" > "$work/objects.tsv"
|
|
92
|
-
say "upload plan ($(wc -l < "$work/objects.tsv" | tr -d ' ') objects, in order) to s3://$bucket via R2 S3 API:"
|
|
93
|
-
cut -f1,2 "$work/objects.tsv" | sed 's/^/ /'
|
|
94
|
-
[ -z "$dry" ] || { say "dry run: nothing uploaded"; return 0; }
|
|
95
|
-
local endpoint=${R2_ENDPOINT:-https://$CLOUDFLARE_ACCOUNT_ID.r2.cloudflarestorage.com}
|
|
96
|
-
s3() { AWS_ACCESS_KEY_ID="$R2_ACCESS_KEY_ID" AWS_SECRET_ACCESS_KEY="$R2_SECRET_ACCESS_KEY" \
|
|
97
|
-
AWS_DEFAULT_REGION=auto AWS_REQUEST_CHECKSUM_CALCULATION=when_required \
|
|
98
|
-
aws s3api "$@" --bucket "$bucket" --endpoint-url "$endpoint" --output text; }
|
|
99
|
-
while IFS=$'\t' read -r key size digest type cache; do
|
|
100
|
-
file="$out/$key"
|
|
101
|
-
[ "$(wc -c < "$file" | tr -d ' ')" = "$size" ] && [ "$(sha256 "$file")" = "$digest" ] ||
|
|
102
|
-
{ say "refusing: $key changed after staging"; exit 1; }
|
|
103
|
-
if [ "$cache" != no-cache ] && existing=$(s3 head-object --key "$key" --query ContentLength 2>/dev/null); then
|
|
104
|
-
[ "$existing" = "$size" ] || { say "refusing: immutable $key exists with other bytes"; exit 1; }
|
|
105
|
-
say " exists $key"; continue
|
|
106
|
-
fi
|
|
107
|
-
s3 put-object --key "$key" --body "$file" --content-type "$type" --cache-control "$cache" >/dev/null
|
|
108
|
-
[ "$(s3 head-object --key "$key" --query ContentLength)" = "$size" ] || { say "upload of $key did not verify"; exit 1; }
|
|
109
|
-
say " uploaded $key"
|
|
110
|
-
done < "$work/objects.tsv"
|
|
111
|
-
}
|
|
112
|
-
|
|
113
103
|
# Links every published file of <tag> on its GitLab release (creating the release when release
|
|
114
104
|
# tooling has not), pointing at the feed. Links that already exist are kept.
|
|
115
105
|
link_release() { # <tag>
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
106
|
+
local header= token= project=${CI_PROJECT_ID:-}
|
|
107
|
+
if [ -n "${CI_JOB_TOKEN:-}" ]; then header=JOB-TOKEN token=$CI_JOB_TOKEN
|
|
108
|
+
elif [ -n "${GITLAB_RELEASE_TOKEN:-}" ]; then header=PRIVATE-TOKEN token=$GITLAB_RELEASE_TOKEN; fi
|
|
109
|
+
[ -z "$dry" ] && [ -n "$header" ] || { say "GitLab release links skipped"; return 0; }
|
|
110
|
+
if [ -z "$project" ]; then
|
|
111
|
+
# The origin remote's path (https://host/<path>.git or git@host:<path>.git), URL-encoded.
|
|
112
|
+
project=${GITLAB_PROJECT:-$(git -C "$root" remote get-url origin)}
|
|
113
|
+
project=${project%.git}
|
|
114
|
+
case "$project" in git@*:*) project=${project#*:} ;; *://*) project=${project#*://}; project=${project#*/} ;; esac
|
|
115
|
+
project=${project//\//%2F}
|
|
116
|
+
fi
|
|
117
|
+
# The token reaches bun through its environment, never its arguments.
|
|
118
|
+
LINK_TOKEN="$token" LINK_HEADER="$header" bun -e '
|
|
119
|
+
const [api, project, tag, base, app, outDir] = process.argv.slice(1)
|
|
120
|
+
const auth = { [process.env.LINK_HEADER]: process.env.LINK_TOKEN }
|
|
119
121
|
const fs = require("node:fs")
|
|
120
122
|
const release = JSON.parse(fs.readFileSync(`${outDir}/${app}/${tag}/release.json`, "utf8"))
|
|
121
123
|
const url = `${api}/projects/${project}/releases/${encodeURIComponent(tag)}`
|
|
122
124
|
const call = (method, path, body) => fetch(url + path, { method,
|
|
123
|
-
headers: {
|
|
125
|
+
headers: { ...auth, "content-type": "application/json" },
|
|
124
126
|
body: body && JSON.stringify(body) })
|
|
125
127
|
let res = await call("GET", "")
|
|
126
128
|
if (res.status === 404) {
|
|
127
129
|
res = await fetch(`${api}/projects/${project}/releases`, { method: "POST",
|
|
128
|
-
headers: {
|
|
130
|
+
headers: { ...auth, "content-type": "application/json" },
|
|
129
131
|
body: JSON.stringify({ tag_name: tag, name: tag, description: `Desktop release ${tag}.` }) })
|
|
130
132
|
if (!res.ok) throw new Error(`creating release ${tag}: ${res.status} ${await res.text()}`)
|
|
131
133
|
res = await call("GET", "")
|
|
@@ -139,7 +141,7 @@ link_release() { # <tag>
|
|
|
139
141
|
link_type: /\.(json)$/.test(name) ? "other" : "package" })
|
|
140
142
|
if (!link.ok) throw new Error(`linking ${name}: ${link.status} ${await link.text()}`)
|
|
141
143
|
console.log(` linked ${name}`)
|
|
142
|
-
}' "$CI_API_V4_URL" "$
|
|
144
|
+
}' "${CI_API_V4_URL:-https://gitlab.com/api/v4}" "$project" "$1" "$feed_base" "$repo" "$out"
|
|
143
145
|
}
|
|
144
146
|
|
|
145
147
|
if [ "$channel" = stable ]; then
|
|
@@ -149,8 +151,9 @@ if [ "$channel" = stable ]; then
|
|
|
149
151
|
[ -n "$tag" ] || { say "nothing to promote"; exit 0; }
|
|
150
152
|
released=$(bun -e 'const l=require(process.argv[1]);console.log(l.releases.find(r=>r.tag===process.argv[2]).sourceSha)' "$out/$repo/index.json" "$tag")
|
|
151
153
|
extend_plan stable "$tag" "$released"
|
|
152
|
-
upload
|
|
154
|
+
upload content
|
|
153
155
|
[ -n "$dry" ] || bun "$cli/release-finalize-cli.js" --local release-config.json "$tag"
|
|
156
|
+
upload live
|
|
154
157
|
exit 0
|
|
155
158
|
fi
|
|
156
159
|
|
|
@@ -198,7 +201,8 @@ bun -e '
|
|
|
198
201
|
if (missing.length) { console.error("command artifacts missing from the plan: " + missing.join(", ")); process.exit(1) }' \
|
|
199
202
|
"$out/upload-plan.json" "$PWD/release-config.json" "$repo" "$tag" "$platform"
|
|
200
203
|
extend_plan daily "$tag" "$sha"
|
|
201
|
-
upload
|
|
204
|
+
upload content
|
|
202
205
|
verified=$(bun "$cli/release-finalize-cli.js" --local release-config.json "$tag")
|
|
203
206
|
say "verified from the feed: $verified"
|
|
207
|
+
upload live
|
|
204
208
|
link_release "$tag"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.39.1","commit":"4b9894a73bdbe3960175c897fa65c64447551953"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adea-ai/app-framework",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
30
30
|
"ci/desktop-release.sh",
|
|
31
|
+
"ci/desktop-release-feed.sh",
|
|
31
32
|
"dist",
|
|
32
33
|
"src/app/application.tsx",
|
|
33
34
|
"src/appearance",
|