Files
WeHub Mirror 6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
WeHub snapshot of cb28d14c6f2c081de7a0d8729a8c816c9adef67a
2026-08-10 11:17:50 +08:00

120 lines
4.7 KiB
TypeScript

/**
* Per-environment desktop update feed resolution.
*
* Installed desktop shells ask the Sim deployment they are pointed at —
* `GET <origin>/api/desktop/update/latest-mac.yml` — instead of a global
* GitHub feed, so each environment independently controls which shell build
* its clients are offered. The environment IS the channel:
*
* - dev.sim.ai → `alpha` (per-push prerelease builds from `dev`)
* - staging.sim.ai → `beta` (per-push prerelease builds from `staging`)
* - sim.ai + self-hosted/unknown → `latest` (stable vX.Y.Z releases only)
*
* Artifacts stay on GitHub Releases (dumb storage); the feed route picks the
* right release for its channel and serves that release's electron-updater
* manifest with download URLs rewritten to absolute GitHub asset URLs.
*
* Channels are strictly isolated: alpha serves only `-alpha.` prereleases,
* beta only `-beta.` prereleases, and `latest` only stable releases. Builds
* carry per-channel app identity (Sim Dev / Sim Staging / Sim), so serving a
* stable prod-identity artifact to a dev shell would offer an update
* Squirrel.Mac cannot apply (bundle-id mismatch) — each channel only ever
* moves forward on its own artifacts.
*/
import { compareVersions } from '@/lib/desktop/min-version'
export const DESKTOP_RELEASE_REPO = 'simstudioai/sim'
export type DesktopUpdateChannel = 'alpha' | 'beta' | 'latest'
/** Maps a deployment hostname to its desktop update channel. */
export function channelForHostname(hostname: string): DesktopUpdateChannel {
const host = hostname.toLowerCase()
if (host === 'dev.sim.ai' || host.endsWith('.dev.sim.ai')) {
return 'alpha'
}
if (host === 'staging.sim.ai' || host.endsWith('.staging.sim.ai')) {
return 'beta'
}
return 'latest'
}
/** The channel a specific version belongs to, from its prerelease tag. */
export function channelOfVersion(version: string): DesktopUpdateChannel {
if (version.includes('-alpha.')) return 'alpha'
if (version.includes('-beta.')) return 'beta'
return 'latest'
}
/**
* The manifest asset every desktop build uploads. electron-builder's GitHub
* provider always names it `latest-mac.yml` regardless of the version's
* prerelease tag (channels are a generic-provider concept); which channel a
* release belongs to is carried entirely by its tag.
*/
export const MANIFEST_ASSET_NAME = 'latest-mac.yml'
/** The subset of the GitHub releases API the feed needs. */
export interface DesktopReleaseCandidate {
tag_name: string
draft: boolean
prerelease: boolean
assets?: Array<{ name: string; browser_download_url: string }>
}
/**
* Picks the newest release of the channel's own kind. Channels never see
* another channel's artifacts (see module docs). Releases without their
* updater manifest asset are skipped — a release created before its build
* finished (or whose build failed) must not take the channel down. Returns
* null when nothing qualifies.
*/
export function selectReleaseForChannel(
releases: DesktopReleaseCandidate[],
channel: DesktopUpdateChannel
): DesktopReleaseCandidate | null {
let best: DesktopReleaseCandidate | null = null
let bestVersion = ''
for (const release of releases) {
if (release.draft) continue
const version = release.tag_name.replace(/^v/, '')
if (channelOfVersion(version) !== channel) continue
// Defense in depth: a bare vX.Y.Z tag manually marked "pre-release" on
// GitHub must not reach stable clients.
if (channel === 'latest' && release.prerelease) continue
if (release.assets && !release.assets.some((asset) => asset.name === MANIFEST_ASSET_NAME)) {
continue
}
if (best === null) {
const valid = compareVersions(version, '0.0.0')
if (valid === null) continue
best = release
bestVersion = version
continue
}
const comparison = compareVersions(version, bestVersion)
if (comparison !== null && comparison > 0) {
best = release
bestVersion = version
}
}
return best
}
/**
* Rewrites the manifest's relative artifact references (`url:` entries and
* the legacy top-level `path:`) to absolute GitHub release asset URLs, so
* the shell downloads artifacts (and their `.blockmap`s, resolved relative
* to the file URL) straight from GitHub while the feed itself stays served
* by this deployment.
*/
export function rewriteManifestUrls(manifest: string, tag: string): string {
const base = `https://github.com/${DESKTOP_RELEASE_REPO}/releases/download/${tag}/`
return manifest.replace(/^(\s*(?:-\s*)?(?:url|path):\s*)(\S+)\s*$/gm, (line, prefix, value) => {
if (value.startsWith('http://') || value.startsWith('https://')) {
return line
}
return `${prefix}${base}${encodeURIComponent(value)}`
})
}