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

Macos add local installer #1335

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions .github/workflows/beta-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
channel: beta
arch: amd64
upload_url: ${{ needs.create-draft-release.outputs.upload_url }}
cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }}

build-macos-arm64:
uses: ./.github/workflows/template-build-macos.yml
Expand All @@ -63,6 +64,7 @@ jobs:
channel: beta
arch: arm64
upload_url: ${{ needs.create-draft-release.outputs.upload_url }}
cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }}

build-windows-x64:
uses: ./.github/workflows/template-build-windows-x64.yml
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
cmake-flags: "-DCORTEX_VARIANT=nightly -DCORTEX_CPP_VERSION='v${{ needs.get-update-version.outputs.new_version }}' -DCMAKE_TOOLCHAIN_FILE=/Users/runner/work/cortex.cpp/cortex.cpp/engine/vcpkg/scripts/buildsystems/vcpkg.cmake"
channel: nightly
arch: amd64
cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }}

build-macos-arm64:
uses: ./.github/workflows/template-build-macos.yml
Expand All @@ -71,6 +72,7 @@ jobs:
cmake-flags: "-DCORTEX_VARIANT=nightly -DCORTEX_CPP_VERSION='v${{ needs.get-update-version.outputs.new_version }}' -DMAC_ARM64=ON -DCMAKE_TOOLCHAIN_FILE=/Users/runner/work/cortex.cpp/cortex.cpp/engine/vcpkg/scripts/buildsystems/vcpkg.cmake"
channel: nightly
arch: arm64
cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }}

build-windows-x64:
uses: ./.github/workflows/template-build-windows-x64.yml
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/stable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
channel: stable
arch: amd64
upload_url: ${{ needs.create-draft-release.outputs.upload_url }}
cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }}

build-macos-arm64:
uses: ./.github/workflows/template-build-macos.yml
Expand All @@ -63,6 +64,7 @@ jobs:
channel: stable
arch: arm64
upload_url: ${{ needs.create-draft-release.outputs.upload_url }}
cortex-llamacpp-version: ${{ needs.get-cortex-llamacpp-latest-version.outputs.cortex_llamacpp_latest_version }}

build-windows-x64:
uses: ./.github/workflows/template-build-windows-x64.yml
Expand Down
67 changes: 58 additions & 9 deletions .github/workflows/template-build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ on:
type: string
default: 'arm64'
description: 'The architecture to use for this job'
cortex-llamacpp-version:
required: true
type: string
default: '0.0.0'
description: 'The version of cortex-llamacpp to use for this job'
secrets:
DELTA_AWS_S3_BUCKET_NAME:
required: false
Expand Down Expand Up @@ -78,7 +83,7 @@ on:
required: false

jobs:
build-mac-x64:
build-mac:
runs-on: ${{ inputs.runs-on }}
permissions:
contents: write
Expand Down Expand Up @@ -169,7 +174,7 @@ jobs:
QUILL_NOTARY_ISSUER: ${{ secrets.NOTARY_ISSUER }}
QUILL_NOTARY_KEY: "/tmp/notary-key.p8"

- name: Build Installers
- name: Build network Installers
shell: bash
run: |
cd engine
Expand All @@ -185,8 +190,34 @@ jobs:
productbuild --synthesize --package Distribution.pkg Distribution.xml
sed -i '' 's/require-scripts="false"/require-scripts="true"/' Distribution.xml
cat Distribution.xml
productbuild --distribution Distribution.xml --sign "Developer ID Installer: ${{ secrets.DEVELOPER_ID }}" --package-path . ${{ steps.set-output-params.outputs.package_name }}.pkg
xcrun notarytool submit ${{ steps.set-output-params.outputs.package_name }}.pkg --apple-id ${{ secrets.APPLE_ID }} --password ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }} --team-id ${{ secrets.APPLE_TEAM_ID }} --wait
productbuild --distribution Distribution.xml --sign "Developer ID Installer: ${{ secrets.DEVELOPER_ID }}" --package-path . ${{ steps.set-output-params.outputs.package_name }}-network.pkg
xcrun notarytool submit ${{ steps.set-output-params.outputs.package_name }}-network.pkg --apple-id ${{ secrets.APPLE_ID }} --password ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }} --team-id ${{ secrets.APPLE_TEAM_ID }} --wait

- name: Build local Installers
shell: bash
run: |
mkdir -p engine/templates/macos/Scripts/dependencies
cd engine/templates/macos/Scripts/dependencies
wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-mac-amd64.tar.gz
wget https://github.com/janhq/cortex.llamacpp/releases/download/v${{ inputs.cortex-llamacpp-version }}/cortex.llamacpp-${{ inputs.cortex-llamacpp-version }}-mac-arm64.tar.gz

