Skip to content

Commit a1bc1cd

Browse files
noreplyclaude
andcommitted
fork release: check only the server program, never publish below a published release
- check-archives reads only <stem>/t3 (t3.exe in the zip), not client/, and fails when the program is missing. The web client names this repository on every Actions build, so it passed while the server still named upstream. - check-bundle (new) checks apps/server/dist without dist/client, for the same reason. - resolve and publish refuse a version that is not above every published release on the server's stable channel: the server updater takes the newest-created release, so an older build published later would read as a downgrade. Published releases are always latest. - Preflight runs fork-release-workflow.test.py too. - The build sets T3CODE_DESKTOP_UPDATE_REPOSITORY (the name release-repository.ts reads); the former T3CODE_RELEASE_REPOSITORY is gone. The publish job takes its guard script from github.workflow_sha, not from the commit being built. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0da2ccd commit a1bc1cd

4 files changed

Lines changed: 182 additions & 55 deletions

File tree

‎.github/scripts/fork-release-workflow.test.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,25 @@ def index(pred):
116116
"fork-release.sh resolve" in "\n".join(str(s.get("run", "")) for s in steps(jobs["preflight"])))
117117
check("preflight runs the guard tests", "fork-release.test.sh" in runs)
118118
check("the CLI archives are checked for the release repository", "fork-release.sh check-archives release-assets" in runs)
119+
check("preflight runs this shape test", "fork-release-workflow.test.py" in
120+
"\n".join(str(s.get("run", "")) for s in steps(jobs["preflight"])))
121+
122+
# The server bundle check skips dist/client, which names this repository on every Actions build.
123+
bundle_steps = [s for s in steps(jobs["build_bundle"]) if "apps/server/dist" in str(s.get("run", ""))]
124+
check("the server bundle is checked through check-bundle (without dist/client)",
125+
[str(s.get("run", "")).strip() for s in bundle_steps]
126+
== ["bash .github/scripts/fork-release.sh check-bundle apps/server/dist"])
127+
128+
# The build names this fork through the setting scripts/lib/release-repository.ts reads.
129+
build = next((s for s in steps(jobs["build_bundle"]) if s.get("name") == "Build JS bundle"), {})
130+
check("the build sets T3CODE_DESKTOP_UPDATE_REPOSITORY to this repository",
131+
(build.get("env") or {}).get("T3CODE_DESKTOP_UPDATE_REPOSITORY") == "${{ github.repository }}")
132+
check("the former name T3CODE_RELEASE_REPOSITORY appears nowhere", "T3CODE_RELEASE_REPOSITORY" not in text)
133+
134+
# The write job's guard script comes from the workflow's own commit, not the commit being built.
135+
guard = [s for s in steps(jobs["publish"]) if str(s.get("uses", "")).startswith("actions/checkout@")]
136+
check("publish checks out its guard script at github.workflow_sha",
137+
len(guard) == 1 and (guard[0].get("with") or {}).get("ref") == "${{ github.workflow_sha }}")
119138

120139
if failures:
121140
print(f"{len(failures)} failed")

‎.github/scripts/fork-release.sh‎

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
#
55
# resolve Preflight: picks base tag, version and tag for HEAD (key=value lines).
66
# remove-drafts TAG Refuses a published TAG, then deletes drafts with TAG left by earlier runs.
7-
# publish ID TAG VERSION Refuses a published TAG, then publishes draft ID, marked latest only
8-
# when VERSION is above every published fork release.
9-
# check-archives DIR Every CLI archive in DIR must name REPOSITORY as its release repository.
7+
# publish ID TAG VERSION Refuses a published TAG or a published release that is not below
8+
# VERSION, then publishes draft ID as the latest release.
9+
# check-bundle DIR The server bundle DIR (apps/server/dist) outside DIR/client must name
10+
# REPOSITORY as its release repository.
11+
# check-archives DIR The `t3` program of every CLI archive in DIR must name REPOSITORY.
1012
#
1113
# Environment: REPOSITORY (owner/name of this fork; GITHUB_REPOSITORY in a run), UPSTREAM
1214
# (owner/name, resolve looks it up), UPSTREAM_URL (git URL of upstream, default GitHub), ORIGIN
@@ -63,6 +65,23 @@ refuse_published() {
6365
fi
6466
}
6567

