Skip to content
Open
120 changes: 120 additions & 0 deletions .github/workflows/build-desktop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Build Desktop Artifacts

on:
push:
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: Windows
os: windows-latest
build_command: pnpm run electron-build-win-ci
artifact_name: easy-dataset-windows
artifact_path: dist/*.exe
- name: macOS
os: macos-latest
build_command: pnpm run electron-build-mac-ci
- name: Linux
os: ubuntu-latest
build_command: pnpm run electron-build-linux-ci
artifact_name: easy-dataset-linux
artifact_path: dist/*.AppImage

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
# pnpm 的版本已经在package.json中标记了

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
cache-dependency-path: pnpm-lock.yaml

- name: Restore Next.js build cache
uses: actions/cache@v4
with:
path: .next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('package.json', 'next.config.js', 'next.config.mjs', 'app/**/*.[jt]s', 'app/**/*.[jt]sx', 'components/**/*.[jt]s', 'components/**/*.[jt]sx', 'lib/**/*.[jt]s', 'lib/**/*.[jt]sx', 'electron/**/*.[jt]s', 'electron/**/*.[jt]sx', 'prisma/schema.prisma', 'public/**/*', 'locales/**/*') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('pnpm-lock.yaml') }}-
${{ runner.os }}-nextjs-

- name: Install Linux build dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
if apt-cache show libasound2t64 >/dev/null 2>&1; then
ASOUND_PACKAGE=libasound2t64
else
ASOUND_PACKAGE=libasound2
fi
sudo apt-get install -y --no-install-recommends \
libarchive-tools \
"$ASOUND_PACKAGE" \
libatk-bridge2.0-0 \
libdrm2 \
libgbm1 \
libgtk-3-0 \
libnotify4 \
libnss3 \
libsecret-1-0 \
libxkbcommon0 \
libxss1 \
rpm \
xdg-utils

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build desktop app
run: ${{ matrix.build_command }}

- name: Separate macOS DMGs
if: runner.os == 'macOS'
run: |
for f in dist/*.dmg; do
if [[ "$f" == *"-arm64.dmg" ]]; then
cp "$f" dist/easy-dataset-macos-arm64.dmg
else
cp "$f" dist/easy-dataset-macos-x64.dmg
fi
done

- name: Upload macOS (arm64)
if: runner.os == 'macOS'
uses: actions/upload-artifact@v4
with:
name: easy-dataset-macos-arm64
path: dist/easy-dataset-macos-arm64.dmg
if-no-files-found: error

- name: Upload macOS (x64)
if: runner.os == 'macOS'
uses: actions/upload-artifact@v4
with:
name: easy-dataset-macos-x64
path: dist/easy-dataset-macos-x64.dmg
if-no-files-found: error

- name: Upload dist artifact (Windows & Linux)
if: runner.os != 'macOS'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: ${{ matrix.artifact_path }}
if-no-files-found: error
14 changes: 1 addition & 13 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
// 最佳实践配置示例
module.exports = {
experimental: {
serverComponentsExternalPackages: ['@opendocsg/pdf2md', 'pdfjs-dist', '@hyzyla/pdfium'],
serverComponentsExternalPackages: ['@opendocsg/pdf2md', '@hyzyla/pdfium', 'pdf2md-js', 'sharp'],
esmExternals: 'loose'
},
webpack: (config, { isServer }) => {
if (!isServer) {
config.externals.push({
unpdf: 'window.unpdf',
'pdfjs-dist': 'window.pdfjsLib'
});
} else {
config.externals.push('pdfjs-dist');
config.externals.push('@hyzyla/pdfium');
}
return config;
}
};
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
"clean-dist": "rm -rf dist",
"electron-build": "pnpm clean-dist && pnpm db:template && prisma db push && next build && electron-builder -mwl",
"electron-build-mac": "pnpm clean-dist && pnpm db:template && prisma db push && next build && electron-builder --mac",
"electron-build-mac-ci": "pnpm clean-dist && pnpm db:template && prisma db push && next build && electron-builder --mac --publish never",
"electron-build-win": "pnpm clean-dist && pnpm db:template && prisma db push && next build && electron-builder --win",
"electron-build-win-ci": "pnpm clean-dist && pnpm db:template && prisma db push && next build && electron-builder --win --publish never",
"electron-build-linux": "pnpm clean-dist && pnpm db:template && prisma db push && next build && electron-builder --linux",
"electron-build-linux-ci": "pnpm clean-dist && pnpm db:template && prisma db push && next build && electron-builder --linux --publish never",
"docker": "docker build -t easy-dataset .",
"prettier": "npx prettier --write ."
},
Expand Down Expand Up @@ -142,6 +145,7 @@
"buildResources": "public",
"output": "dist"
},
"npmRebuild": false,
"asar": true,
"asarUnpack": [
"**/node_modules/sharp/**/*",
Expand Down Expand Up @@ -181,5 +185,6 @@
"allowToChangeInstallationDirectory": true,
"perMachine": false
}
}
},
"packageManager": "pnpm@11.5.2+sha512.71c631e382066efc25625d5cf029075de07b61b37f6e27350fbd84b1bda5864c8c1967adc280776b45c30a715c0359a3be08fef42d5bb09e2b99029979692916"
}
9 changes: 9 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
nodeLinker: hoisted

allowBuilds:
'@prisma/client': true
'@prisma/engines': true
canvas: true
electron: true
prisma: true
sharp: true