build: fix electron release build process (#2408)

This commit is contained in:
LongYinan
2023-05-17 17:22:49 +08:00
committed by GitHub
parent 50196d8fde
commit 1350633690
6 changed files with 71 additions and 86 deletions

View File

@@ -337,12 +337,11 @@ jobs:
shell: bash shell: bash
run: | run: |
rm -rf apps/electron/node_modules/better-sqlite3/build 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 - name: Run desktop tests
if: ${{ matrix.spec.test && matrix.spec.os == 'ubuntu-latest' }} if: ${{ matrix.spec.test && matrix.spec.os == 'ubuntu-latest' }}
run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- yarn test run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- yarn workspace @affine/electron test
working-directory: apps/electron
env: env:
COVERAGE: true COVERAGE: true

View File

@@ -73,28 +73,36 @@ jobs:
name: before-make-web-static name: before-make-web-static
path: apps/electron/resources/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: make-distribution:
environment: production environment: production
strategy: strategy:
# all combinations: macos-latest x64, macos-latest arm64, windows-latest x64, ubuntu-latest x64 # all combinations: macos-latest x64, macos-latest arm64, windows-latest x64, ubuntu-latest x64
matrix: matrix:
spec: spec:
- { os: macos-latest, platform: macos, arch: x64 } - {
- { os: macos-latest, platform: macos, arch: arm64 } os: macos-latest,
- { os: ubuntu-latest, platform: linux, arch: x64 } platform: darwin,
- { os: windows-latest, platform: windows, arch: x64 } 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 }} runs-on: ${{ matrix.spec.os }}
needs: needs:
- before-make - before-make
@@ -114,30 +122,33 @@ jobs:
with: with:
name: before-make-web-static name: before-make-web-static
path: apps/electron/resources/web-static path: apps/electron/resources/web-static
- uses: actions/download-artifact@v3 - name: Rebuild Electron dependences
with: shell: bash
name: before-make-electron-dist run: |
path: apps/electron/dist 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 - name: Signing By Apple Developer ID
if: ${{ matrix.spec.platform == 'macos' }} if: ${{ matrix.spec.platform == 'darwin' }}
uses: apple-actions/import-codesign-certs@v2 uses: apple-actions/import-codesign-certs@v2
with: with:
p12-file-base64: ${{ secrets.CERTIFICATES_P12 }} p12-file-base64: ${{ secrets.CERTIFICATES_P12 }}
p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD }} p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD }}
- name: make - name: make
run: yarn make-${{ matrix.spec.platform }}-${{ matrix.spec.arch }} run: yarn workspace @affine/electron make --platform=${{ matrix.spec.platform }} --arch=${{ matrix.spec.arch }}
working-directory: apps/electron
- name: Save artifacts (mac) - name: Save artifacts (mac)
if: ${{ matrix.spec.platform == 'macos' }} if: ${{ matrix.spec.platform == 'darwin' }}
run: | run: |
mkdir -p builds mkdir -p builds
mv apps/electron/out/*/make/*.dmg ./builds/affine-${{ env.BUILD_TYPE }}-macos-${{ matrix.spec.arch }}.dmg 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 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) - name: Save artifacts (windows)
if: ${{ matrix.spec.platform == 'windows' }} if: ${{ matrix.spec.platform == 'win32' }}
run: | run: |
mkdir -p builds mkdir -p builds
mv apps/electron/out/*/make/zip/win32/x64/AFFiNE*-win32-x64-*.zip ./builds/affine-${{ env.BUILD_TYPE }}-windows-x64.zip 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 runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3
- name: Download Artifacts (macos-x64) - name: Download Artifacts (macos-x64)
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
with: with:
name: affine-macos-x64-builds name: affine-darwin-x64-builds
path: ./ path: ./
- name: Download Artifacts (macos-arm64) - name: Download Artifacts (macos-arm64)
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
with: with:
name: affine-macos-arm64-builds name: affine-darwin-arm64-builds
path: ./ path: ./
- name: Download Artifacts (windows-x64) - name: Download Artifacts (windows-x64)
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
with: with:
name: affine-windows-x64-builds name: affine-win32-x64-builds
path: ./ path: ./
- name: Download Artifacts (linux-x64) - name: Download Artifacts (linux-x64)
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
with: with:
name: affine-linux-x64-builds name: affine-linux-x64-builds
path: ./ path: ./
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: release-yml-build-script
path: ./
- name: Setup Node.js - name: Setup Node.js
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
node-version: 18 node-version: 18
- name: Generate Release yml - name: Generate Release yml
run: | run: |
cp ./apps/electron/scripts/generate-yml.js .
node generate-yml.js node generate-yml.js
env: env:
RELEASE_VERSION: ${{ needs.set-build-version.outputs.version }} RELEASE_VERSION: ${{ needs.set-build-version.outputs.version }}

