Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/app-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: electron-build
on:
push:
tags:
- "v*"

jobs:
release:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
node-version: [18.x]

defaults:
run:
working-directory: ./native

steps:
- name: Check out Git repository
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Set up pnpm
uses: pnpm/action-setup@v4

- name: Install Dependencies
run: pnpm install --no-frozen-lockfile

Comment on lines +31 to +33
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove --no-frozen-lockfile flag for consistent builds.

Using --no-frozen-lockfile in CI/CD can lead to inconsistent builds across different environments as it allows package versions to be updated during installation.

-        run: pnpm install --no-frozen-lockfile
+        run: pnpm install
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Install Dependencies
run: pnpm install --no-frozen-lockfile
- name: Install Dependencies
run: pnpm install

- name: Build Electron App
run: pnpm run build

- name: Build and publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pnpm run electron-builder --publish always

Comment on lines +34 to +42
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling and build verification.

The build steps should include error handling and verification of outputs.

       - name: Build Electron App
-        run: pnpm run build
+        run: |
+          pnpm run build
+          if [ $? -ne 0 ]; then
+            echo "Build failed"
+            exit 1
+          fi
+          # Verify build outputs
+          if [ ! -d "dist" ]; then
+            echo "Build directory not found"
+            exit 1
+          fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Build Electron App
run: pnpm run build
- name: Build and publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pnpm run electron-builder --publish always
- name: Build Electron App
run: |
pnpm run build
if [ $? -ne 0 ]; then
echo "Build failed"
exit 1
fi
# Verify build outputs
if [ ! -d "dist" ]; then
echo "Build directory not found"
exit 1
fi
- name: Build and publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pnpm run electron-builder --publish always

- name: Upload Release Assets
uses: softprops/action-gh-release@v1
with:
files: |
./release/**/*.exe
./release/**/*.dmg
./release/**/*.AppImage
./release/**/*.yml
./release/latest*.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63 changes: 63 additions & 0 deletions native/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@codepair/native",
"version": "1.0.1",
"main": "dist/main.js",
"description": "Codepair Native",
"author": "yorkie-team",
"repository": {
"type": "git",
"url": "https://github.com/minai621/codepair"
},
"license": "Apache-2.0",
Comment on lines +1 to +11
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

🛠️ Refactor suggestion

Repository URL needs to be updated to match the official repository

The repository URL in package.json should be updated to point to the official yorkie-team repository instead of the personal fork. Based on the git remote information, here's what needs to be changed:

  • Update repository URL from https://github.com/minai621/codepair to https://github.com/yorkie-team/codepair.git
  • Keep version as 1.0.1 since this might be intentional for the native package versioning strategy
🔗 Analysis chain

Review and update repository metadata