cd ../../
chmod +x create_pkg_local.sh
./create_pkg_local.sh ${{ steps.set-output-params.outputs.package_name }} ${{ inputs.new_version }} ../../cortex/${{ steps.set-output-params.outputs.destination_binary_name }} ${{ steps.set-output-params.outputs.destination_binary_name }} ${{ steps.set-output-params.outputs.data_folder_name }} ${{ steps.set-output-params.outputs.configuration_file_name }} ${{ steps.set-output-params.outputs.uninstaller_file_name }}
cp ${{ steps.set-output-params.outputs.package_name }}.pkg ../../

- name: Codesign and notary for macos installer
run: |
cd engine
productsign --sign "Developer ID Installer: ${{ secrets.DEVELOPER_ID }}" ${{ steps.set-output-params.outputs.package_name }}.pkg ${{ steps.set-output-params.outputs.package_name }}$-signed.pkg
rm ${{ steps.set-output-params.outputs.package_name }}.pkg
mv ${{ steps.set-output-params.outputs.package_name }}$-signed.pkg Distribution.pkg
productbuild --synthesize --package Distribution.pkg Distribution.xml
sed -i '' 's/require-scripts="false"/require-scripts="true"/' Distribution.xml
cat Distribution.xml
productbuild --distribution Distribution.xml --sign "Developer ID Installer: ${{ secrets.DEVELOPER_ID }}" --package-path . ${{ steps.set-output-params.outputs.package_name }}-local.pkg
xcrun notarytool submit ${{ steps.set-output-params.outputs.package_name }}-local.pkg --apple-id ${{ secrets.APPLE_ID }} --password ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }} --team-id ${{ secrets.APPLE_TEAM_ID }} --wait


- name: Package
run: |
Expand All @@ -202,16 +233,23 @@ jobs:
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-installer
path: ./engine/${{ steps.set-output-params.outputs.package_name }}.pkg
name: cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-network-installer
path: ./engine/${{ steps.set-output-params.outputs.package_name }}-network.pkg

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-local-installer
path: ./engine/${{ steps.set-output-params.outputs.package_name }}-local.pkg

- name: upload to aws s3 if public provider is aws
if: inputs.public_provider == 'aws-s3'
run: |
aws s3 cp ./engine/cortex.tar.gz s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/temp-latest/mac-${{ inputs.arch}}-cortex-nightly.tar.gz

aws s3 cp ./engine/cortex.tar.gz s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/v${{ inputs.new_version }}/mac-${{ inputs.arch}}/cortex-nightly.tar.gz
aws s3 cp ./engine/${{ steps.set-output-params.outputs.package_name }}.pkg s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/v${{ inputs.new_version }}/mac-${{ inputs.arch}}/cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-installer.pkg
aws s3 cp ./engine/${{ steps.set-output-params.outputs.package_name }}-network.pkg s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/v${{ inputs.new_version }}/mac-${{ inputs.arch}}/cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-network-installer.pkg
aws s3 cp ./engine/${{ steps.set-output-params.outputs.package_name }}-local.pkg s3://${{ secrets.DELTA_AWS_S3_BUCKET_NAME }}/cortex/v${{ inputs.new_version }}/mac-${{ inputs.arch}}/cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-local-installer.pkg
env:
AWS_ACCESS_KEY_ID: ${{ secrets.DELTA_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.DELTA_AWS_SECRET_ACCESS_KEY }}
Expand All @@ -236,6 +274,17 @@ jobs:
uses: actions/upload-release-asset@v1.0.1
with:
upload_url: ${{ inputs.upload_url }}
asset_path: ./engine/${{ steps.set-output-params.outputs.package_name }}.pkg
asset_name: cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-installer.pkg
asset_path: ./engine/${{ steps.set-output-params.outputs.package_name }}-network.pkg
asset_name: cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-network-installer.pkg
asset_content_type: application/octet-stream

