Skip to content

Commit

Permalink
Feature CICD for MacOS and Windows (janhq#263)
Browse files Browse the repository at this point in the history
* Separate CICD into multi platform
* Update yarn script to build multi-platform and arch

---------

Co-authored-by: Hien To <[email protected]>
Co-authored-by: Hien To <>
  • Loading branch information
hiento09 and hiento09 authored Oct 4, 2023
1 parent 4275da9 commit 517d651
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 65 deletions.
151 changes: 151 additions & 0 deletions .github/workflows/build-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
name: Jan Build MacOS App

on:
push:
tags: ['v*.*.*']

jobs:
build-macos:
runs-on: macos-latest
environment: production
permissions:
contents: write
steps:
- name: Getting the repo
uses: actions/checkout@v3

- name: Installing node
uses: actions/setup-node@v1
with:
node-version: 20

- name: Install jq
uses: dcarbone/[email protected]

- name: Get tag
id: tag
uses: dawidd6/action-get-tag@v1

- name: Update app version base on tag
run: |
if [[ ! "${VERSION_TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Tag is not valid!"
exit 1
fi
jq --arg version "${VERSION_TAG#v}" '.version = $version' electron/package.json > /tmp/package.json
mv /tmp/package.json electron/package.json
env:
VERSION_TAG: ${{ steps.tag.outputs.tag }}

- name: Install yarn dependencies
run: |
yarn install
yarn build:plugins
- name: Get Cer for code signing
run: base64 -d <<< "$CODE_SIGN_P12_BASE64" > /tmp/codesign.p12
shell: bash
env:
CODE_SIGN_P12_BASE64: ${{ secrets.CODE_SIGN_P12_BASE64 }}

- name: Build and publish app
run: |
yarn build:publish-darwin
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CSC_LINK: "/tmp/codesign.p12"
CSC_KEY_PASSWORD: ${{ secrets.CODE_SIGN_P12_PASSWORD }}
CSC_IDENTITY_AUTO_DISCOVERY: "true"

build-windows-x64:
runs-on: windows-latest
permissions:
contents: write
steps:
- name: Getting the repo
uses: actions/checkout@v3

- name: Installing node
uses: actions/setup-node@v1
with:
node-version: 20

- name: Install jq
uses: dcarbone/[email protected]

- name: Get tag
id: tag
uses: dawidd6/action-get-tag@v1

- name: Update app version base on tag
shell: bash
run: |
if [[ ! "${VERSION_TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Tag is not valid!"
exit 1
fi
jq --arg version "${VERSION_TAG#v}" '.version = $version' electron/package.json > /tmp/package.json
mv /tmp/package.json electron/package.json
env:
VERSION_TAG: ${{ steps.tag.outputs.tag }}

- name: Install yarn dependencies
run: |
yarn config set network-timeout 300000
yarn install
yarn build:plugins
- name: Build and publish app
run: |
yarn build:publish-win32
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-linux-x64:
runs-on: ubuntu-latest
environment: production
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_TOKEN }}
permissions:
contents: write
steps:
- name: Getting the repo
uses: actions/checkout@v3

- name: Installing node
uses: actions/setup-node@v1
with:
node-version: 20

- name: Install jq
uses: dcarbone/[email protected]

- name: Install Snapcraft
uses: samuelmeuli/action-snapcraft@v2

- name: Get tag
id: tag
uses: dawidd6/action-get-tag@v1

- name: Update app version base on tag
run: |
if [[ ! "${VERSION_TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Tag is not valid!"
exit 1
fi
jq --arg version "${VERSION_TAG#v}" '.version = $version' electron/package.json > /tmp/package.json
mv /tmp/package.json electron/package.json
env:
VERSION_TAG: ${{ steps.tag.outputs.tag }}

- name: Install yarn dependencies
run: |
yarn config set network-timeout 300000
yarn install
yarn build:plugins
- name: Build and publish app
run: |
yarn build:publish-linux
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50 changes: 0 additions & 50 deletions .github/workflows/macos-build-app.yml

This file was deleted.

3 changes: 2 additions & 1 deletion electron/core/plugins/data-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"scripts": {
"build": "tsc -b . && webpack --config webpack.config.js",
"build:package": "rimraf ./data-plugin*.tgz && npm run build && npm pack",
"build:package": "rimraf ./data-plugin*.tgz && node-pre-gyp install --directory=./node_modules/sqlite3 --target_platform=darwin --target_libc=unknown --target_arch=x64 && node-pre-gyp install --directory=./node_modules/sqlite3 --target_platform=darwin --target_libc=unknown --target_arch=arm64 && node-pre-gyp install --directory=./node_modules/sqlite3 --target_platform=linux --target_libc=glibc --target_arch=x64 && node-pre-gyp install --directory=./node_modules/sqlite3 --target_platform=linux --target_libc=musl --target_arch=x64 && node-pre-gyp install --directory=./node_modules/sqlite3 --target_platform=win32 --target_libc=unknown --target_arch=x64 && npm run build && npm pack",
"build:publish": "npm run build:package && cpx *.tgz ../../pre-install"
},
"exports": {
Expand All @@ -37,6 +37,7 @@
"node_modules"
],
"dependencies": {
"node-pre-gyp": "^0.17.0",
"sqlite3": "^5.1.6"
}
}
17 changes: 13 additions & 4 deletions electron/core/plugins/inference-plugin/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,19 @@ async function initModel(product) {
// Write the updated config back to the file
fs.writeFileSync(configFilePath, JSON.stringify(config, null, 4));

const binaryPath =
process.platform === "win32"
? path.join(binaryFolder, "nitro.exe")
: path.join(binaryFolder, "nitro");
let binaryName;

if (process.platform === "win32") {
binaryName = "nitro.exe";
} else if (process.platform === "darwin") { // Mac OS platform
binaryName = process.arch === "arm64" ? "nitro" : "nitro_mac_intel";
} else {
// Linux
binaryName = "nitro_linux"; // For other platforms
}

const binaryPath = path.join(binaryFolder, binaryName);

// Execute the binary

subprocess = spawn(binaryPath, [configFilePath], { cwd: binaryFolder });
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion electron/core/plugins/inference-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"scripts": {
"build": "webpack --config webpack.config.js",
"build:package": "rimraf ./*.tgz && npm run build && cpx \"module.js\" \"dist\" && rm -rf dist/nitro && cp -r nitro dist/nitro && npm pack",
"build:package": "rimraf ./*.tgz && npm run build && cpx \"module.js\" \"dist\" && rimraf dist/nitro/* && cpx \"nitro/**\" \"dist/nitro\" && npm pack",
"build:publish": "yarn build:package && cpx *.tgz ../../pre-install"
},
"devDependencies": {
Expand Down
18 changes: 12 additions & 6 deletions electron/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "jan-electron",
"version": "0.1.1",
"version": "0.1.3",
"main": "./build/main.js",
"author": "Jan",
"author": "Jan <[email protected]>",
"license": "MIT",
"homepage": "./",
"build": {
Expand All @@ -12,7 +12,8 @@
"renderer/**/*",
"build/*.{js,map}",
"build/**/*.{js,map}",
"core/pre-install"
"core/pre-install",
"core/plugin-manager/facade"
],
"asarUnpack": [
"core/pre-install"
Expand All @@ -32,9 +33,14 @@
"scripts": {
"lint": "eslint . --ext \".js,.jsx,.ts,.tsx\"",
"dev": "tsc -p . && electron .",
"build": "tsc -p . && electron-builder -p never -mw",
"build:publish": "tsc -p . && electron-builder -p onTagOrDraft -mw",
"postinstall": "electron-builder install-app-deps"
"build": "tsc -p . && electron-builder -p never -m",
"build:darwin": "tsc -p . && electron-builder -p never -m --x64 --arm64",
"build:win32": "tsc -p . && electron-builder -p never -w",
"build:linux": "tsc -p . && electron-builder -p never --linux deb",
"build:publish": "tsc -p . && electron-builder -p onTagOrDraft -m",
"build:publish-darwin": "tsc -p . && electron-builder -p onTagOrDraft -m --x64 --arm64",
"build:publish-win32": "tsc -p . && electron-builder -p onTagOrDraft -w",
"build:publish-linux": "tsc -p . && electron-builder -p onTagOrDraft --linux deb "
},
"dependencies": {
"@npmcli/arborist": "^7.1.0",
Expand Down
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@
"dev": "concurrently --kill-others \"yarn dev:web\" \"wait-on http://localhost:3000 && yarn dev:electron\"",
"build:web": "yarn workspace jan-web build && cpx \"web/out/**\" \"electron/renderer/\"",
"build:electron": "yarn workspace jan-electron build",
"build:plugins": "rm -f ./electron/core/pre-install/*.tgz && concurrently \"cd ./electron/core/plugins/data-plugin && npm install && npm run build:publish\" \"cd ./electron/core/plugins/inference-plugin && npm install && npm run build:publish\" \"cd ./electron/core/plugins/model-management-plugin && npm install && npm run build:publish\" \"cd ./electron/core/plugins/monitoring-plugin && npm install && npm run build:publish\"",
"build:plugins": "rimraf ./electron/core/pre-install/*.tgz && concurrently \"cd ./electron/core/plugins/data-plugin && npm install && npm run build:publish\" \"cd ./electron/core/plugins/inference-plugin && npm install && npm run build:publish\" \"cd ./electron/core/plugins/model-management-plugin && npm install && npm run build:publish\" \"cd ./electron/core/plugins/monitoring-plugin && npm install && npm run build:publish\"",
"build": "yarn build:web && yarn build:electron",
"build:publish": "yarn build:web && yarn workspace jan-electron build:publish"
"build:darwin": "yarn build:web && yarn workspace jan-electron build:darwin",
"build:win32": "yarn build:web && yarn workspace jan-electron build:win32",
"build:linux": "yarn build:web && yarn workspace jan-electron build:linux",
"build:publish": "yarn build:web && yarn workspace jan-electron build:publish",
"build:publish-darwin": "yarn build:web && yarn workspace jan-electron build:publish-darwin",
"build:publish-win32": "yarn build:web && yarn workspace jan-electron build:publish-win32",
"build:publish-linux": "yarn build:web && yarn workspace jan-electron build:publish-linux"
},
"devDependencies": {
"concurrently": "^8.2.1",
"cpx": "^1.5.0",
"wait-on": "^7.0.1"
"wait-on": "^7.0.1",
"rimraf": "^3.0.2"
},
"version": "0.0.0"
}

0 comments on commit 517d651

Please sign in to comment.