There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
build(electron): allow customizing channel type for internal build (#4511)
Peng Xiao5e9eeaddbd75
diff --git a/.github/workflows/nightly-build.yml b/.github/workflows/nightly-build.ymlindex 634293928a..9dcf81a13c 100644--- a/.github/workflows/nightly-build.yml+++ b/.github/workflows/nightly-build.yml@@ -2,6 +2,15 @@ name: Build Canary Desktop App on Staging Branchon:workflow_dispatch:+ inputs:+ channel_override:+ description: 'channel type (canary, beta, or stable)'+ type: choice+ default: beta+ options:+ - canary+ - beta+ - stablepush:branches:# 0.6.x-staging@@ -27,7 +36,10 @@ concurrency:cancel-in-progress: trueenv:+ # BUILD_TYPE => app icon, app name, etcBUILD_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.mjsindex f4a37b1139..bd1db6d99c 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.mjsindex cf7307b11e..22e568cafc 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 devtoolsawait 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.tsindex adc6df4ceb..95d0ea9163 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.tsindex fb24f7b1e6..ccaed0b076 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 argsif (process.argv.includes('--app-name')) {diff --git a/apps/electron/src/main/updater/electron-updater.ts b/apps/electron/src/main/updater/electron-updater.tsindex 593fd33c74..dc91ab7537 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';