-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Electron app setup and release workflow #403
Conversation
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (1)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including You can disable this status message by setting the WalkthroughThe changes introduce foundational configurations for the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
🧹 Outside diff range and nitpick comments (3)
native/src/main.ts (2)
18-24
: Improve application lifecycle managementThe application lifecycle handling could be more robust. Consider adding proper cleanup and error handling.
Here's a suggested improvement:
+let mainWindow: BrowserWindow | null = null; + function createWindow() { const win = new BrowserWindow({...}); + mainWindow = win; + + win.on('closed', () => { + mainWindow = null; + }); // ... rest of createWindow function } -app.whenReady().then(createWindow); +app.whenReady().then(() => { + createWindow(); + + process.on('uncaughtException', (error) => { + console.error('Uncaught exception:', error); + }); +}); app.on("window-all-closed", () => { + // Perform any cleanup tasks here if (process.platform !== "darwin") { app.quit(); } });
26-30
: Add window state persistenceConsider adding window state management to preserve the window's position and size between sessions.
I recommend using
electron-window-state
package. Here's how to implement it:+import * as windowStateKeeper from 'electron-window-state'; function createWindow() { + const windowState = windowStateKeeper({ + defaultWidth: 800, + defaultHeight: 600 + }); + const win = new BrowserWindow({ - width: 800, - height: 600, + x: windowState.x, + y: windowState.y, + width: windowState.width, + height: windowState.height, // ... rest of options }); + + windowState.manage(win); }native/package.json (1)
27-62
: Enhance build configuration for security and optimizationSeveral improvements are recommended for the build configuration:
- Consider optimizing the included files to reduce package size
- Add code signing configuration for macOS distribution
- Consider adding auto-update configuration
"build": { "publish": { "provider": "github" }, "appId": "com.example.codepair", "productName": "codepair", "files": [ "dist/**/*", - "node_modules/**/*", + "!node_modules/**/{CHANGELOG.md,README.md,README,readme.md,readme}", + "!node_modules/**/{test,__tests__,tests,powered-test,example,examples}", "package.json", "!node_modules/**/*.{ts,map}" ], "mac": { - "target": "dmg" + "target": "dmg", + "hardenedRuntime": true, + "gatekeeperAssess": false, + "entitlements": "build/entitlements.mac.plist", + "entitlementsInherit": "build/entitlements.mac.plist" },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
.github/workflows/app-release.yml
(1 hunks)native/package.json
(1 hunks)native/src/main.ts
(1 hunks)native/tsconfig.json
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- native/tsconfig.json
🔇 Additional comments (5)
native/src/main.ts (1)
11-15
: Verify development and production URLs
Please ensure that:
- The development server is configured to run on port 5173
- The production URL is correct and accessible
.github/workflows/app-release.yml (3)
1-6
: LGTM! Workflow trigger configuration is appropriate.
The workflow name and trigger configuration are well-defined for release automation.
43-53
: Verify electron-builder configuration and release artifacts.
The workflow should verify the electron-builder configuration and ensure all platform-specific artifacts are included.
#!/bin/bash
# Description: Verify electron-builder configuration and build scripts
# Expected: Configuration exists with correct build targets
# Check electron-builder configuration
echo "Checking electron-builder configuration:"
rg -A 10 "build|electron-builder" native/package.json
# Check if all platform targets are configured
echo "Checking platform targets:"
rg -A 5 "mac|win|linux" native/electron-builder.*
7-18
: Consider using Node.js 20.x for longer-term support.
Node.js 18.x will reach EOL in April 2025. Consider upgrading to Node.js 20.x (LTS) for longer-term support.
- node-version: [18.x]
+ node-version: [20.x]
Verify the working directory exists.
The workflow assumes the existence of a ./native
directory.
✅ Verification successful
The ./native
directory exists with proper electron-builder configuration
The directory exists and contains all necessary files including package.json
with complete electron-builder configuration for all platforms (Windows, macOS, and Linux). The build configuration is properly set up in the package.json
file.
Regarding Node.js version upgrade suggestion:
The package.json doesn't specify Node.js engine requirements, and the project is using modern dependencies including Electron v33 and TypeScript 5.3.3. Since these are compatible with Node.js 20.x, the suggestion to upgrade from Node.js 18.x to 20.x is valid and beneficial for longer-term support.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the existence of the native directory and required files
# Expected: Directory exists with package.json and electron-builder configuration
# Check if native directory exists
if ! [ -d "native" ]; then
echo "Error: native directory not found"
exit 1
fi
# Check for essential files
echo "Checking for essential files in native directory:"
ls -la native/package.json native/electron-builder.* 2>/dev/null || echo "Warning: Missing essential configuration files"
Length of output: 1337
Script:
#!/bin/bash
# Let's verify if the native directory has the electron-builder configuration in package.json
rg -A 20 '"build":\s*{' native/package.json
# Also check the contents of the native directory to see if electron-builder config exists with different extensions
ls -la native/ | grep -iE 'electron-builder|builder'
# Check package.json for Node.js engine requirements
rg '"engines"' -A 3 native/package.json
Length of output: 230
Script:
#!/bin/bash
# Let's try with simpler patterns to check the configuration
echo "Checking native directory contents:"
ls -la native/
echo -e "\nChecking package.json content:"
cat native/package.json
echo -e "\nChecking for Node.js version requirements:"
rg '"node":' native/package.json
Length of output: 2191
native/package.json (1)
20-26
: Review dependency versions for compatibility and security
The dependency versions need attention:
- [email protected] is outdated compared to the latest Electron version
- Consider using caret ranges for minor version updates
#!/bin/bash
# Check latest versions of key dependencies
pnpm view electron-builder version
pnpm view electron version
"devDependencies": {
- "@types/node": "^22.7.6",
+ "@types/node": "^20.0.0",
"cross-env": "^7.0.3",
"electron": "^33.0.1",
- "electron-builder": "^25.1.8",
+ "electron-builder": "^24.0.0",
"typescript": "^5.3.3"
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR.
I have a few comments:
- How about changing native to desktop?
- We need to add
native (or desktop)
topnpm-workspace.yaml
to use it in the monorepo. - We should support the following common commands in
package.json
:"lint": "pnpm run --parallel lint", "lint:check": "pnpm run --parallel lint:check", "format": "pnpm run --parallel format", "format:check": "pnpm run --parallel format:check"
- We also need to change
README.md
and adddesktop/README.md
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (2)
desktop/src/main.ts (2)
27-43
: Add window state management and crash handling.The current lifecycle management is basic. Consider adding window state persistence and crash reporting for a better user experience.
+import windowStateKeeper from 'electron-window-state'; + +let mainWindow: BrowserWindow | null = null; + function createWindow() { try { + // Load the previous state + const mainWindowState = windowStateKeeper({ + defaultWidth: 1000, + defaultHeight: 800 + }); + const win = new BrowserWindow({ maximizable: true, + x: mainWindowState.x, + y: mainWindowState.y, + width: mainWindowState.width, + height: mainWindowState.height, webPreferences: { nodeIntegration: false, contextIsolation: true, sandbox: true } }); + + // Let us register listeners on the window, so we can update the state + mainWindowState.manage(win); + mainWindow = win;Also, consider adding crash reporting:
+app.on('render-process-gone', (event, webContents, details) => { + console.error('Render process crashed:', details.reason); + // Implement your crash reporting logic here +}); + +app.on('child-process-gone', (event, details) => { + console.error('Child process crashed:', details.type, details.reason); + // Implement your crash reporting logic here +});
32-36
: Consider adding graceful shutdown handling.The current window closing behavior could be enhanced to handle unsaved changes or ongoing operations.
-app.on("window-all-closed", () => { - if (process.platform !== "darwin") { - app.quit(); - } -}); +app.on("window-all-closed", async () => { + // Check for unsaved changes or ongoing operations + if (mainWindow) { + const response = await mainWindow.webContents.executeJavaScript( + 'window.onbeforeunload && window.onbeforeunload()' + ); + if (response) { + // Handle cleanup or show confirmation dialog + } + } + + if (process.platform !== "darwin") { + app.quit(); + } +});
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (6)
.github/workflows/app-release.yml
(1 hunks)desktop/.env.development
(1 hunks)desktop/.env.production
(1 hunks)desktop/package.json
(1 hunks)desktop/src/main.ts
(1 hunks)desktop/tsconfig.json
(1 hunks)
✅ Files skipped from review due to trivial changes (4)
- desktop/.env.development
- desktop/.env.production
- desktop/package.json
- desktop/tsconfig.json
🚧 Files skipped from review as they are similar to previous changes (1)
- .github/workflows/app-release.yml
0818881
to
4a51f76
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve left a few comments on this document.
Let’s collaborate on Zoom!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🧹 Outside diff range and nitpick comments (4)
package.json (1)
Line range hint
1-32
: Consider adding release documentationSince this PR introduces Electron app releases, consider adding relevant documentation fields to package.json.
Add these fields to improve documentation:
{ "name": "codepair", "version": "0.1.23", "description": "Build your own AI-powered collaborative markdown editor in just 5 minutes", + "repository": { + "type": "git", + "url": "https://github.com/your-org/codepair.git" + }, + "homepage": "https://github.com/your-org/codepair#readme", + "bugs": { + "url": "https://github.com/your-org/codepair/issues" + }, ...desktop/src/main.ts (1)
21-37
: Add graceful shutdown and system event handling.The application should handle system events and perform cleanup during shutdown.
+// Handle system events +app.on('before-quit', (event) => { + // Perform cleanup tasks here + console.log('Performing cleanup before quit...'); +}); + +// Handle system sleep/resume +app.on('suspend', () => { + console.log('System is going to sleep'); + // Save application state if needed +}); + +app.on('resume', () => { + console.log('System resumed'); + // Restore connections if needed +}); + app.on("window-all-closed", () => { if (process.platform !== "darwin") { app.quit(); } });.github/workflows/desktop-release.yml (2)
1-4
: Consider adding support for pre-releasesThe workflow currently only runs on published releases. Consider adding support for pre-releases to enable testing of the release process before official releases.
on: release: - types: [published] + types: [published, prereleased]
8-16
: Add fail-fast strategy to optimize CI runtimeConsider adding a fail-fast strategy to stop all matrix jobs if one fails, saving CI minutes.
strategy: + fail-fast: true matrix: os: [macos-latest, ubuntu-latest, windows-latest] node-version: [18.x]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (2)
desktop/build/icon.png
is excluded by!**/*.png
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (12)
.github/workflows/desktop-release.yml
(1 hunks).gitignore
(1 hunks)backend/tsconfig.json
(1 hunks)desktop/.env.development
(1 hunks)desktop/.env.production
(1 hunks)desktop/.prettierrc
(1 hunks)desktop/eslint.config.mjs
(1 hunks)desktop/package.json
(1 hunks)desktop/src/main.ts
(1 hunks)desktop/tsconfig.json
(1 hunks)package.json
(1 hunks)pnpm-workspace.yaml
(1 hunks)
✅ Files skipped from review due to trivial changes (4)
- .gitignore
- backend/tsconfig.json
- desktop/.prettierrc
- desktop/eslint.config.mjs
🚧 Files skipped from review as they are similar to previous changes (4)
- desktop/.env.development
- desktop/.env.production
- desktop/package.json
- desktop/tsconfig.json
🔇 Additional comments (5)
pnpm-workspace.yaml (2)
4-4
: LGTM! Workspace configuration aligns with project structure.
The addition of the "desktop" package to the workspace configuration is appropriate for managing the new Electron application alongside existing frontend and backend packages.
4-4
: Verify desktop package setup
Let's ensure the desktop package is properly configured in the workspace.
✅ Verification successful
Let me gather more information about the package.json content to properly verify the desktop package setup.
Desktop package is properly configured and set up
The desktop package is correctly configured with:
- Essential Electron setup in package.json with proper build configurations for multiple platforms
- Required dependencies (electron, electron-builder) and scripts for development and production
- Correct main entry point (dist/main.js) with corresponding TypeScript source (src/main.ts)
- Proper Electron application code with window management and platform-specific behaviors
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the desktop package setup and configuration
# Check if desktop directory exists and has required files
echo "Checking desktop package structure..."
fd -t f . desktop -x echo "Found: {}"
# Verify package.json exists and contains required Electron configuration
echo -e "\nChecking desktop package.json configuration..."
if [ -f "desktop/package.json" ]; then
cat desktop/package.json | jq '{
name: .name,
main: .main,
dependencies: (.dependencies | keys),
devDependencies: (.devDependencies | keys),
scripts: (.scripts | keys)
}'
fi
# Check for essential Electron files
echo -e "\nChecking for essential Electron files..."
fd -t f . desktop/src -x echo "Found source file: {}"
Length of output: 874
Script:
#!/bin/bash
# Get the full content of package.json to verify Electron configuration
echo "Desktop package.json content:"
cat desktop/package.json
# Check for Electron-related dependencies in root package.json
echo -e "\nChecking root package.json for Electron dependencies:"
if [ -f "package.json" ]; then
cat package.json | jq '.dependencies,.devDependencies' | grep -i electron || echo "No Electron dependencies found in root package.json"
fi
# Check main.ts content for Electron imports and setup
echo -e "\nChecking main.ts content:"
cat desktop/src/main.ts
Length of output: 2998
package.json (1)
13-13
: LGTM! Verify desktop package setup
The new desktop script follows the established monorepo pattern correctly.
Let's verify the desktop package setup:
✅ Verification successful
Desktop package is properly configured in the monorepo
The verification confirms:
- Desktop package exists with package.json
- Electron is correctly added as a devDependency (v33.0.1)
- Desktop workspace is properly configured in pnpm-workspace.yaml
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify desktop package configuration exists and contains required Electron setup
# Check if desktop package.json exists and contains electron
if fd -t f "package.json" desktop/; then
cat desktop/package.json | jq -r '.dependencies.electron, .devDependencies.electron'
fi
# Verify desktop workspace is properly configured in pnpm-workspace.yaml
if [ -f "pnpm-workspace.yaml" ]; then
cat pnpm-workspace.yaml
fi
Length of output: 264
desktop/src/main.ts (1)
12-12
: Verify service URL configuration across environments.
Ensure that the DESKTOP_CODEPAIR_URL
is properly configured in both development and production environments.
.github/workflows/desktop-release.yml (1)
39-49
: 🛠️ Refactor suggestion
Optimize release asset upload configuration
Several improvements can be made to the upload step:
- Remove duplicate GITHUB_TOKEN environment variable
- Add condition to skip upload on build failure
- Verify release patterns match electron-builder output
- name: Upload Release Assets
uses: softprops/action-gh-release@v1
+ if: success()
with:
files: |
./release/**/*.exe
./release/**/*.dmg
./release/**/*.AppImage
./release/**/*.yml
./release/latest*.yml
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
✅ Verification successful
Release asset upload patterns match electron-builder configuration
The release patterns in the workflow match the electron-builder configuration:
./release/**/*.exe
matches Windows NSIS output./release/**/*.dmg
matches Mac DMG output./release/**/*.AppImage
matches Linux AppImage output./release/**/*.yml
and./release/latest*.yml
match auto-update metadata files
The suggested improvements to remove the duplicate token and add failure condition are valid optimizations.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Verify that the release patterns match electron-builder output configuration
cd desktop
if [ -f "electron-builder.yml" ]; then
echo "Checking electron-builder configuration..."
cat electron-builder.yml
elif [ -f "package.json" ]; then
echo "Checking package.json build configuration..."
jq '.build' package.json
fi
Length of output: 792
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (1)
.github/workflows/desktop-release.yml (1)
9-12
: Enhance matrix configuration with fail-fast and error handlingThe matrix strategy could benefit from additional configuration:
strategy: + fail-fast: false + max-parallel: 3 matrix: os: [macos-latest, ubuntu-latest, windows-latest] node-version: [18.x]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
.github/workflows/desktop-release.yml
(1 hunks)desktop/src/main.ts
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- desktop/src/main.ts
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/desktop-release.yml
40-40: the runner of "softprops/action-gh-release@v1" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🔇 Additional comments (2)
.github/workflows/desktop-release.yml (2)
19-31
: Action versions and caching configuration need improvement
The environment setup steps still need the improvements suggested in the previous review.
33-38
: 🛠️ Refactor suggestion
Add error handling and timeout to build step
The build step needs improved reliability:
- name: Build and publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
+ set -eo pipefail
pnpm run release
+ timeout-minutes: 30
Likely invalid or redundant comment.
…top configuration
1f1ad33
to
9056ff9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (2)
desktop/build/icon.png
is excluded by!**/*.png
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (10)
.github/workflows/desktop-release.yml
(1 hunks).gitignore
(1 hunks)backend/tsconfig.json
(1 hunks)desktop/.prettierrc
(1 hunks)desktop/eslint.config.mjs
(1 hunks)desktop/package.json
(1 hunks)desktop/src/main.ts
(1 hunks)desktop/tsconfig.json
(1 hunks)package.json
(1 hunks)pnpm-workspace.yaml
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (9)
- .gitignore
- backend/tsconfig.json
- desktop/.prettierrc
- desktop/eslint.config.mjs
- desktop/package.json
- desktop/src/main.ts
- desktop/tsconfig.json
- package.json
- pnpm-workspace.yaml
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/desktop-release.yml
40-40: the runner of "softprops/action-gh-release@v1" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🔇 Additional comments (1)
.github/workflows/desktop-release.yml (1)
14-16
: Verify desktop directory existence
The workflow assumes the existence of a ./desktop
directory. Add a verification step to ensure the directory exists before proceeding with the build.
✅ Verification successful
Desktop directory exists and is properly configured
The verification confirms that the ./desktop
directory exists at the repository root, validating the working directory configuration in the workflow file.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if the desktop directory exists in the repository
if ! fd -t d "^desktop$" --max-depth 1; then
echo "Warning: desktop directory not found at repository root"
fi
Length of output: 44
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After merging this PR, we need to complete the following tasks:
- Set up build tools (e.g., Webpack, Vite)
- Configure CI
- Update
README.md
I’ll create the corresponding issues after the merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution.
* Add Electron app setup and release workflow * Improve error handling in Electron window creation * Update package.json to set module type and adjust versioning * remove property httpHeaders in loadURL * Add environment configuration for development and production URLs * Rename native directory to desktop and update related configurations * Refactor configuration files for improved clarity and organization * Add desktop configuration and update environment variables * Fix setup default value for serviceUrl * Remove development and production environment variable files for desktop configuration * Add Improve error handling in main application window creation * Fix pnpm install command to use frozen lockfile * Update pnpm-lock.yaml * Update version to 0.1.25 in desktop package.json * Refactor clean up tsconfig.json formatting
What this PR does / why we need it:
This PR sets up the Electron application build and release workflow. It introduces a GitHub Actions workflow that automates the building and publishing of the Electron app across macOS, Windows, and Linux platforms whenever a new tag matching v* is pushed. This streamlines the release process and ensures that users can access the latest versions of the desktop application directly from GitHub Releases.
Which issue(s) this PR fixes:
Fixes #285
Special notes for your reviewer:
The workflow uses electron-builder for packaging the app.
The package.json in the native directory has been updated with build scripts and configurations for electron-builder.
Does this PR introduce a user-facing change?:
Additional documentation:
Checklist:
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Documentation
.gitignore
to exclude therelease/
directory.Chores
Style