Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(open-knowledge): retry desktop-release publish, sweep stuck drafts (#2534)

Andrew Mikofalvy730879ad1e48
diff --git a/.github/workflows/desktop-release-draft-janitor.yml b/.github/workflows/desktop-release-draft-janitor.yml
new file mode 100644
index 000000000..cd5262653
--- /dev/null
+++ b/.github/workflows/desktop-release-draft-janitor.yml
@@ -0,0 +1,105 @@
+name: Draft release janitor
+
+# Sweeps orphaned draft GitHub Releases off inkeep/open-knowledge.
+#
+# release.yml creates every beta as `--draft --prerelease`; promote-stable.yml
+# does the same for stable. desktop-release.yml flips `draft=false` ONLY after
+# the signed DMG + channel manifest (beta-mac.yml / latest-mac.yml) upload
+# succeeds — the draft gate keeps a manifest-less release out of the auto-update
+# .atom feed. When that build fails (both historical cases were transient:
+# an Electron-runtime-download EOF and a GitHub-upload 403, neither retried
+# at the time), the release is stranded as a draft. It never entered the feed,
+# so auto-update never saw it, but it stays pinned to the top of the web
+# releases page forever while the next cut rolls forward past it.
+#
+# This janitor removes such orphans on a schedule. It is deliberately
+# conservative: it deletes a stuck draft beta ONLY once a published STABLE
+# release covers that beta's X.Y.Z cycle. That gate is load-bearing — a beta's
+# changelog delta lives ONLY in its GitHub Release body, and promote-stable.yml
+# aggregates the whole cycle's beta bodies (by tag, via `gh release view`) into
+# the stable release notes at promotion time (packages/*/CHANGELOG.md no longer
+# accumulates per-beta under the zero-commit-bump cadence). Deleting a beta
+# before its cycle is promoted would drop that increment from the stable
+# changelog (it renders as "release body unavailable"). Once the cycle's stable
+# exists, every in-range beta body has already been aggregated (and a later beta
+# on an already-promoted base is never aggregated by any future stable), so the
+# body is safe to reap. Drafts on a not-yet-promoted cycle are left for a human
+# to re-run desktop-release.yml against or promote. The git TAG is always kept
+# (npm-provenance source ref + version lineage); only the Release object goes.
+
+on:
+ schedule:
+ # Every 6 hours, off the hour to avoid the top-of-hour scheduler surge.
+ - cron: "37 */6 * * *"
+ # Manual sweep, e.g. right after a known stuck-draft incident.
+ workflow_dispatch:
+
+permissions:
+ # contents: write is required to delete Release objects via the API.
+ contents: write
+
+concurrency:
+ group: desktop-release-draft-janitor
+ cancel-in-progress: false
+
+jobs:
+ sweep:
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ steps:
+ - name: Delete superseded stuck draft releases
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: |
+ set -euo pipefail
+
+ ALL=$(gh release list --repo "$GITHUB_REPOSITORY" --limit 300 \
+ --json tagName,isDraft,isPrerelease,createdAt)
+
+ # Highest published STABLE (non-draft AND non-prerelease) version,
+ # bare (leading v stripped). We gate on a STABLE, not merely a newer
+ # beta: a stuck draft beta's body must survive until its cycle has
+ # been promoted to stable (see header). `sort -V` is GNU coreutils on
+ # ubuntu-latest; both operands here are bare X.Y.Z (no prerelease
+ # suffix), so version-sort ordering is unambiguous.
+ maxstable=$(printf '%s' "$ALL" \
+ | jq -r '.[] | select((.isDraft | not) and (.isPrerelease | not)) | .tagName' \
+ | sed 's/^v//' \
+ | sort -V | tail -n1)
+ if [ -z "${maxstable}" ]; then
+ echo "No published stable release yet; keeping all drafts (their bodies feed the first stable's changelog)."
+ exit 0
+ fi
+ echo "Highest published stable version: ${maxstable}"
+
+ # Candidates: draft AND prerelease AND older than 90 min. The age
+ # gate must exceed desktop-release.yml's job budget (75 min) so a
+ # draft that a still-running per-tag build will promote is never
+ # swept — 5400s leaves margin above the timeout.
+ candidates=$(printf '%s' "$ALL" | jq -r --argjson maxage 5400 '
+ .[]
+ | select(.isDraft and .isPrerelease)
+ | select((now - (.createdAt | fromdateiso8601)) > $maxage)
+ | .tagName')
+
+ if [ -z "${candidates}" ]; then
+ echo "No stuck draft prereleases older than 90 min; nothing to sweep."
+ exit 0
+ fi
+
+ printf '%s\n' "${candidates}" | while IFS= read -r tag; do
+ [ -z "${tag}" ] && continue
+ base="${tag#v}"; base="${base%-beta.*}" # vX.Y.Z-beta.N -> X.Y.Z
+ # Delete only once a published stable covers this beta's cycle,
+ # i.e. base <= maxstable. top==maxstable holds when base < maxstable
+ # (older closed cycle) and when base == maxstable (this cycle's
+ # stable exists). base > maxstable => cycle not yet promoted => keep.
+ top=$(printf '%s\n%s\n' "${base}" "${maxstable}" | sort -V | tail -n1)
+ if [ "${top}" = "${maxstable}" ]; then
+ echo "::notice::Sweeping stuck draft ${tag}: its ${base} cycle is closed (stable ${maxstable} exists), so its body is already aggregated. Git tag kept."
+ gh release delete "${tag}" --repo "$GITHUB_REPOSITORY" --yes
+ else
+ echo "Keeping ${tag}: cycle ${base} not yet promoted (newest stable ${maxstable}) — its body still feeds the future stable changelog. Re-run desktop-release.yml or promote it."
+ fi
+ done
+ echo "Draft-release janitor sweep complete."
diff --git a/.github/workflows/desktop-release.yml b/.github/workflows/desktop-release.yml
index b961b3127..e59a73acc 100644
--- a/.github/workflows/desktop-release.yml
+++ b/.github/workflows/desktop-release.yml
@@ -95,10 +95,12 @@ jobs:
# electron-builder compiles `build/okglass.icon` → `Assets.car` via
# `actool`, which only ships with Xcode 26+.
runs-on: macos-26
- # 45 min budget — same as desktop-build.yml. Signed builds add 2-5 min
- # of notary round-trip over the unsigned path; 45 min leaves headroom
- # for cold caches and notary queue spikes.
- timeout-minutes: 45
+ # 75 min budget. A signed build + notary round-trip is ~20-30 min; the
+ # build+publish step retries once on a transient failure (see below), so
+ # the worst case is two full signed builds back-to-back. 75 min covers
+ # that plus cold caches and notary queue spikes. desktop-build.yml has no
+ # retry and stays at 45.
+ timeout-minutes: 75
steps:
# On `repository_dispatch`, check out the ref supplied by the upstream
# workflow via `client_payload.ref` — that's the exact commit
@@ -194,9 +196,11 @@ jobs:
# Strip leading `v` (electron-builder + npm want bare semver).
VERSION="${RELEASE_TAG#v}"
if [[ "$VERSION" == *-beta.* ]]; then
- echo "channel=beta" >> "$GITHUB_OUTPUT"
- echo "release_type=prerelease" >> "$GITHUB_OUTPUT"
- echo "version=$VERSION" >> "$GITHUB_OUTPUT"
+ {
+ echo "channel=beta"
+ echo "release_type=prerelease"
+ echo "version=$VERSION"
+ } >> "$GITHUB_OUTPUT"
echo "::notice::Building BETA channel from tag $RELEASE_TAG"
elif [[ "$VERSION" == *-beta ]]; then
# The `*-beta.*` glob above requires a dot after `beta` (i.e.
@@ -210,9 +214,11 @@ jobs:
echo "::error::Unsupported prerelease ID in tag $RELEASE_TAG — only -beta.N is supported. See packages/desktop/README.md beta-channel runbook for the supported lifecycle."
exit 1
else
- echo "channel=latest" >> "$GITHUB_OUTPUT"
- echo "release_type=release" >> "$GITHUB_OUTPUT"
- echo "version=$VERSION" >> "$GITHUB_OUTPUT"
+ {
+ echo "channel=latest"
+ echo "release_type=release"
+ echo "version=$VERSION"
+ } >> "$GITHUB_OUTPUT"
echo "::notice::Building LATEST channel from tag $RELEASE_TAG"
fi
@@ -359,10 +365,43 @@ jobs:
# bundled SKILL.md asset's metadata.version; those are baked in
# at Build time, so the workspace-wide on-disk override step
# above is what makes them match the tag. See PRD-6650.
- bun run build:desktop && bunx electron-builder --mac --publish always \
- --config.extraMetadata.version=${{ steps.channel.outputs.version }} \
- --config.publish.channel=${{ steps.channel.outputs.channel }} \
- --config.publish.releaseType=${{ steps.channel.outputs.release_type }}
+ #
+ # Retry the build+publish once on failure. The two observed
+ # stuck-draft causes were both transient and un-retried: a bare EOF
+ # fetching the Electron runtime zip during packaging (app-builder's
+ # DownloadNoRetry path aborts on a single dropped connection), and a
+ # 403 from uploads.github.com mid-publish after a fully successful
+ # sign+notarize (concurrent-upload throttling). Either aborts the run
+ # before the Promote step and orphans the draft release. Re-running
+ # the whole invocation is idempotent: electron-builder deletes then
+ # re-uploads same-named assets on republish, so a partial asset set
+ # left by a failed first attempt is overwritten, not duplicated. A
+ # persistent (non-transient) failure still exits non-zero after the
+ # final attempt and lands in the Warn-on-stuck-draft path + the
+ # scheduled draft-release janitor.
+ set -uo pipefail
+ attempt=1
+ max_attempts=2
+ while true; do
+ echo "::group::electron-builder publish attempt ${attempt}/${max_attempts}"
+ if bun run build:desktop && bunx electron-builder --mac --publish always \
+ --config.extraMetadata.version=${{ steps.channel.outputs.version }} \
+ --config.publish.channel=${{ steps.channel.outputs.channel }} \
+ --config.publish.releaseType=${{ steps.channel.outputs.release_type }}; then
+ echo "::endgroup::"
+ echo "electron-builder succeeded on attempt ${attempt}."
+ break
+ fi
+ echo "::endgroup::"
+ if [ "${attempt}" -ge "${max_attempts}" ]; then
+ echo "::error::electron-builder failed after ${max_attempts} attempts."
+ exit 1
+ fi
+ backoff=$((attempt * 30))
+ echo "::warning::electron-builder attempt ${attempt} failed; retrying in ${backoff}s (transient sign/notarize/upload/download flakes are retried once)."
+ sleep "${backoff}"
+ attempt=$((attempt + 1))
+ done
# Closes the publish-window race: release.yml / promote-stable.yml
# create the GitHub Release as --draft so it stays out of the .atom