68+
# The server's updater (packages/shared/src/cliRelease.ts newestCliReleaseVersion) takes the
69+
# newest-created non-draft release on its channel, not the highest version. So every new release
70+
# must be above every published one, or `t3 update` would see a downgrade and stall until a higher
71+
# build exists. Stable channel = any vX.Y.Z[-...] tag except -nightly./-preview. builds.
72+
refuse_older() {
73+
local version="$1" other published
74+
published="$(releases '.[] | select(.draft | not) | .tag_name')"
75+
for other in $published; do
76+
[[ "$other" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]] || continue
77+
[[ ! "$other" =~ -(nightly|preview)\. ]] || continue
78+
[[ "$other" =~ $stable_version_re || "$other" =~ $fork_version_re ]] \
79+
|| die "Published release $other is on the server's stable channel but has no X.Y.Z or X.Y.Z-fork.N version, so $version cannot be ordered against it; nothing was changed."
80+
version_gt "$version" "$other" \
81+
|| die "$other is published and not below $version. The server updates to the newest-created release, so publishing $version would show every server a downgrade. Build a newer upstream release instead; to go back, install the older release with t3 update --version X --allow-downgrade. Nothing was changed."
82+
done
83+
}
84+
6685
cmd_resolve() {
6786
local upstream="${UPSTREAM:-}"
6887
if [[ -z "$upstream" ]]; then
@@ -119,6 +138,7 @@ cmd_resolve() {
119138
last="$(git ls-remote --tags --refs "$ORIGIN" "v$version-fork.*" \
120139
| sed -n "s|.*refs/tags/v$version-fork\.\([0-9]\+\)$|\1|p" | sort -n | tail -n1)"
121140
version="$version-fork.$(( ${last:-0} + 1 ))"
141+
refuse_older "$version"
122142
{
123143
echo "ref=$head"
124144
echo "upstream=$upstream"
@@ -146,28 +166,35 @@ cmd_publish() {
146166
local id="${1:?release id}" tag="${2:?tag}" version="${3:?version}"
147167
[[ "$version" =~ $fork_version_re ]] || die "'$version' is not a fork version."
148168
refuse_published "$tag"
149-
# Latest only when above every published fork release: building an older ref must not move
150-
# /releases/latest backwards, where the desktop updater would then find nothing newer.
151-
local latest=true other published
152-
published="$(releases '.[] | select((.draft or .prerelease) | not) | .tag_name')"
153-
for other in $published; do
154-
[[ "$other" =~ $fork_version_re ]] || continue
155-
if ! version_gt "$version" "$other"; then
156-
latest=false
157-
echo "$other is published and not below $version, so $tag is not marked latest."
158-
break
159-
fi
160-
done
161-
gh api -X PATCH "repos/$REPOSITORY/releases/$id" -F draft=false -f make_latest="$latest" > /dev/null
162-
echo "Published $tag (latest: $latest)."
169+
# Checked again here: a release published since preflight must not end up above this one. After
170+
# this check VERSION is the highest release, so the server and the desktop updater agree on it.
171+
refuse_older "$version"
172+
gh api -X PATCH "repos/$REPOSITORY/releases/$id" -F draft=false -f make_latest=true > /dev/null
173+
echo "Published $tag (latest: true)."
163174
{
164175
echo "published=true"
165-
echo "latest=$latest"
176+
echo "latest=true"
166177
} >> "$OUTPUT"
167178
}
168179

180+
# The web client (DIR/client) names this repository on every Actions build anyway: upstream's
181+
# apps/web/vite.config.ts bakes GITHUB_REPOSITORY into it. Only the server code counts here.
182+
cmd_check_bundle() {
183+
local dir="${1:?directory}" file files
184+
[[ -d "$dir" ]] || die "No server bundle at $dir."
185+
files="$(find "$dir" -path "$dir/client" -prune -o -type f -print)"
186+
[[ -n "$files" ]] || die "The server bundle $dir holds no files outside client/."
187+
while IFS= read -r file; do
188+
if grep -qaF "\"$REPOSITORY\"" "$file"; then
189+
echo "The server bundle names $REPOSITORY (${file#"$dir"/})."
190+
return 0
191+
fi
192+
done <<< "$files"
193+
die "The server bundle $dir (outside client/) does not name $REPOSITORY as its release repository, so it would update from elsewhere."
194+
}
195+
169196
cmd_check_archives() {
170-
local dir="${1:?directory}" archive work found=0
197+
local dir="${1:?directory}" archive work name stem program found=0
171198
shopt -s nullglob
172199
for archive in "$dir"/t3-*.tar.gz "$dir"/t3-*.zip; do
173200
found=1
@@ -176,12 +203,19 @@ cmd_check_archives() {
176203
*.tar.gz) tar -xzf "$archive" -C "$work" ;;
177204
*.zip) python3 -I -m zipfile -e "$archive" "$work" ;;
178205
esac
179-
# The `t3` executable bundles the server again (release-desktop.yml build-exe), so this checks
180-
# the code that ships rather than the separate JS bundle.
181-
grep -rqaF "\"$REPOSITORY\"" "$work" \
182-
|| die "$(basename "$archive") does not name $REPOSITORY as its release repository, so it would update from elsewhere."
206+
# Only the `t3` program at <stem>/ (scripts/build-cli-archive.ts): it bundles the server again,
207+
# and its updater is what counts. client/ names this repository on every Actions build anyway.
208+
name="$(basename "$archive")"
209+
stem="${name%.tar.gz}"
210+
stem="${stem%.zip}"
211+
program="$work/$stem/t3"
212+
[[ "$archive" != *.zip ]] || program="$work/$stem/t3.exe"
213+
[[ -f "$program" ]] \
214+
|| die "$name has no ${program#"$work"/}, so the server program in it cannot be checked."
215+
grep -qaF "\"$REPOSITORY\"" "$program" \
216+
|| die "${program#"$work"/} in $name does not name $REPOSITORY as its release repository, so it would update from elsewhere."
183217
rm -rf "$work"
184-
echo "$(basename "$archive") names $REPOSITORY."
218+
echo "${program#"$work"/} in $name names $REPOSITORY."
185219
done
186220
(( found )) || die "No CLI archive in $dir."
187221
}
@@ -192,7 +226,8 @@ case "$command" in
192226
resolve) cmd_resolve "$@" ;;
193227
remove-drafts) cmd_remove_drafts "$@" ;;
194228
publish) cmd_publish "$@" ;;
229+
check-bundle) cmd_check_bundle "$@" ;;
195230
check-archives) cmd_check_archives "$@" ;;
196231
version-gt) version_gt "$@" ;;
197-
*) die "usage: $0 resolve | remove-drafts TAG | publish ID TAG VERSION | check-archives DIR" ;;
232+
*) die "usage: $0 resolve | remove-drafts TAG | publish ID TAG VERSION | check-bundle DIR | check-archives DIR" ;;
198233
esac

