update #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Executables | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| build: | |
| name: Build on ${{ matrix.item.os }} | |
| runs-on: ${{ matrix.item.os }} | |
| strategy: | |
| matrix: | |
| item: | |
| # macOS - ARM (Apple Silicon) | |
| - os: macos-14 | |
| arch: arm64 | |
| platform: darwin | |
| pyinstaller_arch: arm64 | |
| package_lock_path: .github/workflows/package-lock.json | |
| use_static_python: false | |
| # macOS - x86 (Intel) | |
| - os: macos-13 | |
| arch: x86_64 | |
| platform: darwin | |
| pyinstaller_arch: x86_64 | |
| package_lock_path: .github/workflows/package-lock.json | |
| use_static_python: false | |
| # 将 node-version 移到每个 item 中 | |
| include: | |
| - node-version: 18.x | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Copy package-lock.json | |
| run: | | |
| echo "Copying ${{ matrix.item.package_lock_path }} to package-lock.json" | |
| cp "${{ matrix.item.package_lock_path }}" package-lock.json | |
| echo "File copied successfully" | |
| shell: bash | |
| # 设置静态 Python 环境(仅适用于 Ubuntu) | |
| - name: Set up static Python (Ubuntu only) | |
| if: ${{ matrix.item.use_static_python }} | |
| run: | | |
| # 下载预编译的静态Python | |
| PYTHON_VERSION=3.10.17 | |
| BUILD_TAG=20250529 | |
| wget https://github.com/astral-sh/python-build-standalone/releases/download/${BUILD_TAG}/cpython-${PYTHON_VERSION}+${BUILD_TAG}-x86_64-unknown-linux-gnu-install_only.tar.gz | |
| # 解压到 /opt/python-static | |
| sudo mkdir -p /opt/python-static | |
| sudo tar -xzf cpython-${PYTHON_VERSION}+${BUILD_TAG}-x86_64-unknown-linux-gnu-install_only.tar.gz -C /opt/python-static --strip-components=1 | |
| # 设置环境变量 | |
| echo "/opt/python-static/bin" >> $GITHUB_PATH | |
| echo "PYTHON_STATIC=/opt/python-static" >> $GITHUB_ENV | |
| # 验证安装 | |
| /opt/python-static/bin/python3 --version | |
| /opt/python-static/bin/python3 -c "import sys; print(sys.executable)" | |
| export PATH=/opt/python-static/bin/:$PATH | |
| python3 --version | |
| # 设置标准 Python 环境(非 Ubuntu 平台) | |
| - name: Set up Python | |
| if: ${{ !matrix.item.use_static_python }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: | | |
| npm install --no-package-lock | |
| - name: PyInstaller build | |
| run: | | |
| npm run release | |
| # 仅 macOS:创建安装包 | |
| - name: Create macOS Installer Package | |
| if: ${{ startsWith(matrix.item.os, 'macos') }} | |
| run: | | |
| # 创建必要的目录结构 | |
| mkdir -p pkg_root/Applications | |
| mkdir -p pkg_scripts | |
| # 查找并移动应用程序 | |
| APP_PATH=perf_testing/dist/ArkAnalyzer-HapRay | |
| if [ -z "$APP_PATH" ]; then | |
| echo "Error: No ArkAnalyzer-HapRay bundle found in dist directory" | |
| exit 1 | |
| fi | |
| APP_NAME=ArkAnalyzer-HapRay | |
| # 复制应用到安装目录 | |
| cp -R "$APP_PATH" pkg_root/Applications/ | |
| # 创建组件属性列表 (plist) | |
| cat > component.plist <<EOF | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| <plist version="1.0"> | |
| <array> | |
| <dict> | |
| <key>BundleHasStrictIdentifier</key> | |
| <true/> | |
| <key>BundleIsRelocatable</key> | |
| <false/> | |
| <key>BundleIsVersionChecked</key> | |
| <true/> | |
| <key>BundleOverwriteAction</key> | |
| <string>upgrade</string> | |
| <key>BundleType</key> | |
| <string>Application</string> | |
| <key>ChildBundles</key> | |
| <array/> | |
| </dict> | |
| </array> | |
| </plist> | |
| EOF | |
| # 构建组件包 | |
| pkgbuild \ | |
| --root "pkg_root" \ | |
| --component-plist component.plist \ | |
| --scripts "pkg_scripts" \ | |
| --identifier "com.huawei.${APP_NAME}" \ | |
| --version "1.0.0" \ | |
| --install-location "/" \ | |
| "component.pkg" | |
| # 创建分发文件 | |
| cat <<'EOF' > distribution.xml | |
| <?xml version="1.0" encoding="utf-8"?> | |
| <installer-gui-script minSpecVersion="2"> | |
| <title>ArkAnalyzer HapRay</title> | |
| <background file="background.svg" alignment="bottomleft" scaling="none"/> | |
| <welcome file="welcome.html"/> | |
| <license file="license.rtf"/> | |
| <options customize="never" rootVolumeOnly="true"/> | |
| <domains enable_anywhere="false" enable_currentUserHome="false" enable_localSystem="true"/> | |
| <pkg-ref id="com.huawei.${APP_NAME}"/> | |
| <choices-outline> | |
| <line choice="default"> | |
| <line choice="${APP_NAME}"/> | |
| </line> | |
| </choices-outline> | |
| <choice id="default"/> | |
| <choice id="${APP_NAME}" visible="false"> | |
| <pkg-ref id="com.huawei.${APP_NAME}"/> | |
| </choice> | |
| <pkg-ref id="com.huawei.${APP_NAME}" version="1.0.0" onConclusion="none">component.pkg</pkg-ref> | |
| </installer-gui-script> | |
| EOF | |
| # 创建最终安装包 | |
| productbuild \ | |
| --distribution distribution.xml \ | |
| --resources . \ | |
| --package-path . \ | |
| "ArkAnalyzer-HapRay-${{ matrix.item.platform }}-${{ matrix.item.arch }}.pkg" | |
| shell: bash | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ArkAnalyzer-HapRay-${{ matrix.item.platform }}-${{ matrix.item.arch }} | |
| path: | | |
| ArkAnalyzer-HapRay-*.zip | |
| ArkAnalyzer-HapRay-*.pkg |