Skip to content

Commit

Permalink
build: add canary build (#1986)
Browse files Browse the repository at this point in the history
Co-authored-by: Himself65 <himself65@outlook.com>
Co-authored-by: Horus <lhlxtl@gmail.com>
  • Loading branch information
3 people committed Apr 17, 2023
1 parent 54a30bb commit 11de3a6
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 65 deletions.
96 changes: 63 additions & 33 deletions .github/workflows/release-desktop-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ on:
type: boolean
required: true
default: true
is-canary:
description: 'Canary Release? The app will be named as "AFFiNE Canary"'
type: boolean
required: true
default: true

permissions:
actions: write
Expand All @@ -29,9 +34,12 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true

env:
BUILD_TYPE: ${{ github.event.inputs.is-canary == 'true' && 'canary' || 'stable' }}

jobs:
make-macos:
environment: production
environment: ${{ github.ref_name == 'master' && 'production' || 'development' }}
env:
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
Expand Down Expand Up @@ -62,19 +70,6 @@ jobs:
with:
electron-workspace-install: true

- name: install Rust stable
uses: dtolnay/rust-toolchain@stable

- name: add arm64 target
if: matrix.arch == 'arm64'
run: rustup target add aarch64-apple-darwin

- name: Rust cache
uses: swatinem/rust-cache@v2
with:
key: ${{ matrix.arch }}
workspaces: './packages/octobase-node -> target'

- name: Signing By Apple Developer ID
uses: apple-actions/import-codesign-certs@v2
with:
Expand All @@ -88,7 +83,7 @@ jobs:
- name: Save artifacts
run: |
mkdir -p builds
mv apps/electron/out/make/AFFiNE.dmg ./builds/affine-darwin-${{ matrix.arch }}.dmg
mv apps/electron/out/*/make/*.dmg ./builds/affine-${{ env.BUILD_TYPE }}-darwin-${{ matrix.arch }}.dmg
- name: Upload Artifact
uses: actions/upload-artifact@v3
Expand All @@ -98,11 +93,8 @@ jobs:

make-windows:
runs-on: windows-latest
environment: production
environment: ${{ github.ref_name == 'master' && 'production' || 'development' }}
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 }}
Expand All @@ -125,34 +117,67 @@ jobs:
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'

- name: make build
run: yarn make-windows-x64
working-directory: apps/electron

- name: Save windows artifacts
run: |
mkdir -p builds
mv apps/electron/out/make/zip/win32/x64/AFFiNE-win32-x64-*.zip ./builds/affine-windows-x64.zip
mv apps/electron/out/make/squirrel.windows/x64/*.exe ./builds/affine-windows-x64.exe
mv apps/electron/out/make/squirrel.windows/x64/*.msi ./builds/affine-windows-x64.msi
mv apps/electron/out/make/squirrel.windows/x64/*.nupkg ./builds/affine-windows-x64.nupkg
mv apps/electron/out/make/squirrel.windows/x64/RELEASES ./builds/RELEASES
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/squirrel.windows/x64/*.exe ./builds/affine-${{ env.BUILD_TYPE }}-windows-x64.exe
mv apps/electron/out/*/make/squirrel.windows/x64/*.msi ./builds/affine-${{ env.BUILD_TYPE }}-windows-x64.msi
mv apps/electron/out/*/make/squirrel.windows/x64/*.nupkg ./builds/affine-${{ env.BUILD_TYPE }}-windows-x64.nupkg
mv apps/electron/out/*/make/squirrel.windows/x64/RELEASES ./builds/RELEASES
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: affine-windows-x64-builds
path: builds

make-linux:
runs-on: ubuntu-latest
environment: ${{ github.ref_name == 'master' && 'production' || 'development' }}
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 }}
AFFINE_GOOGLE_CLIENT_ID: ${{ secrets.AFFINE_GOOGLE_CLIENT_ID }}
AFFINE_GOOGLE_CLIENT_SECRET: ${{ secrets.AFFINE_GOOGLE_CLIENT_SECRET }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
NEXT_PUBLIC_SENTRY_DSN: ${{ secrets.NEXT_PUBLIC_SENTRY_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
API_SERVER_PROFILE: prod

steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: ./.github/actions/setup-node
with:
electron-workspace-install: true

- name: make build
run: yarn make
working-directory: apps/electron

- name: Save Linux artifacts
run: |
mkdir -p builds
mv apps/electron/out/*/make/zip/linux/x64/*.zip ./builds/affine-${{ env.BUILD_TYPE }}-linux-x64.zip
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: affine-Linux-x64-builds
path: builds

release:
needs: [make-macos, make-windows]
needs: [make-macos, make-windows, make-linux]
runs-on: ubuntu-latest
steps:
- name: Download MacOS x64 Artifacts
Expand All @@ -171,6 +196,11 @@ jobs:
with:
name: affine-windows-x64-builds
path: ./
- name: Download Linux Artifacts
uses: actions/download-artifact@v3
with:
name: affine-Linux-x64-builds
path: ./

- name: Create Release Draft
uses: softprops/action-gh-release@v1
Expand Down
41 changes: 35 additions & 6 deletions apps/electron/forge.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const {
utils: { fromBuildIdentifier },
} = require('@electron-forge/core');

const isCanary = process.env.BUILD_TYPE === 'canary';

const productName = isCanary ? 'AFFiNE-Canary' : 'AFFiNE';
const icoPath = isCanary
? './resources/icons/icon_canary.ico'
: './resources/icons/icon.ico';
const icnsPath = isCanary
? './resources/icons/icon_canary.icns'
: './resources/icons/icon.icns';

/**
* @type {import('@electron-forge/shared-types').ForgeConfig}
*/
module.exports = {
buildIdentifier: isCanary ? 'canary' : 'stable',
packagerConfig: {
name: 'AFFiNE',
icon: './resources/icons/icon.icns',
name: productName,
appBundleId: fromBuildIdentifier({
canary: 'pro.affine.canary',
stable: 'pro.affine.app',
}),
icon: icnsPath,
osxSign: {
identity: 'Developer ID Application: TOEVERYTHING PTE. LTD.',
'hardened-runtime': true,
Expand All @@ -20,28 +43,34 @@ module.exports = {
name: '@electron-forge/maker-dmg',
config: {
format: 'ULFO',
icon: './resources/icons/icon.icns',
icon: icnsPath,
name: 'AFFiNE',
},
},
{
name: '@electron-forge/maker-zip',
config: {
name: 'affine',
iconUrl: './resources/icons/icon.ico',
setupIcon: './resources/icons/icon.ico',
iconUrl: icoPath,
setupIcon: icoPath,
platforms: ['darwin', 'linux', 'win32'],
},
},
{
name: '@electron-forge/maker-squirrel',
config: {
name: 'AFFiNE',
setupIcon: './resources/icons/icon.ico',
setupIcon: icoPath,
// loadingGif: './resources/icons/loading.gif',
},
},
],
hooks: {
readPackageJson: async (_, packageJson) => {
// we want different package name for canary build
// so stable and canary will not share the same app data
packageJson.productName = productName;
},
generateAssets: async (_, platform, arch) => {
const { $ } = await import('zx');

Expand Down
10 changes: 0 additions & 10 deletions apps/electron/layers/main/src/app-state/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as os from 'node:os';
import path from 'node:path';

import { Storage } from '@affine/octobase-node';
import { app, shell } from 'electron';
import { BrowserWindow, ipcMain, nativeTheme } from 'electron';
import fs from 'fs-extra';
Expand All @@ -16,16 +15,7 @@ fs.ensureDirSync(AFFINE_ROOT);

const logger = console;

// todo: rethink this
export const appState = {
storage: new Storage(path.join(AFFINE_ROOT, 'test.db')),
};

export const registerHandlers = () => {
ipcMain.handle('octo:workspace-sync', async (_, id) => {
return appState.storage.sync(id, '');
});

ipcMain.handle('ui:theme-change', async (_, theme) => {
nativeTheme.themeSource = theme;
logger.info('theme change', theme);
Expand Down
4 changes: 1 addition & 3 deletions apps/electron/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "@affine/electron",
"productName": "AFFiNE",
"private": true,
"version": "0.5.3",
"author": "affine",
Expand All @@ -14,19 +13,18 @@
"dev": "cross-env NODE_ENV=development node scripts/dev.mjs",
"prod": "cross-env NODE_ENV=production node scripts/dev.mjs",
"generate-assets": "zx scripts/generate-assets.mjs",
"package": "electron-forge package",
"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",
"build:octobase-node": "yarn workspace @affine/octobase-node build",
"postinstall": "ELECTRON_RUN_AS_NODE=1 electron scripts/update-electron-vendors.mjs"
},
"config": {
"forge": "./forge.config.js"
},
"main": "./dist/layers/main/index.js",
"devDependencies": {
"@affine/octobase-node": "workspace:*",
"@electron-forge/cli": "^6.1.1",
"@electron-forge/core": "^6.1.1",
"@electron-forge/core-utils": "^6.1.1",
Expand Down
Binary file not shown.
Binary file added apps/electron/resources/icons/icon_canary.ico
Binary file not shown.
11 changes: 0 additions & 11 deletions apps/electron/scripts/generate-assets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,6 @@ await fs.move(affineWebOutDir, publicAffineOutDir, { overwrite: true });
await buildLayers();
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/`;

/// --------
/// --------
/// --------
Expand Down
3 changes: 1 addition & 2 deletions apps/electron/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ __metadata:
version: 0.0.0-use.local
resolution: "@affine/electron@workspace:."
dependencies:
"@affine/octobase-node": "workspace:*"
"@electron-forge/cli": ^6.1.1
"@electron-forge/core": ^6.1.1
"@electron-forge/core-utils": ^6.1.1
Expand Down Expand Up @@ -192,7 +191,7 @@ __metadata:
languageName: unknown
linkType: soft

"@affine/octobase-node@workspace:*, @affine/octobase-node@workspace:../../packages/octobase-node":
"@affine/octobase-node@workspace:../../packages/octobase-node":
version: 0.0.0-use.local
resolution: "@affine/octobase-node@workspace:../../packages/octobase-node"
dependencies:
Expand Down

2 comments on commit 11de3a6

@vercel
Copy link

@vercel vercel bot commented on 11de3a6 Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

affine-storybook – ./packages/component

affine-storybook.vercel.app
affine-storybook-git-master-toeverything.vercel.app
affine-storybook-toeverything.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 11de3a6 Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.