From cb2c186f7ff5fd730e1b8afaa5550c36ae49a0ad Mon Sep 17 00:00:00 2001 From: MikiVL Date: Tue, 5 May 2026 23:02:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20GitHub=20Actions=20Windows?= =?UTF-8?q?=20=E6=9E=84=E5=BB=BA=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 .github/workflows/build-windows.yml,在 windows-latest runner 上构建 NSIS 安装包 - 修复 PYTHON_BIN 在 Windows 下需要 .exe 后缀 - 更新 extraResources 为目录式 glob,同时兼容 macOS (main) 和 Windows (main.exe) - package.json 新增 win/nsis electron-builder 目标配置 Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/build-windows.yml | 66 +++++++++++++++++++++++++++++ electron/ipc/templateIpc.js | 6 ++- package.json | 16 ++++++- 3 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/build-windows.yml diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml new file mode 100644 index 0000000..40bd288 --- /dev/null +++ b/.github/workflows/build-windows.yml @@ -0,0 +1,66 @@ +name: Build Windows Installer + +on: + push: + branches: [main, master] + workflow_dispatch: + +jobs: + build-windows: + runs-on: windows-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Disable Windows Defender real-time protection + run: Set-MpPreference -DisableRealtimeMonitoring $true + shell: powershell + + - name: Set up Python 3.11 + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install Python dependencies + run: pip install openpyxl==3.1.2 Pillow==10.3.0 pyinstaller + + - name: Build Python executable + run: > + pyinstaller + --onefile + --name main + --distpath python/dist + --workpath python/build + --specpath python + --hidden-import xl_parser + --hidden-import generator + --collect-all openpyxl + --collect-all et_xmlfile + --collect-all PIL + python/main.py + + - name: Set up Node.js 18 + uses: actions/setup-node@v4 + with: + node-version: "18" + + - name: Install Node dependencies + run: npm ci + + - name: Build renderer + run: npx vite build --config vite.config.mjs + working-directory: renderer + + - name: Build Windows installer + run: npx electron-builder --win --x64 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload installer + uses: actions/upload-artifact@v4 + with: + name: windows-installer + path: dist/*.exe + if-no-files-found: error + retention-days: 30 diff --git a/electron/ipc/templateIpc.js b/electron/ipc/templateIpc.js index 3c9419e..fa6e302 100644 --- a/electron/ipc/templateIpc.js +++ b/electron/ipc/templateIpc.js @@ -8,7 +8,11 @@ const APPDATA_DIR = path.join(app.getPath("userData"), "excel-batch-editor", "te fs.mkdirSync(APPDATA_DIR, { recursive: true }); const PYTHON_BIN = app.isPackaged - ? path.join(process.resourcesPath, "python", "main") + ? path.join( + process.resourcesPath, + "python", + process.platform === "win32" ? "main.exe" : "main" + ) : path.join(__dirname, "../../python/main.py"); function callPython(payload) { diff --git a/package.json b/package.json index b9ad78f..71d44b8 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,9 @@ ], "extraResources": [ { - "from": "python/dist/main", - "to": "python/main" + "from": "python/dist/", + "to": "python", + "filter": ["main", "main.exe"] } ], "mac": { @@ -43,6 +44,17 @@ { "x": 130, "y": 150, "type": "file" }, { "x": 410, "y": 150, "type": "link", "path": "/Applications" } ] + }, + "win": { + "target": [ + { "target": "nsis", "arch": ["x64"] } + ] + }, + "nsis": { + "oneClick": false, + "allowToChangeInstallationDirectory": true, + "createDesktopShortcut": true, + "createStartMenuShortcut": true } }, "devDependencies": {