diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 96fe81f57d..fbe8daa75b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -376,6 +376,17 @@ jobs: env: COVERAGE: true + - name: Make bundle + if: ${{ matrix.spec.os == 'macos-latest' && matrix.spec.arch == 'arm64' }} + run: yarn workspace @affine/electron make --platform=darwin --arch=arm64 + + - name: Bundle output check + if: ${{ matrix.spec.os == 'macos-latest' && matrix.spec.arch == 'arm64' }} + run: | + ./scripts/unzip-macos-arm64.sh + yarn ts-node-esm ./scripts/macos-arm64-output-check.mts + working-directory: apps/electron + - name: Collect code coverage report if: ${{ matrix.spec.test }} run: yarn exec nyc report -t .nyc_output --report-dir .coverage --reporter=lcov diff --git a/apps/electron/.gitignore b/apps/electron/.gitignore index 72afe66b1b..cc2c41bb7f 100644 --- a/apps/electron/.gitignore +++ b/apps/electron/.gitignore @@ -13,3 +13,5 @@ resources/web-static !.yarn/sdks !.yarn/versions dev.json + +zip-out diff --git a/apps/electron/scripts/macos-arm64-output-check.mts b/apps/electron/scripts/macos-arm64-output-check.mts new file mode 100644 index 0000000000..15e0ff7900 --- /dev/null +++ b/apps/electron/scripts/macos-arm64-output-check.mts @@ -0,0 +1,42 @@ +import { fileURLToPath } from 'node:url'; +import { readdir } from 'node:fs/promises'; + +const outputRoot = fileURLToPath( + new URL( + '../zip-out/AFFiNE-canary.app/Contents/Resources/app', + import.meta.url + ) +); +const outputList = [ + [ + 'dist', + [ + 'main.js', + 'helper.js', + 'preload.js', + 'affine.darwin-arm64.node', + 'plugins', + 'workers', + ], + ], + ['dist/plugins', ['bookmark-block']], + ['dist/plugins/bookmark-block', ['index.mjs']], + ['dist/workers', ['plugin.worker.js']], + [ + 'node_modules/@toeverything/plugin-infra/dist', + ['manager.js', 'manager.cjs'], + ], +] as [entry: string, expected: string[]][]; + +await Promise.all( + outputList.map(async ([entry, output]) => { + const files = await readdir(`${outputRoot}/${entry}`); + output.forEach(file => { + if (!files.includes(file)) { + throw new Error(`File ${entry}/${file} not found`); + } + }); + }) +); + +console.log('Output check passed'); diff --git a/apps/electron/scripts/unzip-macos-arm64.sh b/apps/electron/scripts/unzip-macos-arm64.sh new file mode 100755 index 0000000000..1790fcbd97 --- /dev/null +++ b/apps/electron/scripts/unzip-macos-arm64.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Set the directory +dir="./out/canary/make/zip/darwin/arm64" + +# Get the first file +file=$(ls -1 $dir | head -n 1) + +# Check if file exists and is a zip file +if [ -f "$dir/$file" ] && [ ${file: -4} == ".zip" ] +then + # Unzip the file + unzip "$dir/$file" -d "zip-out" +else + echo "No zip file found" +fi diff --git a/apps/electron/tsconfig.node.json b/apps/electron/tsconfig.node.json index bba6c23afc..94614e8be5 100644 --- a/apps/electron/tsconfig.node.json +++ b/apps/electron/tsconfig.node.json @@ -7,7 +7,8 @@ "resolveJsonModule": true, "moduleResolution": "Node", "allowSyntheticDefaultImports": true, - "noEmit": false + "noEmit": false, + "outDir": "./lib/scripts" }, "include": ["./scripts", "esbuild.main.config.ts", "esbuild.plugin.config.ts"] }