diff --git a/.github/workflows/nightly-build.yml b/.github/workflows/nightly-build.yml index 634293928..9dcf81a13 100644 --- a/.github/workflows/nightly-build.yml +++ b/.github/workflows/nightly-build.yml @@ -2,6 +2,15 @@ name: Build Canary Desktop App on Staging Branch on: workflow_dispatch: + inputs: + channel_override: + description: 'channel type (canary, beta, or stable)' + type: choice + default: beta + options: + - canary + - beta + - stable push: branches: # 0.6.x-staging @@ -27,7 +36,10 @@ concurrency: cancel-in-progress: true env: + # BUILD_TYPE => app icon, app name, etc BUILD_TYPE: internal + # BUILD_TYPE_OVERRIDE => channel type (canary, beta, or stable) - get the channel type (the api configs) + BUILD_TYPE_OVERRIDE: ${{ github.event.inputs.channel_override || 'beta' }} jobs: set-build-version: diff --git a/apps/electron/scripts/build-layers.mjs b/apps/electron/scripts/build-layers.mjs index f4a37b113..bd1db6d99 100644 --- a/apps/electron/scripts/build-layers.mjs +++ b/apps/electron/scripts/build-layers.mjs @@ -15,12 +15,21 @@ if (process.platform === 'win32') { async function buildLayers() { const common = config(); + + const define = { + 'process.env.NODE_ENV': `"${NODE_ENV}"`, + 'process.env.BUILD_TYPE': `"${process.env.BUILD_TYPE || 'stable'}"`, + }; + + if (process.env.BUILD_TYPE_OVERRIDE) { + define[ + 'process.env.BUILD_TYPE_OVERRIDE' + ] = `"${process.env.BUILD_TYPE_OVERRIDE}"`; + } + await esbuild.build({ ...common.layers, - define: { - 'process.env.NODE_ENV': `"${NODE_ENV}"`, - 'process.env.BUILD_TYPE': `"${process.env.BUILD_TYPE || 'stable'}"`, - }, + define: define, }); } diff --git a/apps/electron/scripts/generate-assets.mjs b/apps/electron/scripts/generate-assets.mjs index cf7307b11..22e568caf 100755 --- a/apps/electron/scripts/generate-assets.mjs +++ b/apps/electron/scripts/generate-assets.mjs @@ -46,6 +46,8 @@ if (!process.env.SKIP_WEB_BUILD) { await $`yarn -T run build:plugins`; await $`yarn nx build @affine/core`; + await $`yarn workspace @affine/electron build`; + // step 1.5: amend sourceMappingURL to allow debugging in devtools await glob('**/*.{js,css}', { cwd: affineCoreOutDir }).then(files => { return files.map(async file => { diff --git a/apps/electron/src/main/config.ts b/apps/electron/src/main/config.ts index adc6df4ce..95d0ea916 100644 --- a/apps/electron/src/main/config.ts +++ b/apps/electron/src/main/config.ts @@ -7,9 +7,16 @@ export const ReleaseTypeSchema = z.enum([ 'internal', ]); -export const envBuildType = (process.env.BUILD_TYPE || 'canary') +export const envBuildType = ( + process.env.BUILD_TYPE_OVERRIDE || + process.env.BUILD_TYPE || + 'canary' +) .trim() .toLowerCase(); + +export const overrideSession = process.env.BUILD_TYPE === 'internal'; + export const buildType = ReleaseTypeSchema.parse(envBuildType); export const mode = process.env.NODE_ENV; diff --git a/apps/electron/src/main/index.ts b/apps/electron/src/main/index.ts index fb24f7b1e..ccaed0b07 100644 --- a/apps/electron/src/main/index.ts +++ b/apps/electron/src/main/index.ts @@ -1,8 +1,11 @@ import './security-restrictions'; +import path from 'node:path'; + import { app } from 'electron'; import { createApplicationMenu } from './application-menu/create'; +import { buildType, overrideSession } from './config'; import { setupDeepLink } from './deep-link'; import { registerEvents } from './events'; import { registerHandlers } from './handlers'; @@ -14,6 +17,14 @@ import { registerUpdater } from './updater'; app.enableSandbox(); +// use the same data for internal & beta for testing +if (overrideSession) { + const appName = buildType === 'stable' ? 'AFFiNE' : `AFFiNE-${buildType}`; + const userDataPath = path.join(app.getPath('appData'), appName); + app.setPath('userData', userDataPath); + app.setPath('sessionData', userDataPath); +} + if (require('electron-squirrel-startup')) app.quit(); // allow tests to overwrite app name through passing args if (process.argv.includes('--app-name')) { diff --git a/apps/electron/src/main/updater/electron-updater.ts b/apps/electron/src/main/updater/electron-updater.ts index 593fd33c7..dc91ab753 100644 --- a/apps/electron/src/main/updater/electron-updater.ts +++ b/apps/electron/src/main/updater/electron-updater.ts @@ -1,23 +1,12 @@ import { app } from 'electron'; import { autoUpdater } from 'electron-updater'; -import { z } from 'zod'; import { isMacOS, isWindows } from '../../shared/utils'; +import { buildType } from '../config'; import { logger } from '../logger'; import { CustomGitHubProvider } from './custom-github-provider'; import { updaterSubjects } from './event'; -export const ReleaseTypeSchema = z.enum([ - 'stable', - 'beta', - 'canary', - 'internal', -]); - -export const envBuildType = (process.env.BUILD_TYPE || 'canary') - .trim() - .toLowerCase(); -export const buildType = ReleaseTypeSchema.parse(envBuildType); const mode = process.env.NODE_ENV; const isDev = mode === 'development';