‎.github/scripts/fork-release.test.sh‎

Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ expect_refused "resolve: refuses a base above upstream's latest release" "above
140140
echo v0.1.10 > "$root/api/upstream_latest"
141141
expect_resolved "resolve: accepts it once upstream marks it latest" 0.1.10-fork.1
142142

143+
reset_api v0.1.10
144+
echo '[{"id":5,"draft":false,"prerelease":false,"tag_name":"v0.1.10-fork.3"}]' > "$root/api/releases.json"
145+
new_fork v0.1.9
146+
expect_refused "resolve: refuses a build below a published release (older ref after a newer one)" \
147+
"v0.1.10-fork.3 is published and not below 0.1.9-fork.1" "$root/work" resolve
148+
echo '[{"id":5,"draft":true,"prerelease":false,"tag_name":"v0.1.10-fork.3"}]' > "$root/api/releases.json"
149+
expect_resolved "resolve: a higher draft does not block (updaters skip drafts)" 0.1.9-fork.1
150+
143151
# --- remove-drafts -----------------------------------------------------------------------------
144152
new_upstream
145153
reset_api
@@ -182,12 +190,31 @@ fi
182190
reset_api
183191
echo '[{"id":5,"draft":false,"prerelease":false,"tag_name":"v0.1.10-fork.1"},
184192
{"id":9,"draft":true,"prerelease":false,"tag_name":"v0.1.9-fork.2"}]' > "$root/api/releases.json"
185-
if run "$root/work" publish 9 v0.1.9-fork.2 0.1.9-fork.2 && grep -qx "patched 9 draft=false make_latest=false" "$root/api/writes"; then
186-
pass "publish: an older version is published without becoming latest"
193+
expect_refused "publish: refuses a version below a published release (server takes the newest created)" \
194+
"v0.1.10-fork.1 is published and not below 0.1.9-fork.2" "$root/work" publish 9 v0.1.9-fork.2 0.1.9-fork.2
195+
[[ ! -e "$root/api/writes" ]] || fail "publish: nothing written for an older version"
196+
197+
reset_api
198+
echo '[{"id":5,"draft":false,"prerelease":true,"tag_name":"v0.1.10-fork.1"},
199+
{"id":9,"draft":true,"prerelease":false,"tag_name":"v0.1.9-fork.2"}]' > "$root/api/releases.json"
200+
expect_refused "publish: a higher prerelease also blocks (the server ignores the prerelease flag)" \
201+
"not below" "$root/work" publish 9 v0.1.9-fork.2 0.1.9-fork.2
202+
203+
reset_api
204+
echo '[{"id":4,"draft":false,"prerelease":false,"tag_name":"v0.2.0-nightly.20261101.3"},
205+
{"id":6,"draft":false,"prerelease":false,"tag_name":"notes"},
206+
{"id":9,"draft":true,"prerelease":false,"tag_name":"v0.1.9-fork.2"}]' > "$root/api/releases.json"
207+
if run "$root/work" publish 9 v0.1.9-fork.2 0.1.9-fork.2 && grep -qx "patched 9 draft=false make_latest=true" "$root/api/writes"; then
208+
pass "publish: nightly and non-version tags are other channels and do not block"
187209
else
188-
fail "publish: an older version is published without becoming latest"
210+
fail "publish: nightly and non-version tags are other channels and do not block"
189211
fi
190212

