From b51fa5e2b7a5ac079d1ba72eae62fb6d1a45fc96 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Thu, 21 Aug 2025 15:28:40 +0800 Subject: [PATCH] :bug: GitHub action cli packaging issue fixed --- .github/workflows/pake-cli.yaml | 11 ++--------- bin/builders/BaseBuilder.ts | 11 +++++++++-- bin/builders/MacBuilder.ts | 33 ++++++++++++++++++++++++++++++--- bin/helpers/tauriConfig.ts | 16 +++++++++++----- script/build_with_pake_cli.js | 19 +++++++++++++++++++ 5 files changed, 71 insertions(+), 19 deletions(-) diff --git a/.github/workflows/pake-cli.yaml b/.github/workflows/pake-cli.yaml index f18e437..413fdad 100644 --- a/.github/workflows/pake-cli.yaml +++ b/.github/workflows/pake-cli.yaml @@ -113,18 +113,11 @@ jobs: restore-keys: | ${{ runner.os }}-node- - - name: Cache pake-cli installation - uses: actions/cache@v4 - id: pake_cache - with: - path: node_modules/pake-cli - key: ${{ runner.os }}-pake-cli-${{ hashFiles('**/package.json') }}-${{ inputs.multi_arch }} - - name: Install pake-cli shell: bash run: | - echo "Installing pake-cli..." - npm install pake-cli --no-package-lock + echo "Installing latest pake-cli..." + npm install pake-cli@latest --no-package-lock # Verify installation if [ ! -d "node_modules/pake-cli" ]; then diff --git a/bin/builders/BaseBuilder.ts b/bin/builders/BaseBuilder.ts index ef5f974..7d76e97 100644 --- a/bin/builders/BaseBuilder.ts +++ b/bin/builders/BaseBuilder.ts @@ -169,18 +169,25 @@ export default abstract class BaseBuilder { fullCommand += ' --bundles app'; } + // Add features + const features = ['cli-build']; + // Add macos-proxy feature for modern macOS (Darwin 23+ = macOS 14+) if (IS_MAC) { const macOSVersion = this.getMacOSMajorVersion(); if (macOSVersion >= 23) { - fullCommand += ' --features macos-proxy'; + features.push('macos-proxy'); } } + + if (features.length > 0) { + fullCommand += ` --features ${features.join(',')}`; + } return fullCommand; } - private getMacOSMajorVersion(): number { + protected getMacOSMajorVersion(): number { try { const os = require('os'); const release = os.release(); diff --git a/bin/builders/MacBuilder.ts b/bin/builders/MacBuilder.ts index 52f1b5e..4bd06cf 100644 --- a/bin/builders/MacBuilder.ts +++ b/bin/builders/MacBuilder.ts @@ -1,3 +1,4 @@ +import path from 'path'; import tauriConfig from '@/helpers/tauriConfig'; import { PakeAppOptions } from '@/types'; import BaseBuilder from './BaseBuilder'; @@ -33,9 +34,35 @@ export default class MacBuilder extends BaseBuilder { } protected getBuildCommand(): string { - return this.options.multiArch - ? 'npm run build:mac' - : super.getBuildCommand(); + if (this.options.multiArch) { + const baseCommand = this.options.debug + ? 'npm run tauri build -- --debug' + : 'npm run tauri build --'; + + // Use temporary config directory to avoid modifying source files + const configPath = path.join( + 'src-tauri', + '.pake', + 'tauri.conf.json', + ); + let fullCommand = `${baseCommand} --target universal-apple-darwin -c "${configPath}"`; + + // Add features + const features = ['cli-build']; + + // Add macos-proxy feature for modern macOS (Darwin 23+ = macOS 14+) + const macOSVersion = this.getMacOSMajorVersion(); + if (macOSVersion >= 23) { + features.push('macos-proxy'); + } + + if (features.length > 0) { + fullCommand += ` --features ${features.join(',')}`; + } + + return fullCommand; + } + return super.getBuildCommand(); } protected getBasePath(): string { diff --git a/bin/helpers/tauriConfig.ts b/bin/helpers/tauriConfig.ts index c16888e..5a6b41b 100644 --- a/bin/helpers/tauriConfig.ts +++ b/bin/helpers/tauriConfig.ts @@ -1,8 +1,14 @@ -import pakeConf from '../../src-tauri/pake.json'; -import CommonConf from '../../src-tauri/tauri.conf.json'; -import WinConf from '../../src-tauri/tauri.windows.conf.json'; -import MacConf from '../../src-tauri/tauri.macos.conf.json'; -import LinuxConf from '../../src-tauri/tauri.linux.conf.json'; +import path from 'path'; +import fsExtra from 'fs-extra'; +import { npmDirectory } from '@/utils/dir'; + +// Load configs from npm package directory, not from project source +const tauriSrcDir = path.join(npmDirectory, 'src-tauri'); +const pakeConf = fsExtra.readJSONSync(path.join(tauriSrcDir, 'pake.json')); +const CommonConf = fsExtra.readJSONSync(path.join(tauriSrcDir, 'tauri.conf.json')); +const WinConf = fsExtra.readJSONSync(path.join(tauriSrcDir, 'tauri.windows.conf.json')); +const MacConf = fsExtra.readJSONSync(path.join(tauriSrcDir, 'tauri.macos.conf.json')); +const LinuxConf = fsExtra.readJSONSync(path.join(tauriSrcDir, 'tauri.linux.conf.json')); const platformConfigs = { win32: WinConf, diff --git a/script/build_with_pake_cli.js b/script/build_with_pake_cli.js index f08c6f1..3bf964a 100644 --- a/script/build_with_pake_cli.js +++ b/script/build_with_pake_cli.js @@ -47,6 +47,25 @@ const main = async () => { console.log("Cleaned previous .pake directory for fresh build"); } + // Also clean any potential target directories that might contain cached configs + const targetDirs = [ + "src-tauri/target", + "src-tauri/target/debug", + "src-tauri/target/release", + "src-tauri/target/universal-apple-darwin" + ]; + + targetDirs.forEach(dir => { + if (fs.existsSync(dir)) { + // Only remove .pake subdirectories, not the entire target directory + const targetPakeDir = path.join(dir, ".pake"); + if (fs.existsSync(targetPakeDir)) { + fs.rmSync(targetPakeDir, { recursive: true, force: true }); + console.log(`Cleaned .pake directory in ${dir}`); + } + } + }); + // Build CLI parameters let params = [ "dist/cli.js",