ci(workflow): 增强CI/CD流程并修复文件扩展名问题 #8
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: C/C++ 持续集成 | |
| on: | |
| push: | |
| branches: [ "main", "master" ] | |
| tags: [ "v*", "release-*" ] | |
| pull_request: | |
| branches: [ "main", "master" ] | |
| release: | |
| types: [created, published] | |
| workflow_dispatch: | |
| inputs: | |
| version_override: | |
| description: '版本号覆盖(可选)' | |
| required: false | |
| type: string | |
| jobs: | |
| build-and-test-linux: | |
| name: 构建和测试 (Linux) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 调试信息 | |
| run: | | |
| echo "=== 构建任务调试信息 ===" | |
| echo "事件类型: ${{ github.event_name }}" | |
| echo "引用: ${{ github.ref }}" | |
| echo "标签名: ${{ github.ref_name }}" | |
| echo "是否标签推送: ${{ startsWith(github.ref, 'refs/tags/') }}" | |
| - name: 检出代码仓库 | |
| uses: actions/checkout@v4 | |
| - name: 安装依赖项 | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y g++ cmake make sqlite3 libsqlite3-dev pkg-config | |
| - name: 使用Make构建 | |
| run: make | |
| - name: 验证构建结果 | |
| run: | | |
| echo "=== 验证构建结果 ===" | |
| if [ ! -f "phone_forensic" ]; then | |
| echo "❌ 可执行文件未找到" | |
| ls -la | |
| exit 1 | |
| fi | |
| echo "✅ 可执行文件已成功生成" | |
| file phone_forensic | |
| du -h phone_forensic | |
| timeout 5s ./phone_forensic --help 2>&1 | head -20 || \ | |
| timeout 5s ./phone_forensic --version 2>&1 | head -5 || \ | |
| echo "程序运行测试完成" | |
| - name: 清理构建文件 | |
| run: make clean | |
| build-and-test-windows: | |
| name: 构建和测试 (Windows) | |
| runs-on: windows-latest | |
| steps: | |
| - name: 检出代码仓库 | |
| uses: actions/checkout@v4 | |
| - name: 设置MSYS2和MinGW环境 | |
| uses: msys2/setup-msys2@v2 | |
| with: | |
| update: true | |
| install: >- | |
| mingw-w64-x86_64-gcc | |
| mingw-w64-x86_64-sqlite3 | |
| mingw-w64-x86_64-pkg-config | |
| - name: 编译Windows可执行文件 | |
| shell: msys2 {0} | |
| run: | | |
| export PKG_CONFIG_PATH="/mingw64/lib/pkgconfig" | |
| x86_64-w64-mingw32-g++ -std=c++17 -Wall -O3 -static \ | |
| main.cc model/model.cc view/view.cc controller/controller.cc \ | |
| -o phone_forensic.exe -lsqlite3 -lws2_32 -lole32 -lshell32 | |
| if [ ! -f "phone_forensic.exe" ]; then | |
| echo "❌ 编译失败" | |
| exit 1 | |
| fi | |
| echo "✅ Windows可执行文件编译完成" | |
| - name: 验证Windows可执行文件 | |
| shell: msys2 {0} | |
| run: | | |
| timeout 5s ./phone_forensic.exe --help 2>&1 | head -5 || true | |
| build-and-test-macos: | |
| name: 构建和测试 (macOS) | |
| runs-on: macos-latest | |
| steps: | |
| - name: 检出代码仓库 | |
| uses: actions/checkout@v4 | |
| - name: 安装依赖项 | |
| run: | | |
| brew install sqlite3 | |
| echo "/usr/local/bin" >> $GITHUB_PATH | |
| echo "/opt/homebrew/bin" >> $GITHUB_PATH | |
| - name: 设置C++17编译器标志 | |
| run: | | |
| echo "CXX=g++" >> $GITHUB_ENV | |
| echo "CXXFLAGS=-std=c++17 -Wall -O3" >> $GITHUB_ENV | |
| - name: 使用Make构建 | |
| run: | | |
| export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/opt/homebrew/lib/pkgconfig" | |
| make | |
| - name: 验证构建结果 | |
| run: | | |
| echo "=== 验证构建结果 ===" | |
| if [ ! -f "phone_forensic" ]; then | |
| echo "❌ 可执行文件未找到" | |
| ls -la | |
| exit 1 | |
| fi | |
| echo "✅ macOS可执行文件已成功生成" | |
| file phone_forensic | |
| du -h phone_forensic | |
| timeout 5s ./phone_forensic --help 2>&1 | head -20 || \ | |
| timeout 5s ./phone_forensic --version 2>&1 | head -5 || \ | |
| echo "程序运行测试完成" | |
| linux-release: | |
| name: Linux发行版打包 | |
| runs-on: ubuntu-latest | |
| needs: [build-and-test-linux] | |
| if: > | |
| (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) || | |
| (github.event_name == 'release') || | |
| (github.event_name == 'workflow_dispatch') | |
| steps: | |
| - name: 检出代码仓库 | |
| uses: actions/checkout@v4 | |
| - name: 获取版本号 | |
| id: get-version | |
| shell: bash | |
| run: | | |
| case "${{ github.event_name }}" in | |
| "release") | |
| VERSION="${{ github.event.release.tag_name }}" | |
| ;; | |
| "workflow_dispatch") | |
| if [ -n "${{ github.event.inputs.version_override }}" ]; then | |
| VERSION="${{ github.event.inputs.version_override }}" | |
| else | |
| VERSION="manual-${{ github.run_number }}-$(date +%Y%m%d)" | |
| fi | |
| ;; | |
| "push") | |
| VERSION="${GITHUB_REF#refs/tags/}" | |
| ;; | |
| *) | |
| VERSION="unknown-$(date +%Y%m%d-%H%M%S)" | |
| ;; | |
| esac | |
| CLEAN_VERSION=$(echo "$VERSION" | sed 's/^v//' | sed 's/^release-//' | tr -cd 'a-zA-Z0-9._-') | |
| echo "原始版本: $VERSION" | |
| echo "清理后版本: $CLEAN_VERSION" | |
| echo "VERSION=$CLEAN_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "VERSION=$CLEAN_VERSION" >> "$GITHUB_ENV" | |
| - name: 安装打包工具 | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y dpkg-dev | |
| - name: 构建发布版本 | |
| run: | | |
| make clean | |
| CXXFLAGS="-std=c++17 -Wall -O3 -DNDEBUG" make | |
| strip phone_forensic || echo "strip skipped" | |
| - name: 创建DEB软件包 | |
| run: | | |
| mkdir -p package/usr/local/bin package/DEBIAN | |
| cp phone_forensic package/usr/local/bin/ | |
| cat > package/DEBIAN/control <<EOF | |
| Package: lqz-forensic | |
| Version: ${{ env.VERSION }} | |
| Section: utils | |
| Priority: optional | |
| Architecture: amd64 | |
| Maintainer: 钟智强 <johnmelodymel@qq.com> | |
| Description: Android Device Forensic Tool | |
| 灵取证是一款功能强大且专业的安卓设备数据取证工具,专门为执法部门、司法机构和安全调查人员设计开发。 | |
| 支持提取通话记录、短信、照片、视频等数据,严格遵循相关法律法规。 | |
| EOF | |
| cat > package/DEBIAN/postinst <<EOF | |
| #!/bin/sh | |
| set -e | |
| echo "灵取证 ${{ env.VERSION }} 安装完成" | |
| echo "运行命令: phone_forensic" | |
| EOF | |
| chmod 755 package/DEBIAN/postinst | |
| dpkg-deb --build package lqz-forensic_${{ env.VERSION }}_amd64.deb | |
| - name: 创建通用压缩包 | |
| run: | | |
| DIR_NAME="lqz-${{ env.VERSION }}-linux-amd64" | |
| mkdir -p "${DIR_NAME}" | |
| cp phone_forensic README.md LICENSE "${DIR_NAME}/" | |
| cat > "${DIR_NAME}/README-zh.txt" <<EOF | |
| 灵取证 ${{ env.VERSION }} - Linux版本 | |
| 简介: | |
| 灵取证是一款功能强大且专业的安卓设备数据取证工具... | |
| 运行方法: | |
| 1. 确保已安装ADB工具: sudo apt-get install adb | |
| 2. 在终端中运行: ./phone_forensic | |
| 系统要求: | |
| - Ubuntu 18.04 或更高版本 | |
| - 已安装ADB工具 | |
| - 已开启USB调试的Android设备 | |
| 技术支持: | |
| - 开发者:钟智强 <johnmelodymel@qq.com> | |
| - GitHub: https://github.com/ctkqiang/LQZ | |
| - QQ交流群: 934810107 | |
| 免责声明: | |
| 本工具仅供执法部门在法律框架内使用,任何非法使用或滥用概不负责。 | |
| EOF | |
| cat > "${DIR_NAME}/install.sh" <<EOF | |
| #!/bin/bash | |
| echo "正在安装灵取证 ${{ env.VERSION }} ..." | |
| sudo cp phone_forensic /usr/local/bin/ | |
| sudo chmod +x /usr/local/bin/phone_forensic | |
| echo "安装完成!运行命令: phone_forensic" | |
| EOF | |
| chmod +x "${DIR_NAME}/install.sh" | |
| tar czf "${DIR_NAME}.tar.gz" "${DIR_NAME}/" | |
| - name: 上传到GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: | | |
| lqz-forensic_*.deb | |
| lqz-*-linux-amd64.tar.gz | |
| tag_name: ${{ github.event_name == 'release' && github.event.release.tag_name || github.ref_name || env.VERSION }} | |
| name: 灵取证 ${{ env.VERSION }} | |
| body: | | |
| ## 灵取证 ${{ env.VERSION }} | |
| ### Linux版本发布 | |
| **包含文件:** | |
| 1. `lqz-forensic_${{ env.VERSION }}_amd64.deb` | |
| 2. `lqz-${{ env.VERSION }}-linux-amd64.tar.gz` | |
| ### 使用说明 | |
| ```bash | |
| # DEB安装 | |
| sudo dpkg -i lqz-forensic_${{ env.VERSION }}_amd64.deb | |
| # 通用包 | |
| tar -xzf lqz-${{ env.VERSION }}-linux-amd64.tar.gz | |
| ./lqz-${{ env.VERSION }}-linux-amd64/phone_forensic | |
| ``` | |
| --- | |
| 自动生成于: ${{ github.event.repository.pushed_at || github.event.release.published_at }} | |
| draft: false | |
| prerelease: ${{ contains(env.VERSION, 'beta') || contains(env.VERSION, 'alpha') || contains(env.VERSION, 'rc') }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| windows-release: | |
| name: Windows版本打包 | |
| runs-on: windows-latest | |
| needs: [build-and-test-windows] | |
| if: > | |
| (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) || | |
| (github.event_name == 'release') || | |
| (github.event_name == 'workflow_dispatch') | |
| steps: | |
| - name: 检出代码仓库 | |
| uses: actions/checkout@v4 | |
| - name: 获取版本号 | |
| id: get-version | |
| shell: bash | |
| run: | | |
| case "${{ github.event_name }}" in | |
| "release") | |
| VERSION="${{ github.event.release.tag_name }}" | |
| ;; | |
| "workflow_dispatch") | |
| if [ -n "${{ github.event.inputs.version_override }}" ]; then | |
| VERSION="${{ github.event.inputs.version_override }}" | |
| else | |
| VERSION="manual-${{ github.run_number }}-$(date +%Y%m%d)" | |
| fi | |
| ;; | |
| "push") | |
| VERSION="${GITHUB_REF#refs/tags/}" | |
| ;; | |
| *) | |
| VERSION="unknown-$(date +%Y%m%d-%H%M%S)" | |
| ;; | |
| esac | |
| CLEAN_VERSION=$(echo "$VERSION" | sed 's/^v//' | sed 's/^release-//' | tr -cd 'a-zA-Z0-9._-') | |
| echo "VERSION=$CLEAN_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "VERSION=$CLEAN_VERSION" >> "$GITHUB_ENV" | |
| - name: 设置MSYS2和MinGW环境 | |
| uses: msys2/setup-msys2@v2 | |
| with: | |
| update: true | |
| install: >- | |
| mingw-w64-x86_64-gcc | |
| mingw-w64-x86_64-sqlite3 | |
| mingw-w64-x86_64-pkg-config | |
| - name: 编译Windows可执行文件 | |
| shell: msys2 {0} | |
| run: | | |
| export PKG_CONFIG_PATH="/mingw64/lib/pkgconfig" | |
| x86_64-w64-mingw32-g++ -std=c++17 -Wall -O3 -static \ | |
| main.cc model/model.cc view/view.cc controller/controller.cc \ | |
| -o phone_forensic.exe -lsqlite3 -lws2_32 -lole32 -lshell32 | |
| if [ ! -f "phone_forensic.exe" ]; then | |
| echo "❌ 编译失败" | |
| exit 1 | |
| fi | |
| - name: 创建Windows安装包 | |
| shell: powershell | |
| run: | | |
| $Version = "${{ env.VERSION }}" | |
| $FolderName = "lqz-$Version-windows-amd64" | |
| New-Item -ItemType Directory -Force -Path $FolderName | Out-Null | |
| Copy-Item "phone_forensic.exe", "README.md", "LICENSE" -Destination $FolderName | |
| @" | |
| @echo off | |
| chcp 65001 >nul | |
| echo. | |
| echo ╔══════════════════════════════════════════════╗ | |
| echo ║ 灵取证 - 安卓取证工具 ║ | |
| echo ║ 版本: $Version ║ | |
| echo ╚══════════════════════════════════════════════╝ | |
| echo. | |
| echo 按任意键开始运行程序... | |
| pause >nul | |
| start phone_forensic.exe | |
| "@ | Out-File -FilePath "$FolderName\运行灵取证.bat" -Encoding ASCII | |
| Compress-Archive -Path "$FolderName\*" -DestinationPath "$FolderName.zip" | |
| - name: 上传Windows版本到GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: lqz-*-windows-amd64.zip | |
| tag_name: ${{ github.event_name == 'release' && github.event.release.tag_name || github.ref_name || env.VERSION }} | |
| name: 灵取证 ${{ env.VERSION }} (Windows版本) | |
| body: | | |
| ## 灵取证 ${{ env.VERSION }} - Windows版本 | |
| - `lqz-${{ env.VERSION }}-windows-amd64.zip` | |
| ### 使用说明 | |
| 1. 解压 ZIP 文件 | |
| 2. 双击 `运行灵取证.bat` | |
| --- | |
| 自动生成于: ${{ github.event.repository.pushed_at || github.event.release.published_at }} | |
| draft: false | |
| prerelease: ${{ contains(env.VERSION, 'beta') || contains(env.VERSION, 'alpha') || contains(env.VERSION, 'rc') }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |