Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

build: fix electron release build process (#2408)

LongYinan135063369098
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 8f99e6e535..cc78b7c6d8 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -337,12 +337,11 @@ jobs:
shell: bash
run: |
rm -rf apps/electron/node_modules/better-sqlite3/build
- yarn workspace @affine/electron rebuild:for-electron
+ yarn workspace @affine/electron rebuild:for-electron --arch=${{ matrix.spec.arch }}
- name: Run desktop tests
if: ${{ matrix.spec.test && matrix.spec.os == 'ubuntu-latest' }}
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- yarn test
- working-directory: apps/electron
+ run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- yarn workspace @affine/electron test
env:
COVERAGE: true
diff --git a/.github/workflows/nightly-build.yml b/.github/workflows/nightly-build.yml
index 5ad0ffe7f1..44af64bf9e 100644
--- a/.github/workflows/nightly-build.yml
+++ b/.github/workflows/nightly-build.yml
@@ -73,28 +73,36 @@ jobs:
name: before-make-web-static
path: apps/electron/resources/web-static
- - name: Upload Artifact (electron dist)
- uses: actions/upload-artifact@v3
- with:
- name: before-make-electron-dist
- path: apps/electron/dist
-
- - name: Upload YML Build Script
- uses: actions/upload-artifact@v3
- with:
- name: release-yml-build-script
- path: apps/electron/scripts/generate-yml.js
-
make-distribution:
environment: production
strategy:
# all combinations: macos-latest x64, macos-latest arm64, windows-latest x64, ubuntu-latest x64
matrix:
spec:
- - { os: macos-latest, platform: macos, arch: x64 }
- - { os: macos-latest, platform: macos, arch: arm64 }
- - { os: ubuntu-latest, platform: linux, arch: x64 }
- - { os: windows-latest, platform: windows, arch: x64 }
+ - {
+ os: macos-latest,
+ platform: darwin,
+ arch: x64,
+ target: x86_64-apple-darwin,
+ }
+ - {
+ os: macos-latest,
+ platform: darwin,
+ arch: arm64,
+ target: aarch64-apple-darwin,
+ }
+ - {
+ os: ubuntu-latest,
+ platform: linux,
+ arch: x64,
+ target: x86_64-unknown-linux-gnu,
+ }
+ - {
+ os: windows-latest,
+ platform: win32,
+ arch: x64,
+ target: x86_64-pc-windows-msvc,
+ }
runs-on: ${{ matrix.spec.os }}
needs:
- before-make
@@ -114,30 +122,33 @@ jobs:
with:
name: before-make-web-static
path: apps/electron/resources/web-static
- - uses: actions/download-artifact@v3
- with:
- name: before-make-electron-dist
- path: apps/electron/dist
+ - name: Rebuild Electron dependences
+ shell: bash
+ run: |
+ rm -rf apps/electron/node_modules/better-sqlite3/build
+ yarn workspace @affine/electron rebuild:for-electron --arch=${{ matrix.spec.arch }}
+
+ - name: Build layers
+ run: yarn workspace @affine/electron build-layers
- name: Signing By Apple Developer ID
- if: ${{ matrix.spec.platform == 'macos' }}
+ if: ${{ matrix.spec.platform == 'darwin' }}
uses: apple-actions/import-codesign-certs@v2
with:
p12-file-base64: ${{ secrets.CERTIFICATES_P12 }}
p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD }}
- name: make
- run: yarn make-${{ matrix.spec.platform }}-${{ matrix.spec.arch }}
- working-directory: apps/electron
+ run: yarn workspace @affine/electron make --platform=${{ matrix.spec.platform }} --arch=${{ matrix.spec.arch }}
- name: Save artifacts (mac)
- if: ${{ matrix.spec.platform == 'macos' }}
+ if: ${{ matrix.spec.platform == 'darwin' }}
run: |
mkdir -p builds
mv apps/electron/out/*/make/*.dmg ./builds/affine-${{ env.BUILD_TYPE }}-macos-${{ matrix.spec.arch }}.dmg
mv apps/electron/out/*/make/zip/darwin/${{ matrix.spec.arch }}/*.zip ./builds/affine-${{ env.BUILD_TYPE }}-macos-${{ matrix.spec.arch }}.zip
- name: Save artifacts (windows)
- if: ${{ matrix.spec.platform == 'windows' }}
+ if: ${{ matrix.spec.platform == 'win32' }}
run: |
mkdir -p builds
mv apps/electron/out/*/make/zip/win32/x64/AFFiNE*-win32-x64-*.zip ./builds/affine-${{ env.BUILD_TYPE }}-windows-x64.zip
@@ -164,37 +175,34 @@ jobs:
runs-on: ubuntu-latest
steps:
+ - uses: actions/checkout@v3
- name: Download Artifacts (macos-x64)
uses: actions/download-artifact@v3
with:
- name: affine-macos-x64-builds
+ name: affine-darwin-x64-builds
path: ./
- name: Download Artifacts (macos-arm64)
uses: actions/download-artifact@v3
with:
- name: affine-macos-arm64-builds
+ name: affine-darwin-arm64-builds
path: ./
- name: Download Artifacts (windows-x64)
uses: actions/download-artifact@v3
with:
- name: affine-windows-x64-builds
+ name: affine-win32-x64-builds
path: ./
- name: Download Artifacts (linux-x64)
uses: actions/download-artifact@v3
with:
name: affine-linux-x64-builds
path: ./
- - name: Download Artifacts
- uses: actions/download-artifact@v3
- with:
- name: release-yml-build-script
- path: ./
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Generate Release yml
run: |
+ cp ./apps/electron/scripts/generate-yml.js .
node generate-yml.js
env:
RELEASE_VERSION: ${{ needs.set-build-version.outputs.version }}
diff --git a/.github/workflows/release-desktop-app.yml b/.github/workflows/release-desktop-app.yml
index 9d1b8e93fd..0f6418d1ad 100644
--- a/.github/workflows/release-desktop-app.yml
+++ b/.github/workflows/release-desktop-app.yml
@@ -49,8 +49,7 @@ jobs:
- name: Setup Node.js
uses: ./.github/actions/setup-node
- name: generate-assets
- working-directory: apps/electron
- run: yarn generate-assets
+ run: yarn workspace @affine/electron generate-assets
env:
NEXT_PUBLIC_FIREBASE_API_KEY: ${{ secrets.NEXT_PUBLIC_FIREBASE_API_KEY }}
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN: ${{ secrets.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN }}
@@ -75,18 +74,6 @@ jobs:
name: before-make-web-static
path: apps/electron/resources/web-static
- - name: Upload Artifact (electron dist)
- uses: actions/upload-artifact@v3
- with:
- name: before-make-electron-dist
- path: apps/electron/dist
-
- - name: Upload YML Build Script
- uses: actions/upload-artifact@v3
- with:
- name: release-yml-build-script
- path: apps/electron/scripts/generate-yml.js
-
make-distribution:
environment: ${{ github.ref_name == 'master' && 'production' || 'development' }}
strategy:
@@ -95,13 +82,13 @@ jobs:
spec:
- {
os: macos-latest,
- platform: macos,
+ platform: darwin,
arch: x64,
target: x86_64-apple-darwin,
}
- {
os: macos-latest,
- platform: macos,
+ platform: darwin,
arch: arm64,
target: aarch64-apple-darwin,
}
@@ -113,7 +100,7 @@ jobs:
}
- {
os: windows-latest,
- platform: windows,
+ platform: win32,
arch: x64,
target: x86_64-pc-windows-msvc,
}
@@ -136,30 +123,34 @@ jobs:
with:
name: before-make-web-static
path: apps/electron/resources/web-static
- - uses: actions/download-artifact@v3
- with:
- name: before-make-electron-dist
- path: apps/electron/dist
+
+ - name: Rebuild Electron dependences
+ shell: bash
+ run: |
+ rm -rf apps/electron/node_modules/better-sqlite3/build
+ yarn workspace @affine/electron rebuild:for-electron --arch=${{ matrix.spec.arch }}
+
+ - name: Build layers
+ run: yarn workspace @affine/electron build-layers
- name: Signing By Apple Developer ID
- if: ${{ matrix.spec.platform == 'macos' }}
+ if: ${{ matrix.spec.platform == 'darwin' }}
uses: apple-actions/import-codesign-certs@v2
with:
p12-file-base64: ${{ secrets.CERTIFICATES_P12 }}
p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD }}
- name: make
- run: yarn make-${{ matrix.spec.platform }}-${{ matrix.spec.arch }}
- working-directory: apps/electron
+ run: yarn workspace @affine/electron make --platform=${{ matrix.spec.platform }} --arch=${{ matrix.spec.arch }}
- name: Save artifacts (mac)
- if: ${{ matrix.spec.platform == 'macos' }}
+ if: ${{ matrix.spec.platform == 'darwin' }}
run: |
mkdir -p builds
mv apps/electron/out/*/make/*.dmg ./builds/affine-${{ env.BUILD_TYPE }}-macos-${{ matrix.spec.arch }}.dmg
mv apps/electron/out/*/make/zip/darwin/${{ matrix.spec.arch }}/*.zip ./builds/affine-${{ env.BUILD_TYPE }}-macos-${{ matrix.spec.arch }}.zip
- name: Save artifacts (windows)
- if: ${{ matrix.spec.platform == 'windows' }}
+ if: ${{ matrix.spec.platform == 'win32' }}
run: |
mkdir -p builds
mv apps/electron/out/*/make/zip/win32/x64/AFFiNE*-win32-x64-*.zip ./builds/affine-${{ env.BUILD_TYPE }}-windows-x64.zip
@@ -184,37 +175,36 @@ jobs:
runs-on: ubuntu-latest
steps:
+ - uses: actions/checkout@v3
- name: Download Artifacts (macos-x64)
uses: actions/download-artifact@v3
with:
- name: affine-macos-x64-builds
+ name: affine-darwin-x64-builds
path: ./
- name: Download Artifacts (macos-arm64)
uses: actions/download-artifact@v3
with:
- name: affine-macos-arm64-builds
+ name: affine-darwin-arm64-builds
path: ./
- name: Download Artifacts (windows-x64)
uses: actions/download-artifact@v3
with:
- name: affine-windows-x64-builds
+ name: affine-win32-x64-builds
path: ./
- name: Download Artifacts (linux-x64)
uses: actions/download-artifact@v3
with:
name: affine-linux-x64-builds
path: ./
- - name: Download Artifacts
- uses: actions/download-artifact@v3
- with:
- name: release-yml-build-script
- path: ./
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Generate Release yml
run: |
- RELEASE_VERSION=${{ github.event.inputs.version }} node generate-yml.js
+ cp ./apps/electron/scripts/generate-yml.js .
+ node generate-yml.js
+ env:
+ RELEASE_VERSION: ${{ github.event.inputs.version }}
- name: Create Release Draft
uses: softprops/action-gh-release@v1
env:
diff --git a/apps/electron/package.json b/apps/electron/package.json
index 122fafbf2d..4d739f09b5 100644
--- a/apps/electron/package.json
+++ b/apps/electron/package.json
@@ -18,10 +18,6 @@
"generate-main-exposed-meta": "zx scripts/generate-main-exposed-meta.mjs",
"package": "electron-forge package",
"make": "electron-forge make",
- "make-macos-arm64": "electron-forge make --platform=darwin --arch=arm64",
- "make-macos-x64": "electron-forge make --platform=darwin --arch=x64",
- "make-windows-x64": "electron-forge make --platform=win32 --arch=x64",
- "make-linux-x64": "electron-forge make --platform=linux --arch=x64",
"rebuild:for-unit-test": "yarn rebuild better-sqlite3",
"rebuild:for-electron": "yarn electron-rebuild",
"test": "playwright test"
@@ -32,6 +28,7 @@
"main": "./dist/layers/main/index.js",
"devDependencies": {
"@affine-test/kit": "workspace:*",
+ "@affine/native": "workspace:*",
"@electron-forge/cli": "^6.1.1",
"@electron-forge/core": "^6.1.1",
"@electron-forge/core-utils": "^6.1.1",
@@ -59,7 +56,6 @@
"zx": "^7.2.2"
},
"dependencies": {
- "@affine/native": "workspace:*",
"better-sqlite3": "^8.3.0",
"chokidar": "^3.5.3",
"electron-updater": "^5.3.0",
diff --git a/apps/electron/scripts/common.mjs b/apps/electron/scripts/common.mjs
index 9899d5baa7..d4e72613be 100644
--- a/apps/electron/scripts/common.mjs
+++ b/apps/electron/scripts/common.mjs
@@ -39,19 +39,14 @@ export const config = () => {
bundle: true,
target: `node${NODE_MAJOR_VERSION}`,
platform: 'node',
- external: [
- 'electron',
- 'yjs',
- 'better-sqlite3',
- 'electron-updater',
- '@affine/native-*',
- ],
+ external: ['electron', 'yjs', 'better-sqlite3', 'electron-updater'],
define: define,
format: 'cjs',
loader: {
'.node': 'copy',
},
assetNames: '[name]',
+ treeShaking: true,
},
preload: {
entryPoints: [resolve(root, './layers/preload/src/index.ts')],
diff --git a/apps/electron/scripts/generate-assets.mjs b/apps/electron/scripts/generate-assets.mjs
index abf5c2f384..70b35d4683 100644
--- a/apps/electron/scripts/generate-assets.mjs
+++ b/apps/electron/scripts/generate-assets.mjs
@@ -32,9 +32,6 @@ if (process.platform === 'win32') {
cd(repoRootDir);
-// step 1: build electron resources
-await $`yarn workspace @affine/electron build-layers`;
-
// step 2: build web (nextjs) dist
if (!process.env.SKIP_WEB_BUILD) {
process.env.ENABLE_LEGACY_PROVIDER = 'false';