test: 集成夹具的代理改为读 HTTPS_PROXY,不再写死本机端口
构建与发布 / 单测与集成测试 (push) Waiting to run
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (arm64, linux, ubuntu-24.04-arm) (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (arm64, macos, macos-15) (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (x64, linux, ubuntu-24.04) (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (x64, windows, windows-2025) (push) Blocked by required conditions
构建与发布 / 发布 GitHub Release (push) Blocked by required conditions

This commit is contained in:
lofyer
2026-08-05 20:01:33 +08:00
parent cd28a8ad38
commit 3f8ae81a14
2 changed files with 7 additions and 2 deletions
+3 -1
View File
@@ -75,8 +75,10 @@ app.whenReady().then(async () => {
fs.mkdirSync(path.dirname(epubPath), { recursive: true }); fs.mkdirSync(path.dirname(epubPath), { recursive: true });
if (!fs.existsSync(epubPath)) { if (!fs.existsSync(epubPath)) {
const { fetch: uf, ProxyAgent } = require('undici'); const { fetch: uf, ProxyAgent } = require('undici');
// 代理只在设了 HTTPS_PROXY 时用,写死本机代理会让 CI 直接 ECONNREFUSED
const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || '';
const r = await uf('https://www.gutenberg.org/ebooks/11.epub.noimages', { const r = await uf('https://www.gutenberg.org/ebooks/11.epub.noimages', {
dispatcher: new ProxyAgent({ uri: 'http://127.0.0.1:7890', connectTimeout: 30000 }) dispatcher: proxy ? new ProxyAgent({ uri: proxy, connectTimeout: 30000 }) : undefined
}); });
fs.writeFileSync(epubPath, Buffer.from(await r.arrayBuffer())); fs.writeFileSync(epubPath, Buffer.from(await r.arrayBuffer()));
} }
+4 -1
View File
@@ -18,12 +18,15 @@ async function wait(ms) {
return new Promise((resolve) => setTimeout(resolve, ms)); return new Promise((resolve) => setTimeout(resolve, ms));
} }
// 代理只在设了 HTTPS_PROXY 时用。写死本机代理会让没有代理的环境(CI)
// 直接 ECONNREFUSED,取不到夹具。
async function ensurePdf() { async function ensurePdf() {
if (fs.existsSync(PDF_CACHE)) return; if (fs.existsSync(PDF_CACHE)) return;
fs.mkdirSync(path.dirname(PDF_CACHE), { recursive: true }); fs.mkdirSync(path.dirname(PDF_CACHE), { recursive: true });
const { fetch, ProxyAgent } = require('undici'); const { fetch, ProxyAgent } = require('undici');
const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || '';
const response = await fetch('https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf', { const response = await fetch('https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf', {
dispatcher: new ProxyAgent({ uri: 'http://127.0.0.1:7890', connectTimeout: 30000 }) dispatcher: proxy ? new ProxyAgent({ uri: proxy, connectTimeout: 30000 }) : undefined
}); });
if (!response.ok) throw new Error(`PDF 下载失败:${response.status}`); if (!response.ok) throw new Error(`PDF 下载失败:${response.status}`);
fs.writeFileSync(PDF_CACHE, Buffer.from(await response.arrayBuffer())); fs.writeFileSync(PDF_CACHE, Buffer.from(await response.arrayBuffer()));