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

WIP Attempt to Migrate to Electron Forge + GitHub Actions for CI/CD #255

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
43 changes: 43 additions & 0 deletions .github/workflows/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build Lifecycle

on:
pull_request:
push:
branches: [main]

jobs:
build:
name: Build (${{ matrix.os }})
# Assumes we are using tags for releases
if: startsWith(github.ref, 'refs/tags/')
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
steps:
- name: Install Dependencies (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libx11-dev libxkbfile-dev libsecret-1-dev fakeroot rpm

- name: GitHub Checkout
uses: actions/checkout@v3
with:
ref: '${{ github.head_ref }}'
token: '${{ secrets.GH_PAT }}'

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 20

- name: npm install
run: npm install

- name: Add Mac OS Certs
if: matrix.os == 'macos-latest'
run: chmod +x ./scripts/add-mac-certs.sh && ./scripts/add-mac-certs.sh
env:
CERTIFICATE_OSX_APPLICATION: ${{ secrets.CERTIFICATE_OSX_APPLICATION }}
CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }}
23 changes: 23 additions & 0 deletions add-osx-cert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env sh

KEY_CHAIN=build.keychain
CERTIFICATE_P12=certificate.p12

# Recreate the certificate from the secure environment variable
echo $CERTIFICATE_OSX_APPLICATION | base64 --decode > $CERTIFICATE_P12

#create a keychain
security create-keychain -p actions $KEY_CHAIN

# Make the keychain the default so identities are found
security default-keychain -s $KEY_CHAIN

# Unlock the keychain
security unlock-keychain -p actions $KEY_CHAIN

security import $CERTIFICATE_P12 -k $KEY_CHAIN -P $CERTIFICATE_PASSWORD -T /usr/bin/codesign;

security set-key-partition-list -S apple-tool:,apple: -s -k actions $KEY_CHAIN

# remove certs
rm -fr *.p12
139 changes: 139 additions & 0 deletions forge.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { MakerDeb } from '@electron-forge/maker-deb';
import { MakerDMG } from '@electron-forge/maker-dmg';
import { MakerRpm } from '@electron-forge/maker-rpm';
import { MakerSquirrel } from '@electron-forge/maker-squirrel';
import { AutoUnpackNativesPlugin } from '@electron-forge/plugin-auto-unpack-natives';
import { WebpackPlugin } from '@electron-forge/plugin-webpack';
import type { ForgeConfig } from '@electron-forge/shared-types';
import { app } from 'electron';
import path from 'path';
import { PublisherGithub } from '@electron-forge/publisher-github';
import Electron from 'electron';
import rendererProdConfig from './scripts/configs/webpack.config.renderer.prod';
import rendererDevConfig from './scripts/configs/webpack.config.renderer.dev';
import mainProdConfig from './scripts/configs/webpack.config.main.prod';
import mainDevConfig from './scripts/configs/webpack.config.preload.dev';

console.log('process.env.NODE_ENV', process.env.NODE_ENV);
const isProduction = process.env.NODE_ENV === 'production';

const PRODUCT_NAME = 'GodMode';
// TODO: Use this for assets (e.g. icons)
// const APP_PATH = './src/images';

// const IMAGES_PATH =
// app && app.isPackaged
// ? path.join(process.resourcesPath, 'src/images')
// : path.join(__dirname, './src/images');

const config: ForgeConfig = {
packagerConfig: {
asar: true,

// TODO: Uncomment these when ready to notarize and sign
// osxNotarize: {
// appBundleId: 'com.example.electron-forge',
// appleId: process.env.APPLE_ID,
// appleIdPassword: process.env.APPLE_ID_PASSWORD,
// ascProvider: process.env.ASC_PROVIDER,
// },

// osxSign: {
// hardenedRuntime: true,
// identity: 'Developer ID Application: Your Name (XXXXXXXXXX)',
// 'gatekeeper-assess': false,
// 'entitlements': '/entitlements.mac.plist',
// 'entitlements-inherit': '/entitlements.mac.plist',
// },
},
rebuildConfig: {},
makers: [
// Windows
new MakerSquirrel({
name: PRODUCT_NAME,
// https://www.electronforge.io/guides/code-signing/code-signing-windows
// certificateFile: './cert.pfx',
// certificatePassword: process.env.CERTIFICATE_PASSWORD,
setupIcon: `${__dirname}/src/images/[email protected]`,
}),

// Zip
// TODO: Do we want to make a zip?
// new MakerZIP({}, ['darwin']),

// Redhat Package Manager
new MakerRpm({
options: {
homepage: 'https://smol.ai/',
genericName: PRODUCT_NAME,
},
}),

// Debian Package Manager
new MakerDeb({
options: {
genericName: PRODUCT_NAME,
maintainer: 'smol-ai',
homepage: 'https://smol.ai/',
// icon: './assets/icons/icon.png',
},
}),

// Apple Disk Image
new MakerDMG({
name: PRODUCT_NAME,
format: 'ULFO',
icon: `${__dirname}/src/images/[email protected]`,
iconSize: 128,
// background: './assets/icons/background.png', // TODO: Background image for DMG installer
contents: [
{
x: 448,
y: 344,
type: 'link',
path: '/Applications',
name: 'Applications',
},
{
x: 192,
y: 344,
type: 'file',
path: `${__dirname}/out/GodMode-darwin-arm64/GodMode.app`,
name: 'GodMode.app',
},
],
}),
],
publishers: [
new PublisherGithub(
{
repository: {
owner: 'smol-ai',
name: PRODUCT_NAME,
},
},
['darwin', 'win32'],
),
],
plugins: [
new AutoUnpackNativesPlugin({}),
new WebpackPlugin({
mainConfig: isProduction ? mainProdConfig : mainDevConfig,
renderer: {
config: isProduction ? rendererDevConfig : rendererProdConfig,
entryPoints: [
{
html: './src/renderer/index.ejs',
js: './src/renderer/index.tsx',
name: 'main_window',
preload: {
js: './src/main/preload.ts',
},
},
],
},
}),
],
};

export default config;
Loading