diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml new file mode 100644 index 0000000..0eac85e --- /dev/null +++ b/.github/workflows/build-release.yml @@ -0,0 +1,55 @@ +name: Build release packages + +on: + workflow_dispatch: + push: + tags: + - "v*" + +permissions: + contents: read + +jobs: + package: + name: Package ${{ matrix.platform }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - platform: windows + os: windows-latest + command: dist:win + - platform: linux + os: ubuntu-22.04 + command: dist:linux + - platform: macos + os: macos-14 + command: dist:mac + + env: + CSC_IDENTITY_AUTO_DISCOVERY: "false" + + steps: + - name: Check out source + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Build packages + run: npm run ${{ matrix.command }} + + - name: Upload packages + uses: actions/upload-artifact@v4 + with: + name: ArborFlow-${{ matrix.platform }} + path: release/${{ matrix.platform }}/ + if-no-files-found: error + compression-level: 0 diff --git a/README.md b/README.md index 6299e37..b128d20 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,9 @@ npm run dist:linux npm run dist:mac ``` -输出目录为 `release/`。建议在目标操作系统上执行对应打包命令,特别是 macOS 签名、公证以及不同 CPU 架构的构建。 +输出按平台分别保存到 `release/windows/`、`release/linux/` 和 `release/macos/`。建议在目标操作系统上执行对应打包命令,特别是 macOS 签名、公证以及不同 CPU 架构的构建。 + +仓库内的 `.github/workflows/build-release.yml` 会在 Windows、Ubuntu 和 macOS 原生运行器上并行打包。可在 GitHub Actions 中手动运行,也会在推送 `v*` 标签时自动执行并上传三个独立平台产物。 可用的默认目标: @@ -247,6 +249,9 @@ npm run icon:render | `npm run dist:win` | 构建 Windows 包 | | `npm run dist:linux` | 构建 Linux 包 | | `npm run dist:mac` | 构建 macOS 包 | +| `npm run pack:win` | 不重复构建前端,直接生成 Windows 包 | +| `npm run pack:linux` | 不重复构建前端,直接生成 Linux 包 | +| `npm run pack:mac` | 不重复构建前端,直接生成 macOS 包 | ## 项目结构 diff --git a/package.json b/package.json index 9a8116e..8b3dbc4 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,13 @@ "dev": "concurrently -k \"vite --host 127.0.0.1\" \"wait-on http://127.0.0.1:5173 && electron .\"", "build": "tsc -b && vite build", "preview": "vite preview --host 127.0.0.1", - "dist": "npm run build && electron-builder", - "dist:linux": "npm run build && electron-builder --linux", - "dist:mac": "npm run build && electron-builder --mac", - "dist:win": "npm run build && electron-builder --win", + "dist": "node scripts/dist-current.cjs", + "dist:linux": "npm run build && npm run pack:linux", + "dist:mac": "npm run build && npm run pack:mac", + "dist:win": "npm run build && npm run pack:win", + "pack:linux": "electron-builder --linux --config.directories.output=release/linux", + "pack:mac": "electron-builder --mac --config.directories.output=release/macos", + "pack:win": "electron-builder --win --config.directories.output=release/windows", "mock:monitor": "node scripts/mock-monitor.cjs", "icon:render": "electron scripts/render-icon.cjs" }, diff --git a/scripts/dist-current.cjs b/scripts/dist-current.cjs new file mode 100644 index 0000000..fb90a76 --- /dev/null +++ b/scripts/dist-current.cjs @@ -0,0 +1,25 @@ +const { spawnSync } = require('node:child_process'); + +const platformTarget = { + darwin: 'mac', + linux: 'linux', + win32: 'win', +}; + +const target = platformTarget[process.platform]; +if (!target) { + console.error(`Unsupported packaging platform: ${process.platform}`); + process.exit(1); +} + +const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm'; +const result = spawnSync(npmCommand, ['run', `dist:${target}`], { + stdio: 'inherit', +}); + +if (result.error) { + console.error(result.error.message); + process.exit(1); +} + +process.exit(result.status ?? 1);