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.

fix: cleanup electron build script (#1813)

Peng Xiao5bd3aa4a80f7
diff --git a/.github/workflows/release-desktop-app.yml b/.github/workflows/release-desktop-app.yml
index 097e6a6275..78b11bdffc 100644
--- a/.github/workflows/release-desktop-app.yml
+++ b/.github/workflows/release-desktop-app.yml
@@ -29,103 +29,24 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true
-jobs:
- before-make:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v3
- - name: Setup Node.js
- uses: ./.github/actions/setup-node
- with:
- electron-workspace-install: true
-
- - name: before-make
- working-directory: apps/electron
- run: yarn before-make
- env:
- NEXT_PUBLIC_FIREBASE_API_KEY: ${{ secrets.NEXT_PUBLIC_FIREBASE_API_KEY }}
- NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN: ${{ secrets.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN }}
- NEXT_PUBLIC_FIREBASE_PROJECT_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_PROJECT_ID }}
- NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET: ${{ secrets.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET }}
- NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID }}
- NEXT_PUBLIC_FIREBASE_APP_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_APP_ID }}
- NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID }}
-
- - name: Upload Artifact (web-static)
- uses: actions/upload-artifact@v3
- with:
- 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
-
- build-macos-x64:
- needs: before-make
- runs-on: macos-latest
- steps:
- - uses: actions/checkout@v3
- - name: Setup Node.js
- uses: ./.github/actions/setup-node
- with:
- electron-workspace-install: true
-
- - name: install Rust stable
- uses: dtolnay/rust-toolchain@stable
-
- - name: Rust cache
- uses: swatinem/rust-cache@v2
- with:
- workspaces: './packages/octobase-node -> target'
-
- - uses: actions/download-artifact@v3
- 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: build octobase-node
- run: yarn build:octobase-node
- working-directory: apps/electron
-
- - name: move octobase Binary
- run: cp ./packages/octobase-node/octobase.*.node ./apps/electron/dist/layers/main/
-
- - name: Signing By Apple Developer ID
- uses: apple-actions/import-codesign-certs@v2
- with:
- p12-file-base64: ${{ secrets.CERTIFICATES_P12 }}
- p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD }}
-
- - name: make build
- run: yarn make-macos-x64
- working-directory: apps/electron
- env:
- APPLE_ID: ${{ secrets.APPLE_ID }}
- APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
- APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
-
- - name: Save x64 artifacts
- run: |
- mkdir -p builds
- mv apps/electron/out/make/AFFiNE.dmg ./builds/affine-darwin-x64-${{ github.event.inputs.version }}.dmg
-
- - name: Upload Artifact
- uses: actions/upload-artifact@v3
- with:
- name: affine-darwin-x64-builds
- path: builds
+env:
+ APPLE_ID: ${{ secrets.APPLE_ID }}
+ APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
+ APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
+ NEXT_PUBLIC_FIREBASE_API_KEY: ${{ secrets.NEXT_PUBLIC_FIREBASE_API_KEY }}
+ NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN: ${{ secrets.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN }}
+ NEXT_PUBLIC_FIREBASE_PROJECT_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_PROJECT_ID }}
+ NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET: ${{ secrets.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET }}
+ NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID }}
+ NEXT_PUBLIC_FIREBASE_APP_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_APP_ID }}
+ NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID }}
- build-macos-arm64:
- needs: before-make
+jobs:
+ make-macos:
runs-on: macos-latest
+ strategy:
+ matrix:
+ arch: [x64, arm64]
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
@@ -137,6 +58,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable
- name: add arm64 target
+ if: matrix.arch == 'arm64'
run: rustup target add aarch64-apple-darwin
- name: Rust cache
@@ -144,23 +66,6 @@ jobs:
with:
workspaces: './packages/octobase-node -> target'
- - uses: actions/download-artifact@v3
- 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: build octobase-node
- run: yarn build:octobase-node --target=aarch64-apple-darwin
- working-directory: apps/electron
-
- - name: move octobase Binary
- run: cp ./packages/octobase-node/octobase.*.node ./apps/electron/dist/layers/main/
-
- name: Signing By Apple Developer ID
uses: apple-actions/import-codesign-certs@v2
with:
@@ -168,26 +73,21 @@ jobs:
p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD }}
- name: make build
- run: yarn make-macos-arm64
+ run: yarn make-macos-${{ matrix.arch }}
working-directory: apps/electron
- env:
- APPLE_ID: ${{ secrets.APPLE_ID }}
- APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
- APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
- - name: Save arm64 artifacts
+ - name: Save artifacts
run: |
mkdir -p builds
- mv apps/electron/out/make/AFFiNE.dmg ./builds/affine-darwin-arm64-${{ github.event.inputs.version }}.dmg
+ mv apps/electron/out/make/AFFiNE.dmg ./builds/affine-darwin-${{ matrix.arch }}-${{ github.event.inputs.version }}.dmg
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
- name: affine-darwin-arm64-builds
+ name: affine-darwin-${{ matrix.arch }}-builds
path: builds
- build-windows:
- needs: before-make
+ make-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
@@ -204,23 +104,6 @@ jobs:
with:
workspaces: './packages/octobase-node -> target'
- - uses: actions/download-artifact@v3
- 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: build octobase-node
- run: yarn build:octobase-node
- working-directory: apps/electron
-
- - name: move octobase Binary
- run: cp ./packages/octobase-node/octobase.*.node ./apps/electron/dist/layers/main/
-
- name: make build
run: yarn make-windows-x64
working-directory: apps/electron
@@ -237,7 +120,7 @@ jobs:
path: builds
release:
- needs: [build-macos-x64, build-macos-arm64, build-windows]
+ needs: [make-macos, make-windows]
runs-on: ubuntu-latest
steps:
- name: Download MacOS x64 Artifacts
diff --git a/apps/electron/forge.config.js b/apps/electron/forge.config.js
index c0d5c87426..e8aaf14d16 100644
--- a/apps/electron/forge.config.js
+++ b/apps/electron/forge.config.js
@@ -31,4 +31,18 @@ module.exports = {
},
},
],
+ hooks: {
+ generateAssets: async (_, platform, arch) => {
+ const { $ } = await import('zx');
+
+ if (platform === 'darwin' && arch === 'arm64') {
+ // In GitHub Actions runner, MacOS is always x64
+ // we need to manually set TARGET to aarch64-apple-darwin
+ process.env.TARGET = 'aarch64-apple-darwin';
+ }
+
+ // run yarn generate-assets
+ await $`yarn generate-assets`;
+ },
+ },
};
diff --git a/apps/electron/package.json b/apps/electron/package.json
index 84b8449dd3..4a16cb6ae8 100644
--- a/apps/electron/package.json
+++ b/apps/electron/package.json
@@ -13,7 +13,7 @@
"scripts": {
"dev": "cross-env NODE_ENV=development node scripts/dev.mjs",
"prod": "cross-env NODE_ENV=production node scripts/dev.mjs",
- "before-make": "zx scripts/before-make.mjs",
+ "generate-assets": "zx scripts/generate-assets.mjs",
"make": "electron-forge make",
"make-macos-arm64": "electron-forge make --platform=darwin --arch=arm64",
"make-macos-x64": "electron-forge make --platform=darwin --arch=x64",
diff --git a/apps/electron/scripts/before-make.mjs b/apps/electron/scripts/generate-assets.mjs
similarity index 79%
rename from apps/electron/scripts/before-make.mjs
rename to apps/electron/scripts/generate-assets.mjs
index ca6446b26e..1111506040 100644
--- a/apps/electron/scripts/before-make.mjs
+++ b/apps/electron/scripts/generate-assets.mjs
@@ -40,6 +40,17 @@ await fs.move(affineWebOutDir, publicAffineOutDir, { overwrite: true });
await buildLayers();
echo('Build layers done');
+// step 3: build octobase-node
+let buildOctobaseNode = 'yarn workspace @affine/octobase-node build';
+if (process.env.TARGET) {
+ buildOctobaseNode += ` --target=${process.env.TARGET}`;
+}
+await $([buildOctobaseNode]);
+
+// step 4: copy octobase-node to electron dist
+await fs.ensureDir('./apps/electron/dist/layers/main/');
+await $`cp ./packages/octobase-node/octobase.*.node ./apps/electron/dist/layers/main/`;
+
/// --------
/// --------
/// --------
diff --git a/docs/building-desktop-client-app.md b/docs/building-desktop-client-app.md
index e62dc6fcd4..5efeb89afa 100644
--- a/docs/building-desktop-client-app.md
+++ b/docs/building-desktop-client-app.md
@@ -9,37 +9,43 @@
## Prerequisites
-Before you start building AFFiNE Desktop Client Application, please follow the [Tauri getting started > prerequisites guide](https://tauri.app/v1/guides/getting-started/prerequisites) to set up your environment.
+Before you start building AFFiNE Desktop Client Application, please [install Rust toolchain first](https://www.rust-lang.org/learn/get-started).
Note that if you encounter any issues with installing Rust and crates, try following [this guide (zh-CN)](https://course.rs/first-try/slowly-downloading.html) to set up alternative registries.
## Development
-To run AFFiNE Desktop Client Application locally, run the following commands in apps/desktop:
+To run AFFiNE Desktop Client Application locally, run the following commands:
```sh
+# in repo root
yarn install
-yarn build:preload
-yarn dev:app
+yarn dev
+# in apps/electron
+yarn generate-assets
+yarn dev
```
+Now you should see the Electron app window popping up shortly.
+
## Build
-To build the desktop client application, run `yarn build:app` in `apps/desktop`.
+To build the desktop client application, run `yarn make` in `apps/electron`.
+
+Note: you may want to comment out `osxSign` and `osxNotarize` in `forge.config.js` to avoid signing and notarizing the app.
+
Once the build is complete, you can find the paths to the binaries in the terminal output.
```
Finished 2 bundles at:
- /Users/affine/Documents/GitHub/AFFiNE/apps/desktop/src-tauri/target/release/bundle/macos/AFFiNE.app
- /Users/affine/Documents/GitHub/AFFiNE/apps/desktop/src-tauri/target/release/bundle/dmg/AFFiNE_0.0.2_aarch64.dmg
+ › Artifacts available at: <affine-repo>/apps/electron/out/make
```
## CI
-Please refer to `.github/workflows/client-app.yml` for the CI workflow. It will:
+Please refer to `.github/workflows/release-desktop-app.yml` for the CI workflow. It will:
-- run for pull requests and pushes to `master` branch
- build the app for all supported platforms
- upload the artifacts to GitHub Actions