From df163a85e534b16fd3937baf7ba5cc5b15e24c5c Mon Sep 17 00:00:00 2001 From: hiento09 <136591877+hiento09@users.noreply.github.com> Date: Wed, 22 Nov 2023 17:48:02 +0700 Subject: [PATCH] Chore: refactor to makefile (#691) * Add makefile for jan * CICD switchs to use make * Update README.md to use Makefile --------- Co-authored-by: Hien To --- .github/workflows/jan-electron-build.yml | 74 ++----------------- .../jan-electron-linter-and-test.yml | 43 +---------- Makefile | 62 ++++++++++++++++ README.md | 34 +-------- 4 files changed, 77 insertions(+), 136 deletions(-) create mode 100644 Makefile diff --git a/.github/workflows/jan-electron-build.yml b/.github/workflows/jan-electron-build.yml index db585e3c1..118d6c3a0 100644 --- a/.github/workflows/jan-electron-build.yml +++ b/.github/workflows/jan-electron-build.yml @@ -28,12 +28,7 @@ jobs: - 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 + make update-app-version env: VERSION_TAG: ${{ steps.tag.outputs.tag }} @@ -49,25 +44,9 @@ jobs: p12-file-base64: ${{ secrets.CODE_SIGN_P12_BASE64 }} p12-password: ${{ secrets.CODE_SIGN_P12_PASSWORD }} - - - name: Build uikit - run: | - cd uikit - yarn install - yarn build - - - name: Install yarn dependencies - run: | - yarn build:core - yarn install - yarn build:plugins - env: - APP_PATH: "." - DEVELOPER_ID: ${{ secrets.DEVELOPER_ID }} - - name: Build and publish app run: | - yarn build:publish + make build-and-publish env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} CSC_LINK: "/tmp/codesign.p12" @@ -75,6 +54,8 @@ jobs: CSC_IDENTITY_AUTO_DISCOVERY: "true" APPLE_ID: ${{ secrets.APPLE_ID }} APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }} + APP_PATH: "." + DEVELOPER_ID: ${{ secrets.DEVELOPER_ID }} build-windows-x64: runs-on: windows-latest @@ -99,34 +80,13 @@ jobs: - 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 + make update-app-version env: VERSION_TAG: ${{ steps.tag.outputs.tag }} - - name: Build uikit - run: | - cd uikit - yarn config set network-timeout 300000 - yarn install - yarn build - - - name: Install yarn dependencies - shell: powershell - run: | - yarn config set network-timeout 300000 - yarn build:core - yarn install - $env:NITRO_VERSION = Get-Content .\plugins\inference-plugin\nitro\version.txt; echo $env:NITRO_VERSION - yarn build:plugins - - name: Build and publish app run: | - yarn build:publish + make build-and-publish env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -158,31 +118,13 @@ jobs: - 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 + make update-app-version env: VERSION_TAG: ${{ steps.tag.outputs.tag }} - - name: Build uikit - run: | - cd uikit - yarn install - yarn build - - - name: Install yarn dependencies - run: | - yarn config set network-timeout 300000 - yarn build:core - yarn install - yarn build:plugins - - name: Build and publish app run: | - yarn build:publish + make build-and-publish env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/jan-electron-linter-and-test.yml b/.github/workflows/jan-electron-linter-and-test.yml index 92f29c368..7717afbd4 100644 --- a/.github/workflows/jan-electron-linter-and-test.yml +++ b/.github/workflows/jan-electron-linter-and-test.yml @@ -43,21 +43,9 @@ jobs: with: node-version: 20 - - name: Build uikit - run: | - cd uikit - yarn install - yarn build - - name: Linter and test run: | - yarn config set network-timeout 300000 - yarn build:core - yarn install - yarn lint - yarn build:plugins - yarn build:test - yarn test + make test env: CSC_IDENTITY_AUTO_DISCOVERY: "false" @@ -81,24 +69,10 @@ jobs: with: node-version: 20 - - name: Build uikit - run: | - yarn config set network-timeout 300000 - cd uikit - yarn install - yarn build - - name: Linter and test shell: powershell run: | - yarn config set network-timeout 300000 - yarn build:core - yarn install - $env:NITRO_VERSION = Get-Content .\plugins\inference-plugin\nitro\version.txt; echo $env:NITRO_VERSION - yarn build:plugins - yarn build:test - $env:CI="e2e" - yarn test + make test test-on-ubuntu: runs-on: [self-hosted, Linux, ubuntu-desktop] @@ -118,19 +92,8 @@ jobs: with: node-version: 20 - - name: Build uikit - run: | - cd uikit - yarn install - yarn build - - name: Linter and test run: | export DISPLAY=$(w -h | awk 'NR==1 {print $2}') echo -e "Display ID: $DISPLAY" - yarn config set network-timeout 300000 - yarn build:core - yarn install - yarn build:plugins - yarn build:test - yarn test + make test diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..3d04b745f --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +# Makefile for Jan Electron App - Build, Lint, Test, and Clean + +# Default target, does nothing +all: + @echo "Specify a target to run" + +# Builds the UI kit +build-uikit: +ifeq ($(OS),Windows_NT) + cd uikit && yarn config set network-timeout 300000 && yarn install && yarn build +else + cd uikit && yarn install && yarn build +endif +# Updates the app version based on the tag +update-app-version: + 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 + +# Installs yarn dependencies and builds core and plugins +install-and-build: build-uikit +ifeq ($(OS),Windows_NT) + powershell -Command "yarn config set network-timeout 300000; \ + $$env:NITRO_VERSION = Get-Content .\\plugins\\inference-plugin\\nitro\\version.txt; \ + Write-Output \"Nitro version: $$env:NITRO_VERSION\"; yarn build:core; yarn install; yarn build:plugins" +else + yarn build:core + yarn install + yarn build:plugins +endif + +dev: install-and-build + yarn dev + +# Linting +lint: install-and-build + yarn lint + +# Testing +test: lint + yarn build:test + yarn test + +# Builds and publishes the app +build-and-publish: install-and-build + yarn build:publish + +# Build +build: install-and-build + yarn build + +clean: +ifeq ($(OS),Windows_NT) + powershell -Command "Get-ChildItem -Path . -Include node_modules, .next, dist -Recurse -Directory | Remove-Item -Recurse -Force" +else + find . -name "node_modules" -type d -prune -exec rm -rf '{}' + + find . -name ".next" -type d -exec rm -rf '{}' + + find . -name "dist" -type d -exec rm -rf '{}' + +endif diff --git a/README.md b/README.md index 8405eb74e..75214d940 100644 --- a/README.md +++ b/README.md @@ -91,11 +91,10 @@ Contributions are welcome! Please read the [CONTRIBUTING.md](CONTRIBUTING.md) fi - node >= 20.0.0 - yarn >= 1.22.0 +- make >= 3.81 ### Instructions -Note: This instruction is tested on MacOS only. - 1. **Clone the Repository:** ```bash @@ -104,25 +103,10 @@ Note: This instruction is tested on MacOS only. cd jan ``` -2. **Install dependencies:** - -```bash - yarn install - - # Build core module - yarn build:core - - # Packing base plugins - yarn build:plugins - - # Packing uikit - yarn build:uikit -``` - -3. **Run development and Using Jan Desktop** +2. **Run development and Using Jan Desktop** ``` - yarn dev + make dev ``` This will start the development server and open the desktop app. @@ -134,19 +118,9 @@ Note: This instruction is tested on MacOS only. # Do step 1 and 2 in previous section git clone https://github.com/janhq/jan cd jan -yarn install - -# Build core module -yarn build:core - -# Package base plugins -yarn build:plugins - -# Packing uikit -yarn build:uikit # Build the app -yarn build +make build ``` This will build the app MacOS m1/m2 for production (with code signing already done) and put the result in `dist` folder.