Managed SSH previously tied remote Agent and Runtime artifacts to desktop packaging and Host activation. Settings now manages verified Linux x64 and arm64 .gbagent packages explicitly, with source-aligned download and update plus offline import and export. Each package contains the signed Agent, pinned Node, and compatible OpenCode Runtime, and project activation never downloads one automatically. Dedicated native CI and a protected release workflow publish deterministic, signed cumulative catalogs to GitHub and Beijing OSS without replacing the desktop Latest release. Desktop packaging is metadata-only, remains independent of Agent artifacts and signing credentials, and Linux desktop releases add RPM installers. The managed SSH path also keeps model credentials in Main, enforces Ask as read-only, verifies signed Agent and Runtime inputs, preserves ACP recovery, and reports Host update cancellation and failures accurately. Release note: 远程项目现可在“设置”中手动下载、更新或离线导入签名 Agent 包,桌面安装包与远程组件发布相互独立;Linux 桌面版同时新增 RPM 安装包。
186 lines
4.9 KiB
JavaScript
186 lines
4.9 KiB
JavaScript
const {
|
|
mkdirSync,
|
|
readFileSync,
|
|
writeFileSync
|
|
} = require('node:fs')
|
|
const { dirname, resolve } = require('node:path')
|
|
const {
|
|
expectedFormatForFile,
|
|
targetDefinitions
|
|
} = require('./aggregate-release.cjs')
|
|
|
|
const supportedTargets = new Map(
|
|
targetDefinitions.map((target) => [
|
|
`${target.platform}-${target.arch}`,
|
|
target
|
|
])
|
|
)
|
|
|
|
function parseArguments(argv) {
|
|
const options = {}
|
|
const optionNames = new Map([
|
|
['--manifest', 'manifest'],
|
|
['--base-url', 'baseUrl'],
|
|
['--output', 'output']
|
|
])
|
|
for (let index = 0; index < argv.length; index += 1) {
|
|
const argument = argv[index]
|
|
const optionName = optionNames.get(argument)
|
|
if (optionName) {
|
|
const value = argv[index + 1]
|
|
if (!value) {
|
|
throw new Error(`${argument} 缺少值`)
|
|
}
|
|
options[optionName] = value
|
|
index += 1
|
|
} else {
|
|
throw new Error(`未知参数:${argument}`)
|
|
}
|
|
}
|
|
if (!options.manifest || !options.baseUrl || !options.output) {
|
|
throw new Error('必须指定 --manifest、--base-url 和 --output')
|
|
}
|
|
return {
|
|
manifest: resolve(options.manifest),
|
|
baseUrl: options.baseUrl,
|
|
output: resolve(options.output)
|
|
}
|
|
}
|
|
|
|
function validateBaseUrl(value) {
|
|
let url
|
|
try {
|
|
url = new URL(value)
|
|
} catch {
|
|
throw new Error(`OSS 基础地址无效:${value}`)
|
|
}
|
|
if (
|
|
url.protocol !== 'https:' ||
|
|
url.username ||
|
|
url.password ||
|
|
url.search ||
|
|
url.hash
|
|
) {
|
|
throw new Error('OSS 基础地址必须是无凭据、查询参数和片段的 HTTPS 地址')
|
|
}
|
|
if (!url.pathname.endsWith('/')) {
|
|
url.pathname += '/'
|
|
}
|
|
return url
|
|
}
|
|
|
|
function assertFile(file, targetKey) {
|
|
if (
|
|
!file ||
|
|
typeof file.name !== 'string' ||
|
|
!/^GoodBuddy-[A-Za-z0-9._-]+$/u.test(file.name) ||
|
|
!Number.isSafeInteger(file.size) ||
|
|
file.size < 1 ||
|
|
typeof file.sha256 !== 'string' ||
|
|
!/^[a-f0-9]{64}$/u.test(file.sha256)
|
|
) {
|
|
throw new Error(`发布文件元数据无效:${targetKey}`)
|
|
}
|
|
}
|
|
|
|
function createSiteRelease(manifest, baseUrlValue) {
|
|
if (
|
|
!manifest ||
|
|
manifest.formatVersion !== 1 ||
|
|
manifest.productName !== 'GoodBuddy' ||
|
|
typeof manifest.version !== 'string' ||
|
|
!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u.test(manifest.version) ||
|
|
!Array.isArray(manifest.targets)
|
|
) {
|
|
throw new Error('聚合发布 manifest 元数据无效')
|
|
}
|
|
const baseUrl = validateBaseUrl(baseUrlValue)
|
|
const seenTargets = new Set()
|
|
const targets = {}
|
|
for (const target of manifest.targets) {
|
|
const key = `${target?.platform}-${target?.arch}`
|
|
const expectedTarget = supportedTargets.get(key)
|
|
const expectedFormats = expectedTarget?.formats
|
|
if (
|
|
!expectedFormats ||
|
|
seenTargets.has(key) ||
|
|
!Array.isArray(target.formats) ||
|
|
!Array.isArray(target.files) ||
|
|
target.formats.length !== expectedFormats.length ||
|
|
!expectedFormats.every(
|
|
(format, index) => target.formats[index] === format
|
|
) ||
|
|
target.files.length !== expectedFormats.length
|
|
) {
|
|
throw new Error(`发布目标元数据无效:${key}`)
|
|
}
|
|
const files = {}
|
|
for (const file of target.files) {
|
|
assertFile(file, key)
|
|
const format = expectedFormatForFile(
|
|
file.name,
|
|
expectedTarget
|
|
)
|
|
if (!format || !expectedFormats.includes(format) || files[format]) {
|
|
throw new Error(`发布文件格式无效:${file.name}`)
|
|
}
|
|
files[format] = {
|
|
name: file.name,
|
|
size: file.size,
|
|
sha256: file.sha256,
|
|
url: new URL(encodeURIComponent(file.name), baseUrl).href
|
|
}
|
|
}
|
|
if (expectedFormats.some((format) => !files[format])) {
|
|
throw new Error(`发布目标文件不完整:${key}`)
|
|
}
|
|
targets[key] = {
|
|
platform: target.platform,
|
|
arch: target.arch,
|
|
files
|
|
}
|
|
seenTargets.add(key)
|
|
}
|
|
if (seenTargets.size !== supportedTargets.size) {
|
|
throw new Error(
|
|
`发布目标数量错误:期望 ${supportedTargets.size},实际 ${seenTargets.size}`
|
|
)
|
|
}
|
|
return {
|
|
formatVersion: 1,
|
|
productName: manifest.productName,
|
|
version: manifest.version,
|
|
targets,
|
|
checksumUrl: new URL('SHA256SUMS', baseUrl).href,
|
|
fallbackUrl: 'https://github.com/mesalogo/goodbuddy/releases/latest'
|
|
}
|
|
}
|
|
|
|
function main(argv = process.argv.slice(2)) {
|
|
const options = parseArguments(argv)
|
|
const manifest = JSON.parse(readFileSync(options.manifest, 'utf8'))
|
|
const siteRelease = createSiteRelease(manifest, options.baseUrl)
|
|
mkdirSync(dirname(options.output), { recursive: true })
|
|
writeFileSync(
|
|
options.output,
|
|
`${JSON.stringify(siteRelease, null, 2)}\n`,
|
|
'utf8'
|
|
)
|
|
console.log(`官网发布索引已生成:${options.output}`)
|
|
}
|
|
|
|
module.exports = {
|
|
createSiteRelease,
|
|
parseArguments,
|
|
validateBaseUrl
|
|
}
|
|
|
|
if (require.main === module) {
|
|
try {
|
|
main()
|
|
} catch (error) {
|
|
console.error(error)
|
|
process.exitCode = 1
|
|
}
|
|
}
|