- name: Upload release assert if public provider is github
if: inputs.public_provider == 'github'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: actions/upload-release-asset@v1.0.1
with:
upload_url: ${{ inputs.upload_url }}
asset_path: ./engine/${{ steps.set-output-params.outputs.package_name }}-local.pkg
asset_name: cortex-${{ inputs.new_version }}-mac-${{ inputs.arch}}-local-installer.pkg
asset_content_type: application/octet-stream
8 changes: 6 additions & 2 deletions .github/workflows/template-noti-discord.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ jobs:
- Windows:
- Network Installer: https://delta.jan.ai/cortex/v{{ VERSION }}/windows-amd64/cortex-{{ VERSION }}-windows-amd64-network-installer.exe
- Local Installer: https://delta.jan.ai/cortex/v{{ VERSION }}/windows-amd64/cortex-{{ VERSION }}-windows-amd64-local-installer.exe
- macOS Intel: https://delta.jan.ai/cortex/v{{ VERSION }}/mac-amd64/cortex-{{ VERSION }}-mac-amd64-installer.pkg
- macOS Apple Silicon: https://delta.jan.ai/cortex/v{{ VERSION }}/mac-arm64/cortex-{{ VERSION }}-mac-arm64-installer.pkg
- macOS Intel:
- Network Installer: https://delta.jan.ai/cortex/v{{ VERSION }}/mac-amd64/cortex-{{ VERSION }}-mac-amd64-network-installer.pkg
- Local Installer: https://delta.jan.ai/cortex/v{{ VERSION }}/mac-amd64/cortex-{{ VERSION }}-mac-amd64-local-installer.pkg
- macOS Apple Silicon:
- Network Installer: https://delta.jan.ai/cortex/v{{ VERSION }}/mac-arm64/cortex-{{ VERSION }}-mac-arm64-network-installer.pkg
- Local Installer: https://delta.jan.ai/cortex/v{{ VERSION }}/mac-arm64/cortex-{{ VERSION }}-mac-arm64-local-installer.pkg
- Linux Deb: https://delta.jan.ai/cortex/v{{ VERSION }}/linux-amd64/cortex-{{ VERSION }}-linux-amd64-installer.deb
- Github action run: https://github.com/janhq/cortex.cpp/actions/runs/{{ GITHUB_RUN_ID }}
env:
Expand Down
28 changes: 28 additions & 0 deletions engine/templates/macos/create_pkg_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
PACKAGE_NAME=$1
VERSION=$2
SOURCE_BINARY_PATH=$3
DESTINATION_BINARY_NAME=$4
DATA_FOLDER_NAME=$5
CONFIGURATION_FILE_NAME=$6
UNINSTALLER_FILE_NAME=$7

mkdir installer
mkdir Scripts

cp $SOURCE_BINARY_PATH installer/$DESTINATION_BINARY_NAME

export DESTINATION_BINARY_NAME
cp postinstall_local Scripts/postinstall
sed -i '' "3s/.*/DESTINATION_BINARY_NAME=$DESTINATION_BINARY_NAME/" Scripts/postinstall
sed -i '' "4s/.*/DATA_FOLDER_NAME=$DATA_FOLDER_NAME/" Scripts/postinstall
sed -i '' "5s/.*/CONFIGURATION_FILE_NAME=$CONFIGURATION_FILE_NAME/" Scripts/postinstall
chmod +x Scripts/postinstall

export DATA_FOLDER_NAME CONFIGURATION_FILE_NAME UNINSTALLER_FILE_NAME
cp cortex-uninstall.sh installer/$UNINSTALLER_FILE_NAME
sed -i '' "2s/.*/DESTINATION_BINARY_NAME=$DESTINATION_BINARY_NAME/" installer/$UNINSTALLER_FILE_NAME
sed -i '' "3s/.*/DATA_FOLDER_NAME=$DATA_FOLDER_NAME/" installer/$UNINSTALLER_FILE_NAME
sed -i '' "4s/.*/CONFIGURATION_FILE_NAME=$CONFIGURATION_FILE_NAME/" installer/$UNINSTALLER_FILE_NAME
sed -i '' "5s/.*/UNINSTALLER_FILE_NAME=$UNINSTALLER_FILE_NAME/" installer/$UNINSTALLER_FILE_NAME

pkgbuild --identifier ai.cortexcpp.pkg --version $VERSION --scripts Scripts --install-location /usr/local/bin --root ./installer ${PACKAGE_NAME}.pkg
17 changes: 17 additions & 0 deletions engine/templates/macos/postinstall_local
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env sh
set -e
DESTINATION_BINARY_NAME=cortex
DATA_FOLDER_NAME=.cortex
CONFIGURATION_FILE_NAME=.cortexrc

USER_TO_RUN_AS=$(stat -f "%Su" /dev/console)

echo "Download cortex.llamacpp engines by default for user $USER_TO_RUN_AS"
sudo -u $USER_TO_RUN_AS /usr/local/bin/$DESTINATION_BINARY_NAME engines install cortex.llamacpp -s ./dependencies

sudo chown -R $USER_TO_RUN_AS:staff "/Users/$USER_TO_RUN_AS/$DATA_FOLDER_NAME"
sudo chown $USER_TO_RUN_AS:staff "/Users/$USER_TO_RUN_AS/$CONFIGURATION_FILE_NAME"

rm -rf ./dependencies

exit 0
Loading