213+
reset_api
214+
echo '[{"id":4,"draft":false,"prerelease":false,"tag_name":"v0.1.8-rc.1"}]' > "$root/api/releases.json"
215+
expect_refused "publish: a stable-channel tag it cannot order fails loudly" "cannot be ordered" \
216+
"$root/work" publish 9 v0.1.9-fork.2 0.1.9-fork.2
217+
191218
reset_api
192219
echo '[{"id":9,"draft":true,"prerelease":false,"tag_name":"v0.1.9-fork.1"}]' > "$root/api/releases.json"
193220
expect_refused "publish: re-checks the tag right before un-drafting" "already exists" "$root/work" publish 9 v0.1.9-fork.1 0.1.9-fork.1
@@ -199,17 +226,56 @@ expect_refused "publish: a failed release listing fails the step" "Could not lis
199226
[[ ! -e "$root/api/writes" ]] || fail "publish: nothing written after a failed listing"
200227

201228
# --- check-archives ----------------------------------------------------------------------------
202-
mkdir -p "$root/arch/good/t3" "$root/arch/bad/t3" "$root/assets-good" "$root/assets-bad" "$root/assets-none"
203-
printf 'x\0const repo = "me/t3code";\0' > "$root/arch/good/t3/t3"
204-
printf 'x\0const repo = "up/t3code";\0' > "$root/arch/bad/t3/t3"
205-
tar -czf "$root/assets-good/t3-0.1.9-fork.1-linux-x64.tar.gz" -C "$root/arch/good" t3
206-
(cd "$root/arch/good" && python3 -I -m zipfile -c "$root/assets-good/t3-0.1.9-fork.1-win-x64.zip" t3)
207-
cp "$root/assets-good/"*.tar.gz "$root/assets-bad/"
208-
(cd "$root/arch/bad" && python3 -I -m zipfile -c "$root/assets-bad/t3-0.1.9-fork.1-win-x64.zip" t3)
209-
if run "$root" check-archives "$root/assets-good"; then pass "check-archives: archives naming this fork pass"; else fail "check-archives: archives naming this fork pass"; fi
210-
expect_refused "check-archives: an archive naming upstream fails" "win-x64.zip does not name me/t3code" "$root" check-archives "$root/assets-bad"
229+
# Layout of scripts/build-cli-archive.ts: <stem>/t3 (t3.exe in the Windows zip) plus <stem>/client/.
230+
# The web client names this fork on every Actions build (upstream's apps/web/vite.config.ts), so it
231+
# must not count; only the program does.
232+
stage() { # stage DIR STEM PROGRAM PROGRAM_REPO CLIENT_REPO
233+
mkdir -p "$1/$2/client/assets"
234+
printf 'x\0const repo = "%s";\0' "$4" > "$1/$2/$3"
235+
printf 'const u = "%s";' "$5" > "$1/$2/client/assets/index.js"
236+
}
237+
pack() { # pack DIR STEM OUT
238+
case "$3" in
239+
*.tar.gz) tar -czf "$3" -C "$1" "$2" ;;
240+
*.zip) (cd "$1" && python3 -I -m zipfile -c "$3" "$2") ;;
241+
esac
242+
}
243+
lin=t3-0.1.9-fork.1-linux-x64 win=t3-0.1.9-fork.1-win-x64
244+
mkdir -p "$root/assets-good" "$root/assets-bad" "$root/assets-repro" "$root/assets-noprog" "$root/assets-none"
245+
stage "$root/arch/good" "$lin" t3 me/t3code me/t3code
246+
stage "$root/arch/good" "$win" t3.exe me/t3code me/t3code
247+
pack "$root/arch/good" "$lin" "$root/assets-good/$lin.tar.gz"
248+
pack "$root/arch/good" "$win" "$root/assets-good/$win.zip"
249+
cp "$root/assets-good/$lin.tar.gz" "$root/assets-bad/"
250+
stage "$root/arch/bad" "$win" t3.exe up/t3code up/t3code
251+
pack "$root/arch/bad" "$win" "$root/assets-bad/$win.zip"
252+
# The review's repro: t3 names upstream, the web client names the fork.
253+
stage "$root/arch/repro" "$lin" t3 up/t3code me/t3code
254+
pack "$root/arch/repro" "$lin" "$root/assets-repro/$lin.tar.gz"
255+
# No program at all, but the client names the fork.
256+
mkdir -p "$root/arch/noprog/$lin/client" && printf '"me/t3code"' > "$root/arch/noprog/$lin/client/x.js"
257+
printf '"me/t3code"' > "$root/arch/noprog/$lin/t3.sh"
258+
pack "$root/arch/noprog" "$lin" "$root/assets-noprog/$lin.tar.gz"
259+
if run "$root" check-archives "$root/assets-good"; then pass "check-archives: archives whose program names this fork pass"; else fail "check-archives: archives whose program names this fork pass"; fi
260+
expect_refused "check-archives: an archive naming upstream fails" "$win/t3.exe in $win.zip does not name me/t3code" "$root" check-archives "$root/assets-bad"
261+
expect_refused "check-archives: t3 names upstream, client/ names the fork -> fails" "$lin/t3 in $lin.tar.gz does not name me/t3code" "$root" check-archives "$root/assets-repro"
262+
expect_refused "check-archives: a missing program fails" "has no $lin/t3" "$root" check-archives "$root/assets-noprog"
211263
expect_refused "check-archives: no archive at all fails" "No CLI archive" "$root" check-archives "$root/assets-none"
212264