View File

@@ -49,8 +49,7 @@ jobs:
- name: Setup Node.js - name: Setup Node.js
uses: ./.github/actions/setup-node uses: ./.github/actions/setup-node
- name: generate-assets - name: generate-assets
working-directory: apps/electron run: yarn workspace @affine/electron generate-assets
run: yarn generate-assets
env: env:
NEXT_PUBLIC_FIREBASE_API_KEY: ${{ secrets.NEXT_PUBLIC_FIREBASE_API_KEY }} 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_AUTH_DOMAIN: ${{ secrets.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN }}
@@ -75,18 +74,6 @@ jobs:
name: before-make-web-static name: before-make-web-static
path: apps/electron/resources/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: make-distribution:
environment: ${{ github.ref_name == 'master' && 'production' || 'development' }} environment: ${{ github.ref_name == 'master' && 'production' || 'development' }}
strategy: strategy:
@@ -95,13 +82,13 @@ jobs:
spec: spec:
- { - {
os: macos-latest, os: macos-latest,
platform: macos, platform: darwin,
arch: x64, arch: x64,
target: x86_64-apple-darwin, target: x86_64-apple-darwin,
} }
- { - {
os: macos-latest, os: macos-latest,
platform: macos, platform: darwin,
arch: arm64, arch: arm64,
target: aarch64-apple-darwin, target: aarch64-apple-darwin,
} }
@@ -113,7 +100,7 @@ jobs:
} }
- { - {
os: windows-latest, os: windows-latest,
platform: windows, platform: win32,
arch: x64, arch: x64,
target: x86_64-pc-windows-msvc, target: x86_64-pc-windows-msvc,
} }
@@ -136,30 +123,34 @@ jobs:
with: with:
name: before-make-web-static name: before-make-web-static
path: apps/electron/resources/web-static path: apps/electron/resources/web-static
- uses: actions/download-artifact@v3
with: - name: Rebuild Electron dependences
name: before-make-electron-dist shell: bash
path: apps/electron/dist 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 - name: Signing By Apple Developer ID
if: ${{ matrix.spec.platform == 'macos' }} if: ${{ matrix.spec.platform == 'darwin' }}
uses: apple-actions/import-codesign-certs@v2 uses: apple-actions/import-codesign-certs@v2
with: with:
p12-file-base64: ${{ secrets.CERTIFICATES_P12 }} p12-file-base64: ${{ secrets.CERTIFICATES_P12 }}
p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD }} p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD }}
- name: make - name: make
run: yarn make-${{ matrix.spec.platform }}-${{ matrix.spec.arch }} run: yarn workspace @affine/electron make --platform=${{ matrix.spec.platform }} --arch=${{ matrix.spec.arch }}
working-directory: apps/electron
- name: Save artifacts (mac) - name: Save artifacts (mac)
if: ${{ matrix.spec.platform == 'macos' }} if: ${{ matrix.spec.platform == 'darwin' }}
run: | run: |
mkdir -p builds mkdir -p builds
mv apps/electron/out/*/make/*.dmg ./builds/affine-${{ env.BUILD_TYPE }}-macos-${{ matrix.spec.arch }}.dmg 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 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) - name: Save artifacts (windows)
if: ${{ matrix.spec.platform == 'windows' }} if: ${{ matrix.spec.platform == 'win32' }}
run: | run: |
mkdir -p builds mkdir -p builds
mv apps/electron/out/*/make/zip/win32/x64/AFFiNE*-win32-x64-*.zip ./builds/affine-${{ env.BUILD_TYPE }}-windows-x64.zip 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 runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3
- name: Download Artifacts (macos-x64) - name: Download Artifacts (macos-x64)
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
with: with:
name: affine-macos-x64-builds name: affine-darwin-x64-builds
path: ./ path: ./
- name: Download Artifacts (macos-arm64) - name: Download Artifacts (macos-arm64)
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
with: with:
name: affine-macos-arm64-builds name: affine-darwin-arm64-builds
path: ./ path: ./
- name: Download Artifacts (windows-x64) - name: Download Artifacts (windows-x64)
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
with: with:
name: affine-windows-x64-builds name: affine-win32-x64-builds
path: ./ path: ./
- name: Download Artifacts (linux-x64) - name: Download Artifacts (linux-x64)
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
with: with:
name: affine-linux-x64-builds name: affine-linux-x64-builds
path: ./ path: ./
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: release-yml-build-script
path: ./
- uses: actions/setup-node@v3 - uses: actions/setup-node@v3
with: with:
node-version: 18 node-version: 18
- name: Generate Release yml - name: Generate Release yml
run: | 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 - name: Create Release Draft
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
env: env:

