fix: cleanup electron build script (#1813)

This commit is contained in:
Peng Xiao
2023-04-04 07:40:07 -05:00
committed by GitHub
parent c023d0a2b8
commit 5bd3aa4a80
5 changed files with 64 additions and 150 deletions
+23 -140
View File
@@ -29,103 +29,24 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true 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: jobs:
before-make: make-macos:
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
runs-on: macos-latest runs-on: macos-latest
strategy:
matrix:
arch: [x64, arm64]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Setup Node.js - name: Setup Node.js
@@ -137,6 +58,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable uses: dtolnay/rust-toolchain@stable
- name: add arm64 target - name: add arm64 target
if: matrix.arch == 'arm64'
run: rustup target add aarch64-apple-darwin run: rustup target add aarch64-apple-darwin
- name: Rust cache - name: Rust cache
@@ -144,23 +66,6 @@ jobs:
with: with:
workspaces: './packages/octobase-node -> target' 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 - name: Signing By Apple Developer ID
uses: apple-actions/import-codesign-certs@v2 uses: apple-actions/import-codesign-certs@v2
with: with:
@@ -168,26 +73,21 @@ jobs:
p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD }} p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD }}
- name: make build - name: make build
run: yarn make-macos-arm64 run: yarn make-macos-${{ matrix.arch }}
working-directory: apps/electron 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: | run: |
mkdir -p builds 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 - name: Upload Artifact
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: affine-darwin-arm64-builds name: affine-darwin-${{ matrix.arch }}-builds
path: builds path: builds
build-windows: make-windows:
needs: before-make
runs-on: windows-latest runs-on: windows-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@@ -204,23 +104,6 @@ jobs:
with: with:
workspaces: './packages/octobase-node -> target' 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 - name: make build
run: yarn make-windows-x64 run: yarn make-windows-x64
working-directory: apps/electron working-directory: apps/electron
@@ -237,7 +120,7 @@ jobs:
path: builds path: builds
release: release:
needs: [build-macos-x64, build-macos-arm64, build-windows] needs: [make-macos, make-windows]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Download MacOS x64 Artifacts - name: Download MacOS x64 Artifacts
+14
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`;
},
},
}; };
+1 -1
View File
@@ -13,7 +13,7 @@
"scripts": { "scripts": {
"dev": "cross-env NODE_ENV=development node scripts/dev.mjs", "dev": "cross-env NODE_ENV=development node scripts/dev.mjs",
"prod": "cross-env NODE_ENV=production 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": "electron-forge make",
"make-macos-arm64": "electron-forge make --platform=darwin --arch=arm64", "make-macos-arm64": "electron-forge make --platform=darwin --arch=arm64",
"make-macos-x64": "electron-forge make --platform=darwin --arch=x64", "make-macos-x64": "electron-forge make --platform=darwin --arch=x64",
@@ -40,6 +40,17 @@ await fs.move(affineWebOutDir, publicAffineOutDir, { overwrite: true });
await buildLayers(); await buildLayers();
echo('Build layers done'); 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/`;
/// -------- /// --------
/// -------- /// --------
/// -------- /// --------
+15 -9
View File
@@ -9,37 +9,43 @@
## Prerequisites ## 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. 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 ## 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 ```sh
# in repo root
yarn install yarn install
yarn build:preload yarn dev
yarn dev:app
# in apps/electron
yarn generate-assets
yarn dev
``` ```
Now you should see the Electron app window popping up shortly.
## Build ## 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. Once the build is complete, you can find the paths to the binaries in the terminal output.
``` ```
Finished 2 bundles at: Finished 2 bundles at:
/Users/affine/Documents/GitHub/AFFiNE/apps/desktop/src-tauri/target/release/bundle/macos/AFFiNE.app Artifacts available at: <affine-repo>/apps/electron/out/make
/Users/affine/Documents/GitHub/AFFiNE/apps/desktop/src-tauri/target/release/bundle/dmg/AFFiNE_0.0.2_aarch64.dmg
``` ```
## CI ## 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 - build the app for all supported platforms
- upload the artifacts to GitHub Actions - upload the artifacts to GitHub Actions