265+
# --- check-bundle (apps/server/dist with the web client in dist/client) ------------------------
266+
bundle() { # bundle NAME SERVER_REPO CLIENT_REPO
267+
mkdir -p "$root/dist-$1/client/assets"
268+
printf 'const repo = "%s";' "$2" > "$root/dist-$1/bin.mjs"
269+
printf 'const u = "%s";' "$3" > "$root/dist-$1/client/assets/index.js"
270+
}
271+
bundle good me/t3code me/t3code
272+
bundle repro up/t3code me/t3code
273+
mkdir -p "$root/dist-clientonly/client" && printf '"me/t3code"' > "$root/dist-clientonly/client/x.js"
274+
if run "$root" check-bundle "$root/dist-good"; then pass "check-bundle: a server bundle naming this fork passes"; else fail "check-bundle: a server bundle naming this fork passes"; fi
275+
expect_refused "check-bundle: server names upstream, client/ names the fork -> fails" "outside client/) does not name me/t3code" "$root" check-bundle "$root/dist-repro"
276+
expect_refused "check-bundle: only client/ files -> fails" "no files outside client/" "$root" check-bundle "$root/dist-clientonly"
277+
expect_refused "check-bundle: a missing bundle fails" "No server bundle" "$root" check-bundle "$root/dist-missing"
278+
213279
# --- version order -----------------------------------------------------------------------------
214280
check_gt() {
215281
if (cd "$root" && "$script" version-gt "$1" "$2") 2> /dev/null; then got=gt; else got=not; fi

0 commit comments

Comments
 (0)