View File

@@ -18,10 +18,6 @@
"generate-main-exposed-meta": "zx scripts/generate-main-exposed-meta.mjs", "generate-main-exposed-meta": "zx scripts/generate-main-exposed-meta.mjs",
"package": "electron-forge package", "package": "electron-forge package",
"make": "electron-forge make", "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-unit-test": "yarn rebuild better-sqlite3",
"rebuild:for-electron": "yarn electron-rebuild", "rebuild:for-electron": "yarn electron-rebuild",
"test": "playwright test" "test": "playwright test"
@@ -32,6 +28,7 @@
"main": "./dist/layers/main/index.js", "main": "./dist/layers/main/index.js",
"devDependencies": { "devDependencies": {
"@affine-test/kit": "workspace:*", "@affine-test/kit": "workspace:*",
"@affine/native": "workspace:*",
"@electron-forge/cli": "^6.1.1", "@electron-forge/cli": "^6.1.1",
"@electron-forge/core": "^6.1.1", "@electron-forge/core": "^6.1.1",
"@electron-forge/core-utils": "^6.1.1", "@electron-forge/core-utils": "^6.1.1",
@@ -59,7 +56,6 @@
"zx": "^7.2.2" "zx": "^7.2.2"
}, },
"dependencies": { "dependencies": {
"@affine/native": "workspace:*",
"better-sqlite3": "^8.3.0", "better-sqlite3": "^8.3.0",
"chokidar": "^3.5.3", "chokidar": "^3.5.3",
"electron-updater": "^5.3.0", "electron-updater": "^5.3.0",

View File

@@ -39,19 +39,14 @@ export const config = () => {
bundle: true, bundle: true,
target: `node${NODE_MAJOR_VERSION}`, target: `node${NODE_MAJOR_VERSION}`,
platform: 'node', platform: 'node',
external: [ external: ['electron', 'yjs', 'better-sqlite3', 'electron-updater'],
'electron',
'yjs',
'better-sqlite3',
'electron-updater',
'@affine/native-*',
],
define: define, define: define,
format: 'cjs', format: 'cjs',
loader: { loader: {
'.node': 'copy', '.node': 'copy',
}, },
assetNames: '[name]', assetNames: '[name]',
treeShaking: true,
}, },
preload: { preload: {
entryPoints: [resolve(root, './layers/preload/src/index.ts')], entryPoints: [resolve(root, './layers/preload/src/index.ts')],

View File

@@ -32,9 +32,6 @@ if (process.platform === 'win32') {
cd(repoRootDir); cd(repoRootDir);
// step 1: build electron resources
await $`yarn workspace @affine/electron build-layers`;
// step 2: build web (nextjs) dist // step 2: build web (nextjs) dist
if (!process.env.SKIP_WEB_BUILD) { if (!process.env.SKIP_WEB_BUILD) {
process.env.ENABLE_LEGACY_PROVIDER = 'false'; process.env.ENABLE_LEGACY_PROVIDER = 'false';