From bef8dcd6d5dcc8fba9e4269d9f67a43690195dbd Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 2 Feb 2024 10:26:31 +0700 Subject: [PATCH 1/5] fix: load model fail overlays thread message error (#1901) --- web/hooks/useSetActiveThread.ts | 4 ++ web/screens/Chat/ChatBody/index.tsx | 6 +-- .../Chat/LoadModelErrorMessage/index.tsx | 48 ------------------- web/screens/Chat/index.tsx | 5 +- 4 files changed, 7 insertions(+), 56 deletions(-) delete mode 100644 web/screens/Chat/LoadModelErrorMessage/index.tsx diff --git a/web/hooks/useSetActiveThread.ts b/web/hooks/useSetActiveThread.ts index 3545d0d23..f5649ccaf 100644 --- a/web/hooks/useSetActiveThread.ts +++ b/web/hooks/useSetActiveThread.ts @@ -8,6 +8,8 @@ import { import { useAtomValue, useSetAtom } from 'jotai' +import { loadModelErrorAtom } from './useActiveModel' + import { extensionManager } from '@/extension' import { setConvoMessagesAtom } from '@/helpers/atoms/ChatMessage.atom' import { @@ -24,6 +26,7 @@ export default function useSetActiveThread() { const setThreadMessage = useSetAtom(setConvoMessagesAtom) const setThreadModelParams = useSetAtom(setThreadModelParamsAtom) const setIsGeneratingResponse = useSetAtom(isGeneratingResponseAtom) + const setLoadModelError = useSetAtom(loadModelErrorAtom) const setActiveThread = async (thread: Thread) => { if (activeThreadId === thread.id) { @@ -32,6 +35,7 @@ export default function useSetActiveThread() { } setIsGeneratingResponse(false) + setLoadModelError(undefined) events.emit(InferenceEvent.OnInferenceStopped, thread.id) // load the corresponding messages diff --git a/web/screens/Chat/ChatBody/index.tsx b/web/screens/Chat/ChatBody/index.tsx index 1ce6b591f..66f14d076 100644 --- a/web/screens/Chat/ChatBody/index.tsx +++ b/web/screens/Chat/ChatBody/index.tsx @@ -25,7 +25,6 @@ const ChatBody: React.FC = () => { const messages = useAtomValue(getCurrentChatMessagesAtom) const { downloadedModels } = useGetDownloadedModels() const { setMainViewState } = useMainViewState() - const loadModelError = useAtomValue(loadModelErrorAtom) if (downloadedModels.length === 0) return ( @@ -86,9 +85,8 @@ const ChatBody: React.FC = () => { message.content.length > 0) && ( )} - {!loadModelError && - (message.status === MessageStatus.Error || - message.status === MessageStatus.Stopped) && + {(message.status === MessageStatus.Error || + message.status === MessageStatus.Stopped) && index === messages.length - 1 && ( )} diff --git a/web/screens/Chat/LoadModelErrorMessage/index.tsx b/web/screens/Chat/LoadModelErrorMessage/index.tsx deleted file mode 100644 index d3c4a704d..000000000 --- a/web/screens/Chat/LoadModelErrorMessage/index.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import { MessageStatus, ThreadMessage } from '@janhq/core' -import { useAtomValue } from 'jotai' - -import { useActiveModel } from '@/hooks/useActiveModel' - -import { totalRamAtom } from '@/helpers/atoms/SystemBar.atom' - -const LoadModelErrorMessage = () => { - const { activeModel } = useActiveModel() - const availableRam = useAtomValue(totalRamAtom) - - return ( - <> -
- - {Number(activeModel?.metadata.size) > availableRam ? ( - <> - Oops! Model size exceeds available RAM. Consider selecting a - smaller model or upgrading your RAM for smoother performance. - - ) : ( - <> -

Apologies, something's amiss!

- Jan's in beta. Find troubleshooting guides{' '} - - here - {' '} - or reach out to us on{' '} - - Discord - {' '} - for assistance. - - )} -
-
- - ) -} -export default LoadModelErrorMessage diff --git a/web/screens/Chat/index.tsx b/web/screens/Chat/index.tsx index 1f7896604..e3eedb6c1 100644 --- a/web/screens/Chat/index.tsx +++ b/web/screens/Chat/index.tsx @@ -20,7 +20,7 @@ import { snackbar } from '@/containers/Toast' import { FeatureToggleContext } from '@/context/FeatureToggle' -import { activeModelAtom, loadModelErrorAtom } from '@/hooks/useActiveModel' +import { activeModelAtom } from '@/hooks/useActiveModel' import { queuedMessageAtom, reloadModelAtom } from '@/hooks/useSendChatMessage' import ChatBody from '@/screens/Chat/ChatBody' @@ -28,7 +28,6 @@ import ChatBody from '@/screens/Chat/ChatBody' import ThreadList from '@/screens/Chat/ThreadList' import ChatInput from './ChatInput' -import LoadModelErrorMessage from './LoadModelErrorMessage' import RequestDownloadModel from './RequestDownloadModel' import Sidebar from './Sidebar' @@ -70,7 +69,6 @@ const ChatScreen: React.FC = () => { const activeModel = useAtomValue(activeModelAtom) const isGeneratingResponse = useAtomValue(isGeneratingResponseAtom) - const loadModelError = useAtomValue(loadModelErrorAtom) const { getRootProps, isDragReject } = useDropzone({ noClick: true, @@ -213,7 +211,6 @@ const ChatScreen: React.FC = () => { )} {activeModel && isGeneratingResponse && } - {loadModelError && } From eaa3053d404f9926728e0da9c239853669027c87 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 2 Feb 2024 13:28:21 +0700 Subject: [PATCH 2/5] fix: openAIEmbedding now requires top level API Key configuration (#1902) * fix: openAIEmbedding now requires top level API Key configuration * chore: typo --- .../assistant-extension/src/node/tools/retrieval/index.ts | 8 +++----- extensions/inference-nitro-extension/src/index.ts | 3 --- web/screens/Settings/Advanced/index.tsx | 4 ++-- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/extensions/assistant-extension/src/node/tools/retrieval/index.ts b/extensions/assistant-extension/src/node/tools/retrieval/index.ts index cd7e9abb1..8c7a6aa2b 100644 --- a/extensions/assistant-extension/src/node/tools/retrieval/index.ts +++ b/extensions/assistant-extension/src/node/tools/retrieval/index.ts @@ -35,21 +35,19 @@ export class Retrieval { if (engine === "nitro") { this.embeddingModel = new OpenAIEmbeddings( { openAIApiKey: "nitro-embedding" }, - { basePath: "http://127.0.0.1:3928/v1" } + { basePath: "http://127.0.0.1:3928/v1" }, ); } else { // Fallback to OpenAI Settings this.embeddingModel = new OpenAIEmbeddings({ - configuration: { - apiKey: settings.api_key, - }, + openAIApiKey: settings.api_key, }); } } public ingestAgentKnowledge = async ( filePath: string, - memoryPath: string + memoryPath: string, ): Promise => { const loader = new PDFLoader(filePath, { splitPages: true, diff --git a/extensions/inference-nitro-extension/src/index.ts b/extensions/inference-nitro-extension/src/index.ts index 9f1f00263..2b0021ba0 100644 --- a/extensions/inference-nitro-extension/src/index.ts +++ b/extensions/inference-nitro-extension/src/index.ts @@ -226,9 +226,6 @@ export default class JanInferenceNitroExtension extends InferenceExtension { */ private async onMessageRequest(data: MessageRequest) { if (data.model?.engine !== InferenceEngine.nitro || !this._currentModel) { - console.log( - `Model is not nitro or no model loaded ${data.model?.engine} ${this._currentModel}` - ); return; } diff --git a/web/screens/Settings/Advanced/index.tsx b/web/screens/Settings/Advanced/index.tsx index 109431515..d2f7d81ee 100644 --- a/web/screens/Settings/Advanced/index.tsx +++ b/web/screens/Settings/Advanced/index.tsx @@ -109,10 +109,10 @@ const Advanced = () => {
-
NVidia GPU
+
Nvidia GPU

- Enable GPU acceleration for NVidia GPUs. + Enable GPU acceleration for Nvidia GPUs.

Date: Sat, 3 Feb 2024 15:20:42 +0700 Subject: [PATCH 3/5] fix: broken manual import model with NA fields (#1912) --- extensions/model-extension/src/index.ts | 31 +++++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/extensions/model-extension/src/index.ts b/extensions/model-extension/src/index.ts index 5640177a0..b9fa7731e 100644 --- a/extensions/model-extension/src/index.ts +++ b/extensions/model-extension/src/index.ts @@ -286,6 +286,7 @@ export default class JanModelExtension extends ModelExtension { * model.json file associated with it. * * This function will create a model.json file for the model. + * It works only with single binary file model. * * @param dirName the director which reside in ~/jan/models but does not have model.json file. */ @@ -302,15 +303,14 @@ export default class JanModelExtension extends ModelExtension { let binaryFileSize: number | undefined = undefined for (const file of files) { - if (file.endsWith(JanModelExtension._incompletedModelFileName)) continue - if (file.endsWith('.json')) continue - - const path = await joinPath([JanModelExtension._homeDir, dirName, file]) - const fileStats = await fs.fileStat(path) - if (fileStats.isDirectory) continue - binaryFileSize = fileStats.size - binaryFileName = file - break + if (file.endsWith(JanModelExtension._supportedModelFormat)) { + const path = await joinPath([JanModelExtension._homeDir, dirName, file]) + const fileStats = await fs.fileStat(path) + if (fileStats.isDirectory) continue + binaryFileSize = fileStats.size + binaryFileName = file + break + } } if (!binaryFileName) { @@ -318,7 +318,7 @@ export default class JanModelExtension extends ModelExtension { return } - const defaultModel = await this.getDefaultModel() + const defaultModel = await this.getDefaultModel() as Model if (!defaultModel) { console.error('Unable to find default model') return @@ -326,8 +326,19 @@ export default class JanModelExtension extends ModelExtension { const model: Model = { ...defaultModel, + // Overwrite default N/A fields id: dirName, name: dirName, + sources: [ + { + url: binaryFileName, + filename: binaryFileName, + }, + ], + settings: { + ...defaultModel.settings, + llama_model_path: binaryFileName, + }, created: Date.now(), description: `${dirName} - user self import model`, metadata: { From 6ea7d8f6cf985b4811d7f27d3b92dad9db3da350 Mon Sep 17 00:00:00 2001 From: Louis Date: Sat, 3 Feb 2024 16:45:34 +0700 Subject: [PATCH 4/5] fix: migration loading indicator (#1913) --- web/containers/Providers/index.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/web/containers/Providers/index.tsx b/web/containers/Providers/index.tsx index 895c22177..c8a20bca7 100644 --- a/web/containers/Providers/index.tsx +++ b/web/containers/Providers/index.tsx @@ -21,6 +21,8 @@ import { import Umami from '@/utils/umami' +import Loader from '../Loader' + import KeyListener from './KeyListener' import { extensionManager } from '@/extension' @@ -30,6 +32,7 @@ const Providers = (props: PropsWithChildren) => { const [setupCore, setSetupCore] = useState(false) const [activated, setActivated] = useState(false) + const [settingUp, setSettingUp] = useState(false) async function setupExtensions() { // Register all active extensions @@ -37,11 +40,13 @@ const Providers = (props: PropsWithChildren) => { setTimeout(async () => { if (!isCoreExtensionInstalled()) { - setupBaseExtensions() + setSettingUp(true) + await setupBaseExtensions() return } extensionManager.load() + setSettingUp(false) setActivated(true) }, 500) } @@ -71,6 +76,7 @@ const Providers = (props: PropsWithChildren) => { + {settingUp && } {setupCore && activated && ( From 4f751338b7810573dbb0b29d6292386bf6dc637b Mon Sep 17 00:00:00 2001 From: hiento09 <136591877+hiento09@users.noreply.github.com> Date: Sun, 4 Feb 2024 15:44:57 +0700 Subject: [PATCH 5/5] Regression fix assitant extension codesign (#1918) * Separated build macos arm64 and x86_x64 * Update dependencies jobs name * Remove arch from electron-builder command for mac * Add combine latest-mac.yml jobs * Remove unuse workflow job * Add prefix to install js-yaml * Run merge script from /tmp * workflow update release draft depend on combile-latest-mac * correct template path * upload assert release latest-mac.yml overwrite set to true * upload assert release latest-mac.yml overwrite set to true * Grant permission for combine latest-mac jobs --------- Co-authored-by: Hien To --- .github/scripts/auto-sign.sh | 2 + .../workflows/jan-electron-build-nightly.yml | 62 ++++++- .github/workflows/jan-electron-build.yml | 84 ++++++++- .../workflows/template-build-macos-arm64.yml | 160 ++++++++++++++++++ ...macos.yml => template-build-macos-x64.yml} | 5 +- electron/merge-latest-ymls.js | 27 +++ electron/package.json | 4 +- 7 files changed, 331 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/template-build-macos-arm64.yml rename .github/workflows/{template-build-macos.yml => template-build-macos-x64.yml} (97%) create mode 100644 electron/merge-latest-ymls.js diff --git a/.github/scripts/auto-sign.sh b/.github/scripts/auto-sign.sh index 5e6ef9750..a2130e791 100755 --- a/.github/scripts/auto-sign.sh +++ b/.github/scripts/auto-sign.sh @@ -8,3 +8,5 @@ fi # If both variables are set, execute the following commands find "$APP_PATH" \( -type f -perm +111 -o -name "*.node" \) -exec codesign -s "$DEVELOPER_ID" --options=runtime {} \; + +find "$APP_PATH" -type f -name "*.o" -exec codesign -s "$DEVELOPER_ID" --options=runtime {} \; diff --git a/.github/workflows/jan-electron-build-nightly.yml b/.github/workflows/jan-electron-build-nightly.yml index cad2ac227..bc32f9ccc 100644 --- a/.github/workflows/jan-electron-build-nightly.yml +++ b/.github/workflows/jan-electron-build-nightly.yml @@ -48,8 +48,17 @@ jobs: get-update-version: uses: ./.github/workflows/template-get-update-version.yml - build-macos: - uses: ./.github/workflows/template-build-macos.yml + build-macos-x64: + uses: ./.github/workflows/template-build-macos-x64.yml + needs: [get-update-version, set-public-provider] + secrets: inherit + with: + ref: ${{ needs.set-public-provider.outputs.ref }} + public_provider: ${{ needs.set-public-provider.outputs.public_provider }} + new_version: ${{ needs.get-update-version.outputs.new_version }} + + build-macos-arm64: + uses: ./.github/workflows/template-build-macos-arm64.yml needs: [get-update-version, set-public-provider] secrets: inherit with: @@ -76,8 +85,51 @@ jobs: public_provider: ${{ needs.set-public-provider.outputs.public_provider }} new_version: ${{ needs.get-update-version.outputs.new_version }} + combine-latest-mac-yml: + needs: [set-public-provider, build-macos-x64, build-macos-arm64] + runs-on: ubuntu-latest + steps: + - name: Getting the repo + uses: actions/checkout@v3 + with: + ref: ${{ needs.set-public-provider.outputs.ref }} + - name: Download mac-x64 artifacts + uses: actions/download-artifact@v3 + with: + name: latest-mac-x64 + path: ./latest-mac-x64 + - name: Download mac-arm artifacts + uses: actions/download-artifact@v3 + with: + name: latest-mac-arm64 + path: ./latest-mac-arm64 + + - name: 'Merge latest-mac.yml' + # unfortunately electron-builder doesn't understand that we have two different releases for mac-x64 and mac-arm, so we need to manually merge the latest files + # see https://github.com/electron-userland/electron-builder/issues/5592 + run: | + ls -la . + ls -la ./latest-mac-x64 + ls -la ./latest-mac-arm64 + ls -la ./electron + cp ./electron/merge-latest-ymls.js /tmp/merge-latest-ymls.js + npm install js-yaml --prefix /tmp + node /tmp/merge-latest-ymls.js ./latest-mac-x64/latest-mac.yml ./latest-mac-arm64/latest-mac.yml ./latest-mac.yml + cat ./latest-mac.yml + + - name: Upload latest-mac.yml + if: ${{ needs.set-public-provider.outputs.public_provider == 'cloudflare-r2' }} + run: | + aws s3api put-object --endpoint-url https://${{ secrets.CLOUDFLARE_ACCOUNT_ID }}.r2.cloudflarestorage.com --bucket ${{ secrets.CLOUDFLARE_R2_BUCKET_NAME }} --key "latest/latest-mac.yml" --body "./latest-mac.yml" + env: + AWS_ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: auto + AWS_EC2_METADATA_DISABLED: "true" + + noti-discord-nightly-and-update-url-readme: - needs: [build-macos, build-windows-x64, build-linux-x64, get-update-version, set-public-provider] + needs: [build-macos-x64, build-macos-arm64, build-windows-x64, build-linux-x64, get-update-version, set-public-provider, combine-latest-mac-yml] secrets: inherit if: github.event_name == 'schedule' uses: ./.github/workflows/template-noti-discord-and-update-url-readme.yml @@ -88,7 +140,7 @@ jobs: new_version: ${{ needs.get-update-version.outputs.new_version }} noti-discord-pre-release-and-update-url-readme: - needs: [build-macos, build-windows-x64, build-linux-x64, get-update-version, set-public-provider] + needs: [build-macos-x64, build-macos-arm64, build-windows-x64, build-linux-x64, get-update-version, set-public-provider, combine-latest-mac-yml] secrets: inherit if: github.event_name == 'push' uses: ./.github/workflows/template-noti-discord-and-update-url-readme.yml @@ -99,7 +151,7 @@ jobs: new_version: ${{ needs.get-update-version.outputs.new_version }} noti-discord-manual-and-update-url-readme: - needs: [build-macos, build-windows-x64, build-linux-x64, get-update-version, set-public-provider] + needs: [build-macos-x64, build-macos-arm64, build-windows-x64, build-linux-x64, get-update-version, set-public-provider, combine-latest-mac-yml] secrets: inherit if: github.event_name == 'workflow_dispatch' && github.event.inputs.public_provider == 'cloudflare-r2' uses: ./.github/workflows/template-noti-discord-and-update-url-readme.yml diff --git a/.github/workflows/jan-electron-build.yml b/.github/workflows/jan-electron-build.yml index 20102447b..89e130bbd 100644 --- a/.github/workflows/jan-electron-build.yml +++ b/.github/workflows/jan-electron-build.yml @@ -9,8 +9,42 @@ jobs: get-update-version: uses: ./.github/workflows/template-get-update-version.yml - build-macos: - uses: ./.github/workflows/template-build-macos.yml + create-draft-release: + runs-on: ubuntu-latest + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + outputs: + upload_url: ${{ steps.create_release.outputs.upload_url }} + version: ${{ steps.get_version.outputs.version }} + permissions: + contents: write + steps: + - name: Extract tag name without v prefix + id: get_version + run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV && echo "::set-output name=version::${GITHUB_REF#refs/tags/v}" + env: + GITHUB_REF: ${{ github.ref }} + - name: Create Draft Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref_name }} + release_name: "${{ env.VERSION }}" + draft: true + prerelease: false + + build-macos-x64: + uses: ./.github/workflows/template-build-macos-x64.yml + secrets: inherit + needs: [get-update-version] + with: + ref: ${{ github.ref }} + public_provider: github + new_version: ${{ needs.get-update-version.outputs.new_version }} + + build-macos-arm64: + uses: ./.github/workflows/template-build-macos-arm64.yml secrets: inherit needs: [get-update-version] with: @@ -36,8 +70,52 @@ jobs: public_provider: github new_version: ${{ needs.get-update-version.outputs.new_version }} + combine-latest-mac-yml: + needs: [build-macos-x64, build-macos-arm64, create-draft-release] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Getting the repo + uses: actions/checkout@v3 + + - name: Download mac-x64 artifacts + uses: actions/download-artifact@v3 + with: + name: latest-mac-x64 + path: ./latest-mac-x64 + - name: Download mac-arm artifacts + uses: actions/download-artifact@v3 + with: + name: latest-mac-arm64 + path: ./latest-mac-arm64 + + - name: 'Merge latest-mac.yml' + # unfortunately electron-builder doesn't understand that we have two different releases for mac-x64 and mac-arm, so we need to manually merge the latest files + # see https://github.com/electron-userland/electron-builder/issues/5592 + run: | + ls -la . + ls -la ./latest-mac-x64 + ls -la ./latest-mac-arm64 + ls -la ./electron + cp ./electron/merge-latest-ymls.js /tmp/merge-latest-ymls.js + npm install js-yaml --prefix /tmp + node /tmp/merge-latest-ymls.js ./latest-mac-x64/latest-mac.yml ./latest-mac-arm64/latest-mac.yml ./latest-mac.yml + cat ./latest-mac.yml + + - name: Yet Another Upload Release Asset Action + uses: shogo82148/actions-upload-release-asset@v1.7.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.create-draft-release.outputs.upload_url }} + asset_path: ./latest-mac.yml + asset_name: latest-mac.yml + asset_content_type: text/yaml + overwrite: true + update_release_draft: - needs: [build-macos, build-windows-x64, build-linux-x64] + needs: [build-macos-x64, build-macos-arm64, build-windows-x64, build-linux-x64, combine-latest-mac-yml] permissions: # write permission is required to create a github release contents: write diff --git a/.github/workflows/template-build-macos-arm64.yml b/.github/workflows/template-build-macos-arm64.yml new file mode 100644 index 000000000..54355d55c --- /dev/null +++ b/.github/workflows/template-build-macos-arm64.yml @@ -0,0 +1,160 @@ +name: build-macos +on: + workflow_call: + inputs: + ref: + required: true + type: string + default: 'refs/heads/main' + public_provider: + required: true + type: string + default: none + description: 'none: build only, github: build and publish to github, cloudflare: build and publish to cloudflare' + new_version: + required: true + type: string + default: '' + cloudflare_r2_path: + required: false + type: string + default: '/latest/' + secrets: + CLOUDFLARE_R2_BUCKET_NAME: + required: false + CLOUDFLARE_R2_ACCESS_KEY_ID: + required: false + CLOUDFLARE_R2_SECRET_ACCESS_KEY: + required: false + CLOUDFLARE_ACCOUNT_ID: + required: false + CODE_SIGN_P12_BASE64: + required: false + CODE_SIGN_P12_PASSWORD: + required: false + APPLE_ID: + required: false + APPLE_APP_SPECIFIC_PASSWORD: + required: false + DEVELOPER_ID: + required: false + +jobs: + build-macos: + runs-on: macos-silicon + environment: production + permissions: + contents: write + steps: + - name: Getting the repo + uses: actions/checkout@v3 + with: + ref: ${{ inputs.ref }} + + - name: Installing node + uses: actions/setup-node@v1 + with: + node-version: 20 + - name: Unblock keychain + run: | + security unlock-keychain -p ${{ secrets.KEYCHAIN_PASSWORD }} ~/Library/Keychains/login.keychain-db + # - uses: actions/setup-python@v5 + # with: + # python-version: '3.11' + + # - name: Install jq + # uses: dcarbone/install-jq-action@v2.0.1 + + - name: Update app version based on latest release tag with build number + if: inputs.public_provider != 'github' + run: | + echo "Version: ${{ inputs.new_version }}" + # Update the version in electron/package.json + jq --arg version "${{ inputs.new_version }}" '.version = $version' electron/package.json > /tmp/package.json + mv /tmp/package.json electron/package.json + + jq --arg version "${{ inputs.new_version }}" '.version = $version' web/package.json > /tmp/package.json + mv /tmp/package.json web/package.json + + jq '.build.publish = [{"provider": "generic", "url": "${{ secrets.CLOUDFLARE_R2_PUBLIC_URL }}", "channel": "latest"}, {"provider": "s3", "bucket": "${{ secrets.CLOUDFLARE_R2_BUCKET_NAME }}", "region": "auto", "endpoint": "https://${{ secrets.CLOUDFLARE_ACCOUNT_ID }}.r2.cloudflarestorage.com", "path": "${{ inputs.cloudflare_r2_path }}", "channel": "latest"}]' electron/package.json > /tmp/package.json + mv /tmp/package.json electron/package.json + cat electron/package.json + + - name: Update app version base on tag + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && inputs.public_provider == 'github' + 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 + jq --arg version "${VERSION_TAG#v}" '.version = $version' web/package.json > /tmp/package.json + mv /tmp/package.json web/package.json + env: + VERSION_TAG: ${{ inputs.new_version }} + + # - 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 }} + + # - uses: apple-actions/import-codesign-certs@v2 + # continue-on-error: true + # with: + # p12-file-base64: ${{ secrets.CODE_SIGN_P12_BASE64 }} + # p12-password: ${{ secrets.CODE_SIGN_P12_PASSWORD }} + + - name: Build and publish app to cloudflare r2 or github artifactory + if: inputs.public_provider != 'github' + run: | + # check public_provider is true or not + echo "public_provider is ${{ inputs.public_provider }}" + if [ "${{ inputs.public_provider }}" == "none" ]; then + make build + else + make build-and-publish + fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # CSC_LINK: "/tmp/codesign.p12" + # CSC_KEY_PASSWORD: ${{ secrets.CODE_SIGN_P12_PASSWORD }} + # 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 }} + AWS_ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: auto + AWS_EC2_METADATA_DISABLED: "true" + + - name: Build and publish app to github + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && inputs.public_provider == 'github' + run: | + make build-and-publish + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # CSC_LINK: "/tmp/codesign.p12" + # CSC_KEY_PASSWORD: ${{ secrets.CODE_SIGN_P12_PASSWORD }} + # 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 }} + ANALYTICS_ID: ${{ secrets.JAN_APP_UMAMI_PROJECT_API_KEY }} + ANALYTICS_HOST: ${{ secrets.JAN_APP_UMAMI_URL }} + + - name: Upload Artifact + if: inputs.public_provider != 'github' + uses: actions/upload-artifact@v2 + with: + name: jan-mac-arm64-${{ inputs.new_version }} + path: ./electron/dist/jan-mac-arm64-${{ inputs.new_version }}.dmg + + - name: Upload Artifact + uses: actions/upload-artifact@v2 + with: + name: latest-mac-arm64 + path: ./electron/dist/latest-mac.yml \ No newline at end of file diff --git a/.github/workflows/template-build-macos.yml b/.github/workflows/template-build-macos-x64.yml similarity index 97% rename from .github/workflows/template-build-macos.yml rename to .github/workflows/template-build-macos-x64.yml index 0ad1d3a6a..e313c2947 100644 --- a/.github/workflows/template-build-macos.yml +++ b/.github/workflows/template-build-macos-x64.yml @@ -148,9 +148,8 @@ jobs: path: ./electron/dist/jan-mac-x64-${{ inputs.new_version }}.dmg - name: Upload Artifact - if: inputs.public_provider != 'github' uses: actions/upload-artifact@v2 with: - name: jan-mac-arm64-${{ inputs.new_version }} - path: ./electron/dist/jan-mac-arm64-${{ inputs.new_version }}.dmg + name: latest-mac-x64 + path: ./electron/dist/latest-mac.yml diff --git a/electron/merge-latest-ymls.js b/electron/merge-latest-ymls.js new file mode 100644 index 000000000..8172a3176 --- /dev/null +++ b/electron/merge-latest-ymls.js @@ -0,0 +1,27 @@ +const yaml = require('js-yaml') +const fs = require('fs') + +// get two file paths from arguments: +const [, , ...args] = process.argv +const file1 = args[0] +const file2 = args[1] +const file3 = args[2] + +// check that all arguments are present and throw error instead +if (!file1 || !file2 || !file3) { + throw new Error('Please provide 3 file paths as arguments: path to file1, to file2 and destination path') +} + +const doc1 = yaml.load(fs.readFileSync(file1, 'utf8')) +console.log('doc1: ', doc1) + +const doc2 = yaml.load(fs.readFileSync(file2, 'utf8')) +console.log('doc2: ', doc2) + +const merged = { ...doc1, ...doc2 } +merged.files.push(...doc1.files) + +console.log('merged', merged) + +const mergedYml = yaml.dump(merged) +fs.writeFileSync(file3, mergedYml, 'utf8') diff --git a/electron/package.json b/electron/package.json index 2892fedc6..08f15b262 100644 --- a/electron/package.json +++ b/electron/package.json @@ -63,11 +63,11 @@ "build:test:darwin": "tsc -p . && electron-builder -p never -m --dir", "build:test:win32": "tsc -p . && electron-builder -p never -w --dir", "build:test:linux": "tsc -p . && electron-builder -p never -l --dir", - "build:darwin": "tsc -p . && electron-builder -p never -m --x64 --arm64", + "build:darwin": "tsc -p . && electron-builder -p never -m", "build:win32": "tsc -p . && electron-builder -p never -w", "build:linux": "tsc -p . && electron-builder -p never -l deb -l AppImage", "build:publish": "run-script-os", - "build:publish:darwin": "tsc -p . && electron-builder -p always -m --x64 --arm64", + "build:publish:darwin": "tsc -p . && electron-builder -p always -m", "build:publish:win32": "tsc -p . && electron-builder -p always -w", "build:publish:linux": "tsc -p . && electron-builder -p always -l deb -l AppImage" },