Several metadata fields need attention:

  1. The repository URL appears to point to a personal fork rather than the main repository
  2. Consider starting with version 1.0.0 for the initial release
 {
   "name": "@codepair/native",
-  "version": "1.0.1",
+  "version": "1.0.0",
   "main": "dist/main.js",
   "description": "Codepair Native",
   "author": "yorkie-team",
   "repository": {
     "type": "git",
-    "url": "https://github.com/minai621/codepair"
+    "url": "<main-repository-url>"
   },

Let me try another script to get the repository information since the previous command didn't work as expected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the correct repository URL
gh repo view --json url --jq .url

Length of output: 287


Script:

#!/bin/bash
# Try different approaches to get repository info
cat package.json | grep -A 5 "repository"

# Also check if there's a root package.json
cat native/package.json | grep -A 5 "repository"

# Check git remote
git remote -v

Length of output: 366

"scripts": {
"build": "tsc src/main.ts --outDir dist",
"start": "pnpm run build && cross-env NODE_ENV=production pnpx electron dist/main.js",
"start:dev": "pnpm run start:codepair:dev && pnpm run build && cross-env NODE_ENV=development pnpx electron dist/main.js",
"start:codepair:dev": "cd ../frontend && Pnpm run dev & ",
"electron-builder": "pnpm run build && electron-builder",
"release": "pnpm run build && electron-builder --publish always"
},
Comment on lines +12 to +19
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix script configuration issues

There are several issues in the scripts configuration:

  1. The build script should use the project's tsconfig.json
  2. There's a typo in start:codepair:dev (Pnpm vs pnpm)
  3. The background process in start:codepair:dev might not clean up properly
   "scripts": {
-    "build": "tsc src/main.ts --outDir dist",
+    "build": "tsc -p tsconfig.json",
     "start": "pnpm run build && cross-env NODE_ENV=production pnpx electron dist/main.js",
     "start:dev": "pnpm run start:codepair:dev && pnpm run build && cross-env NODE_ENV=development pnpx electron dist/main.js",
-    "start:codepair:dev": "cd ../frontend && Pnpm run dev & ",
+    "start:codepair:dev": "cd ../frontend && pnpm run dev",
     "electron-builder": "pnpm run build && electron-builder",
     "release": "pnpm run build && electron-builder --publish always"
   },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"scripts": {
"build": "tsc src/main.ts --outDir dist",
"start": "pnpm run build && cross-env NODE_ENV=production pnpx electron dist/main.js",
"start:dev": "pnpm run start:codepair:dev && pnpm run build && cross-env NODE_ENV=development pnpx electron dist/main.js",
"start:codepair:dev": "cd ../frontend && Pnpm run dev & ",
"electron-builder": "pnpm run build && electron-builder",
"release": "pnpm run build && electron-builder --publish always"
},
"scripts": {
"build": "tsc -p tsconfig.json",
"start": "pnpm run build && cross-env NODE_ENV=production pnpx electron dist/main.js",
"start:dev": "pnpm run start:codepair:dev && pnpm run build && cross-env NODE_ENV=development pnpx electron dist/main.js",
"start:codepair:dev": "cd ../frontend && pnpm run dev",
"electron-builder": "pnpm run build && electron-builder",
"release": "pnpm run build && electron-builder --publish always"
},

"devDependencies": {
"@types/node": "^22.7.6",
"cross-env": "^7.0.3",
"electron": "^33.0.1",
"electron-builder": "^25.1.8",
"typescript": "^5.3.3"
},
"build": {
"publish": {
"provider": "github"
},
"appId": "com.example.codepair",
"productName": "codepair",
"files": [
"dist/**/*",
"node_modules/**/*",
"package.json",
"!node_modules/**/*.{ts,map}"
],
"directories": {
"output": "release"
},
"mac": {
"target": "dmg"
},
"win": {
"target": [
{
"target": "nsis",
"arch": [
"x64"
]
}
]
},
"nsis": {
"oneClick": false,
"allowToChangeInstallationDirectory": true
},
"linux": {
"target": "AppImage"
}
}
}
30 changes: 30 additions & 0 deletions native/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { app, BrowserWindow } from "electron";

function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
},
});
Comment on lines +4 to +10
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Secure the BrowserWindow configuration

The current window configuration has security vulnerabilities. Node integration should be disabled by default, and a preload script should be used instead.

Apply these security-focused changes:

 const win = new BrowserWindow({
   width: 800,
   height: 600,
   webPreferences: {
-    nodeIntegration: true,
+    nodeIntegration: false,
+    contextIsolation: true,
+    sandbox: true,
+    preload: path.join(__dirname, 'preload.js')
   },
 });

Committable suggestion skipped: line range outside the PR's diff.

if (process.env.NODE_ENV === "development") {
win.loadURL("http://localhost:5173");
} else {
win.loadURL("https://codepair.yorkie.dev");
}
Comment on lines +11 to +15
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for URL loading

The URL loading lacks error handling and validation. Also, consider adding security headers for the loaded content.

Consider this improved implementation:

 if (process.env.NODE_ENV === "development") {
-  win.loadURL("http://localhost:5173");
+  win.loadURL("http://localhost:5173").catch(err => {
+    console.error('Failed to load dev server:', err);
+  });
 } else {
-  win.loadURL("https://codepair.yorkie.dev");
+  win.loadURL("https://codepair.yorkie.dev", {
+    httpHeaders: {
+      'Content-Security-Policy': "default-src 'self' https://codepair.yorkie.dev"
+    }
+  }).catch(err => {
+    console.error('Failed to load production URL:', err);
+  });
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (process.env.NODE_ENV === "development") {
win.loadURL("http://localhost:5173");
} else {
win.loadURL("https://codepair.yorkie.dev");
}
if (process.env.NODE_ENV === "development") {
win.loadURL("http://localhost:5173").catch(err => {
console.error('Failed to load dev server:', err);
});
} else {
win.loadURL("https://codepair.yorkie.dev", {
httpHeaders: {
'Content-Security-Policy': "default-src 'self' https://codepair.yorkie.dev"
}
}).catch(err => {
console.error('Failed to load production URL:', err);
});
}

}

app.whenReady().then(createWindow);

app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});

app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
18 changes: 18 additions & 0 deletions native/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"outDir": "dist",
"esModuleInterop": true,
"skipLibCheck": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],

/* Bundler mode */
"moduleResolution": "bundler",

/* Linting */
"strict": true
},
"include": ["src"],
"exclude": ["dist"]
}