fix(desktop): use full Windows installers within the feed limit

This commit is contained in:
Yun Chan 2026-11-20 21:13:37 +09:00
parent 52df7e7e7b
commit df680e4716
17 changed files with 109 additions and 32 deletions

View file

@ -15,6 +15,7 @@ import { spawnSync } from 'node:child_process'
import { existsSync, readFileSync, readdirSync, rmSync, statSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { supportsWindowsDifferentialDownload } from './lib/desktop-installer-mode.mjs'
const root = join(dirname(fileURLToPath(import.meta.url)), '..', '..')
const desktopDir = join(root, 'apps', 'desktop')
@ -24,6 +25,9 @@ const MAX_UPLOAD_BYTES = 100 * 1024 * 1024
const version = JSON.parse(readFileSync(join(root, 'release', 'product-version.json'), 'utf8')).version
const releaseDir = join(desktopDir, 'release', version)
const appDir = join(releaseDir, 'win-unpacked')
const differentialDownload = supportsWindowsDifferentialDownload(
readFileSync(join(desktopDir, 'electron-builder.yml'), 'utf8'),
)
const builderFlags = ['--config', 'electron-builder.yml', '--publish', 'never', '-c.win.forceCodeSigning=false', '-c.npmRebuild=false']
// 같은 버전을 다시 빌드할 때 이전 산출물(휴대용 zip 등)이 섞여 게시되지 않게 비운다.
@ -39,9 +43,10 @@ run('npx', ['electron-builder', '--prepackaged', appDir, '--win', 'nsis', '--x64
const installer = readdirSync(releaseDir).find((name) => /-Setup-.*\.exe$/.test(name))
if (!installer) fail(`설치본이 없습니다: ${releaseDir}`)
for (const required of [`${installer}.blockmap`, 'latest.yml']) {
if (!existsSync(join(releaseDir, required))) fail(`${required} 가 없습니다: ${releaseDir}`)
}
const blockmap = `${installer}.blockmap`
if (differentialDownload && !existsSync(join(releaseDir, blockmap))) fail(`${blockmap} 가 없습니다: ${releaseDir}`)
if (!differentialDownload && existsSync(join(releaseDir, blockmap))) fail(`full-only 패키지에 ${blockmap} 가 있습니다.`)
if (!existsSync(join(releaseDir, 'latest.yml'))) fail(`latest.yml 가 없습니다: ${releaseDir}`)
if (!existsSync(join(appDir, 'resources', 'app-update.yml'))) fail('app-update.yml 누락')
if (!readFileSync(join(releaseDir, 'latest.yml'), 'utf8').includes(`version: ${version}`)) {
fail('latest.yml 의 버전이 product-version.json 과 다릅니다.')

View file

@ -0,0 +1,4 @@
export function supportsWindowsDifferentialDownload(builderSource) {
const nsisBlock = /^nsis:\r?\n((?:[ \t]+[^\r\n]*(?:\r?\n|$))*)/m.exec(builderSource)?.[1] ?? ''
return !/^[ \t]+differentialPackage:[ \t]*false[ \t]*(?:#.*)?$/m.test(nsisBlock)
}

View file

@ -23,11 +23,12 @@ async function fingerprint(directory, name) {
return { name, size: info.size, sha256: hash.digest('hex') }
}
export async function saveReleaseArtifacts(directory, { version, tagCommit, withRuntime }) {
export async function saveReleaseArtifacts(directory, { version, tagCommit, withRuntime, differentialDownload = true }) {
const names = await readdir(directory)
const installers = names.filter((name) => /-Setup-.*\.exe$/.test(name))
if (installers.length !== 1) throw new Error('Expected exactly one release installer')
const files = [installers[0], `${installers[0]}.blockmap`, 'latest.yml']
const files = [installers[0], 'latest.yml']
if (differentialDownload) files.splice(1, 0, `${installers[0]}.blockmap`)
if (withRuntime) {
const portable = JSON.parse(await readFile(join(directory, 'portable.json'), 'utf8'))
const runtime = JSON.parse(await readFile(join(directory, 'runtime', 'runtime.json'), 'utf8'))
@ -40,7 +41,7 @@ export async function saveReleaseArtifacts(directory, { version, tagCommit, with
}
const artifacts = []
for (const name of new Set(files)) artifacts.push(await fingerprint(directory, name))
const checkpoint = { version, tagCommit, withRuntime, artifacts }
const checkpoint = { version, tagCommit, withRuntime, differentialDownload, artifacts }
const path = join(directory, CHECKPOINT)
await writeFile(`${path}.tmp`, `${JSON.stringify(checkpoint, null, 2)}\n`)
await rename(`${path}.tmp`, path)
@ -51,7 +52,11 @@ export async function verifyReleaseArtifacts(directory, expected) {
for (const field of ['version', 'tagCommit', 'withRuntime']) {
if (checkpoint[field] !== expected[field]) throw new Error(`Release checkpoint ${field} mismatch`)
}
if (!Array.isArray(checkpoint.artifacts) || checkpoint.artifacts.length < 3) {
if (expected.differentialDownload !== undefined && checkpoint.differentialDownload !== expected.differentialDownload) {
throw new Error('Release checkpoint differentialDownload mismatch')
}
const minimumArtifacts = checkpoint.differentialDownload === false ? 2 : 3
if (!Array.isArray(checkpoint.artifacts) || checkpoint.artifacts.length < minimumArtifacts) {
throw new Error('Release checkpoint has no complete artifact set')
}
for (const entry of checkpoint.artifacts) {

View file

@ -26,6 +26,7 @@ import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { loadSigningKey, publicPemOf } from './lib/update-manifest-signature.mjs'
import { saveReleaseArtifacts, verifyReleaseArtifacts } from './lib/release-artifacts.mjs'
import { supportsWindowsDifferentialDownload } from './lib/desktop-installer-mode.mjs'
const root = join(dirname(fileURLToPath(import.meta.url)), '..', '..')
const args = process.argv.slice(2)
@ -122,7 +123,14 @@ if (resume) {
const tag = `v${version}`
const tagCommit = git(['rev-parse', `${tag}^{commit}`])
const releaseDir = join(root, 'apps', 'desktop', 'release', version)
const artifactIdentity = { version, tagCommit, withRuntime }
const artifactIdentity = {
version,
tagCommit,
withRuntime,
differentialDownload: supportsWindowsDifferentialDownload(
readFileSync(join(root, 'apps', 'desktop', 'electron-builder.yml'), 'utf8'),
),
}
const hasCheckpoint = existsSync(join(releaseDir, 'release-artifacts.json'))
// 태그가 생긴 뒤의 실패는 --resume 으로 이어 간다.

View file

@ -7,7 +7,7 @@
//
// 검증 항목:
// 1. *-Setup-*.exe 존재, 크기(4KiB ~ 100MiB), DOS MZ + PE\0\0 헤더 정합성
// 2. *.exe.blockmap 존재 및 gzip 매직 바이트(0x1f 0x8b)
// 2. 차분 모드는 *.exe.blockmap 존재·gzip 매직(0x1f 0x8b), full-only 모드는 부재 확인
// 3. latest.yml 버전 일치, 설치본 파일명 참조 일치, 실제 설치본 SHA-512 재계산 일치
// 4. win-unpacked/*.exe x86_64 PE64(0x8664) 헤더, resources/app-update.yml 정본 피드 URL,
// resources/app.asar Chromium Pickle JSON("files") 헤더 정합성
@ -31,6 +31,7 @@ import { tmpdir } from 'node:os'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { gzipSync } from 'node:zlib'
import { supportsWindowsDifferentialDownload } from './lib/desktop-installer-mode.mjs'
const root = join(dirname(fileURLToPath(import.meta.url)), '..', '..')
const CANONICAL_UPDATE_FEED =
@ -99,7 +100,8 @@ export function verifyInstallerReleaseDir({
releaseDir,
expectedVersion,
publicKeyPem,
requireSignature = false
requireSignature = false,
expectBlockmap = true
}) {
const errors = []
const fail = (cond, code) => {
@ -127,8 +129,9 @@ export function verifyInstallerReleaseDir({
const blockmapPath = join(releaseDir, `${installerName}.blockmap`)
if (!existsSync(blockmapPath)) {
errors.push('blockmap_missing')
if (expectBlockmap) errors.push('blockmap_missing')
} else {
fail(expectBlockmap, 'unexpected_blockmap_for_full_only')
const blockmapBytes = readFileSync(blockmapPath)
fail(
blockmapBytes.length >= 10 && blockmapBytes[0] === 0x1f && blockmapBytes[1] === 0x8b,
@ -275,6 +278,17 @@ function runSelfTest() {
return dir
}
const fullOnlyDir = createValidFixture('full-only')
rmSync(join(fullOnlyDir, `${installerName}.blockmap`))
const fullOnlyResult = verifyInstallerReleaseDir({
releaseDir: fullOnlyDir,
expectedVersion: version,
publicKeyPem,
requireSignature: true,
expectBlockmap: false
})
if (!fullOnlyResult.ok) throw new Error('self_test_full_only_case_failed')
const validDir = createValidFixture('valid')
const okResult = verifyInstallerReleaseDir({
releaseDir: validDir,
@ -373,7 +387,7 @@ function runSelfTest() {
'manifest_signature_invalid'
)
process.stdout.write('[release:installer:smoke] self-test GREEN (2 valid + 8 negative cases)\n')
process.stdout.write('[release:installer:smoke] self-test GREEN (3 valid + 8 negative cases)\n')
} finally {
rmSync(sandbox, { recursive: true, force: true })
}
@ -397,6 +411,9 @@ const summary = verifyInstallerReleaseDir({
releaseDir: targetDir,
expectedVersion: productVersion,
publicKeyPem,
requireSignature: args.includes('--verify-signature')
requireSignature: args.includes('--verify-signature'),
expectBlockmap: supportsWindowsDifferentialDownload(
readFileSync(join(root, 'apps', 'desktop', 'electron-builder.yml'), 'utf8')
)
})
process.stdout.write(`${JSON.stringify(summary, null, 2)}\n`)

View file

@ -2,6 +2,7 @@ import { existsSync, readFileSync } from 'node:fs'
import { createHash, createPublicKey } from 'node:crypto'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { supportsWindowsDifferentialDownload } from './lib/desktop-installer-mode.mjs'
const root = join(dirname(fileURLToPath(import.meta.url)), '..', '..')
// canonical updater feed: Forgejo Generic Package Registry
@ -186,6 +187,10 @@ function validate(surfaces) {
'update_policy_staging_invalid',
)
fail(typeof policy?.killSwitch === 'boolean', 'update_policy_kill_switch_missing')
fail(
supportsWindowsDifferentialDownload(surfaces.builder) || policy?.fullInstallVersionGap === 0,
'windows_full_only_policy_mismatch',
)
fail(
surfaces.updatePolicySource.includes('decideUpdate') &&
surfaces.updatePolicySource.includes('fullInstallVersionGap') &&
@ -430,6 +435,13 @@ if (process.argv.includes('--self-test')) {
},
'forgejo_portable_unsupported_upload_artifact',
)
expectRejected(
surfaces,
(candidate) => {
candidate.updatePolicy.fullInstallVersionGap = 3
},
'windows_full_only_policy_mismatch',
)
let missingDesktopKeyRejected = false
try {
loadSurfaces((path) => {
@ -445,7 +457,7 @@ if (process.argv.includes('--self-test')) {
if (!missingDesktopKeyRejected) {
throw new Error('release_metadata_self_test_failed:desktop_license_public_key_missing')
}
result.negativeCases = 18
result.negativeCases = 19
}
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`)