mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
Keep dropped-macOS updaters on their last compatible build and explain why (#38777)
* Keep dropped-macOS updaters on their last compatible build and explain why Stamp minimumSystemVersion into every mac update manifest from the built app's LSMinimumSystemVersion, and refuse to publish an ungated release. When the updater withholds a newer release for this macOS, show a one-time notice and say so in Settings and the update card. * Trim the unsupported-Mac notice copy
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env node
|
||||
// Stamps each macOS update manifest with the app's minimum macOS so the updater on an older
|
||||
// macOS stays on its last compatible build instead of installing one that will not launch.
|
||||
// Usage: node gate-mac-update-manifests.mjs <dist-dir>
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { readdirSync, readFileSync, writeFileSync } from 'node:fs'
|
||||
import { join, resolve } from 'node:path'
|
||||
|
||||
// electron-updater compares `minimumSystemVersion` with os.release(), the Darwin version.
|
||||
export function darwinVersionForMacos(macosVersion) {
|
||||
const major = Number.parseInt(String(macosVersion).split('.')[0] ?? '', 10)
|
||||
if (major >= 11 && major <= 15) {
|
||||
return `${major + 9}.0.0`
|
||||
}
|
||||
if (major >= 26) {
|
||||
return `${major - 1}.0.0`
|
||||
}
|
||||
throw new Error(`Unsupported LSMinimumSystemVersion: ${macosVersion}`)
|
||||
}
|
||||
|
||||
export function withMinimumSystemVersion(manifest, darwinVersion) {
|
||||
const lines = manifest
|
||||
.replace(/\n+$/, '')
|
||||
.split('\n')
|
||||
.filter((line) => !line.startsWith('minimumSystemVersion:'))
|
||||
lines.push(`minimumSystemVersion: ${darwinVersion}`)
|
||||
return `${lines.join('\n')}\n`
|
||||
}
|
||||
|
||||
function readMinimumMacosVersion(distDir) {
|
||||
const versions = new Set()
|
||||
for (const entry of readdirSync(distDir, { withFileTypes: true })) {
|
||||
if (!entry.isDirectory() || !entry.name.startsWith('mac')) {
|
||||
continue
|
||||
}
|
||||
for (const app of readdirSync(join(distDir, entry.name))) {
|
||||
if (!app.endsWith('.app')) {
|
||||
continue
|
||||
}
|
||||
const plist = join(distDir, entry.name, app, 'Contents', 'Info.plist')
|
||||
versions.add(
|
||||
execFileSync('plutil', ['-extract', 'LSMinimumSystemVersion', 'raw', plist], {
|
||||
encoding: 'utf8'
|
||||
}).trim()
|
||||
)
|
||||
}
|
||||
}
|
||||
if (versions.size !== 1) {
|
||||
throw new Error(
|
||||
`Expected one LSMinimumSystemVersion across ${distDir}, found ${[...versions].join(', ')}`
|
||||
)
|
||||
}
|
||||
return [...versions][0]
|
||||
}
|
||||
|
||||
function main(distDir) {
|
||||
const macosVersion = readMinimumMacosVersion(distDir)
|
||||
const darwinVersion = darwinVersionForMacos(macosVersion)
|
||||
const manifests = readdirSync(distDir).filter((name) => name.endsWith('-mac.yml'))
|
||||
if (manifests.length === 0) {
|
||||
throw new Error(`No *-mac.yml manifest in ${distDir}`)
|
||||
}
|
||||
for (const name of manifests) {
|
||||
const path = join(distDir, name)
|
||||
writeFileSync(path, withMinimumSystemVersion(readFileSync(path, 'utf8'), darwinVersion))
|
||||
console.log(`${name}: minimumSystemVersion ${darwinVersion} (macOS ${macosVersion})`)
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv[1] && resolve(process.argv[1]) === resolve(import.meta.filename)) {
|
||||
if (!process.argv[2]) {
|
||||
console.error('Usage: node gate-mac-update-manifests.mjs <dist-dir>')
|
||||
process.exit(1)
|
||||
}
|
||||
main(process.argv[2])
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { darwinVersionForMacos, withMinimumSystemVersion } from './gate-mac-update-manifests.mjs'
|
||||
|
||||
describe('darwinVersionForMacos', () => {
|
||||
it('maps macOS releases to the Darwin version os.release() reports', () => {
|
||||
expect(darwinVersionForMacos('12.0')).toBe('21.0.0')
|
||||
expect(darwinVersionForMacos('13.0')).toBe('22.0.0')
|
||||
expect(darwinVersionForMacos('15.4')).toBe('24.0.0')
|
||||
expect(darwinVersionForMacos('26.0')).toBe('25.0.0')
|
||||
expect(() => darwinVersionForMacos('10.15')).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe('withMinimumSystemVersion', () => {
|
||||
it('replaces any earlier gate with exactly one top-level entry', () => {
|
||||
const manifest =
|
||||
'version: 1.5.0\nfiles:\n - url: Orca-1.5.0-mac.zip\nminimumSystemVersion: 21.0.0\n'
|
||||
expect(withMinimumSystemVersion(manifest, '22.0.0')).toBe(
|
||||
'version: 1.5.0\nfiles:\n - url: Orca-1.5.0-mac.zip\nminimumSystemVersion: 22.0.0\n'
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -141,7 +141,11 @@ describe('publishCompleteDraftReleases', () => {
|
||||
.filter(({ name }) => name.startsWith('latest'))
|
||||
.map(({ id, name }) => [
|
||||
`https://api.github.com/repos/stablyai/orca/releases/assets/${id}`,
|
||||
name === 'latest.yml' ? 'path: orca-windows-setup.exe\n' : ''
|
||||
name === 'latest.yml'
|
||||
? 'path: orca-windows-setup.exe\n'
|
||||
: name === 'latest-mac.yml'
|
||||
? 'minimumSystemVersion: 22.0.0\n'
|
||||
: ''
|
||||
])
|
||||
)
|
||||
)
|
||||
|
||||
@@ -103,6 +103,10 @@ export async function verifyRequiredReleaseAssets({ repo, tag, token }) {
|
||||
continue
|
||||
}
|
||||
const manifestText = await fetchAssetText(repo, manifestAsset, token)
|
||||
// Without it, updaters on a dropped macOS install a build that cannot launch.
|
||||
if (manifestName === 'latest-mac.yml' && !/^minimumSystemVersion:/m.test(manifestText)) {
|
||||
throw new Error(`Release ${tag} latest-mac.yml has no minimumSystemVersion gate.`)
|
||||
}
|
||||
for (const referencedName of extractManifestAssetNames(manifestText)) {
|
||||
requiredNames.add(referencedName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user