fix: cleanup electron build script (#1813)

This commit is contained in:
Peng Xiao 2023-04-04 20:40:07 +08:00 committed by GitHub
parent c023d0a2b8
commit 5bd3aa4a80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 150 deletions

View File

@ -29,103 +29,24 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true
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 }}
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
build-macos-arm64:
needs: before-make
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

View File

@ -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`;
},
},
};

View File

@ -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",

View File

@ -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/`;
/// --------
/// --------
/// --------

View File

@ -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