fix(release): verify-remote 支持自建 Gitea 并修 Windows tar 盘符 #6

Merged
wangheng merged 1 commits from fix/verify-remote-self-hosted into main 2026-12-02 16:41:49 +08:00
+7 -4
View File
@@ -26,7 +26,7 @@ function npmCliPath() {
return c[0] ?? 'npm'
}
const REPO = 'Aisland-SJL/dsh-worktable'
const REPO = process.env.SLARK_WT_REPO || 'Aisland-SJL/dsh-worktable'
// 参数严格解析:--expect-sha <64位hex> [tag];缺值/非 hex/重复参数/多余 tag 一律拒绝
const args = process.argv.slice(2)
let EXPECT_SHA = null
@@ -49,7 +49,9 @@ for (let i = 0; i < args.length; i++) {
sawTag = true
}
// latest 用特殊路径 /releases/latest/download/<asset>;具体 tag 用 /releases/download/<tag>/<asset>(tag 保留 v 前缀)
const assetBase = TAG === '' ? 'https://github.com/' + REPO + '/releases/latest/download/' : 'https://github.com/' + REPO + '/releases/download/' + TAG + '/'
// SLARK_WT_HOST 可指向自建 Gitea(默认 GitHub 上游)
const HOST = process.env.SLARK_WT_HOST || 'https://github.com'
const assetBase = TAG === '' ? HOST + '/' + REPO + '/releases/latest/download/' : HOST + '/' + REPO + '/releases/download/' + TAG + '/'
function httpGet(url, outFile) {
// PowerShell Invoke-WebRequest:走 WinINET 系统代理(本机网络环境需要);-L 行为由 IWR 自动跟随重定向
@@ -69,7 +71,8 @@ console.log('[verify-remote] GET ' + fixedUrl)
if (!httpGet(fixedUrl, fixedFile)) { console.error('[verify-remote] FAIL: download fixed-name asset'); process.exit(1) }
// 2. 解包读版本,拼版本化 URL 并下载
const listTar = spawnSync('tar', ['-tzf', fixedFile], { encoding: 'utf8' })
// Windows: GNU tar 会把 "C:\..." 的盘符当成 rsh 主机,必须 --force-local
const listTar = spawnSync('tar', ['--force-local', '-tzf', fixedFile], { encoding: 'utf8' })
if (listTar.status !== 0) { console.error('[verify-remote] FAIL: tar -tzf'); process.exit(1) }
const entries = listTar.stdout.split(/\r?\n/).filter(Boolean)
const EXPECTED = ['package/LICENSE','package/README.md','package/cordis.patch.yml','package/dsh.plugin.json','package/lib/client.js','package/lib/index.js','package/package.json']
@@ -77,7 +80,7 @@ const okStruct = entries.length === EXPECTED.length && EXPECTED.every((e) => ent
if (!okStruct) { console.error('[verify-remote] FAIL: structure mismatch: ' + entries.join(',')); process.exit(1) }
console.log('[verify-remote] structure ok (7 files)')
const ext = join(work, 'ext'); mkdirSync(ext, { recursive: true })
const x = spawnSync('tar', ['-xzf', fixedFile, '-C', ext])
const x = spawnSync('tar', ['--force-local', '-xzf', fixedFile, '-C', ext])
if (x.status !== 0) { console.error('[verify-remote] FAIL: tar extract'); process.exit(1) }
const pkg = JSON.parse(readFileSync(join(ext, 'package', 'package.json'), 'utf8'))
const manifest = JSON.parse(readFileSync(join(ext, 'package', 'dsh.plugin.json'), 'utf8'))