refactor: 优化 transcode #64
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 and Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - beta | |
| - dev | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| env: | |
| # 提前启用 Node.js 24,消除 action 依赖 Node 20 的弃用警告 | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| VIDEOMERGE_FFMPEG_DARWIN_SHA256: ${{ vars.VIDEOMERGE_FFMPEG_DARWIN_SHA256 }} | |
| VIDEOMERGE_FFPROBE_DARWIN_SHA256: ${{ vars.VIDEOMERGE_FFPROBE_DARWIN_SHA256 }} | |
| VIDEOMERGE_FFMPEG_WINDOWS_SHA256: ${{ vars.VIDEOMERGE_FFMPEG_WINDOWS_SHA256 }} | |
| VIDEOMERGE_FFMPEG_LINUX_SHA256: ${{ vars.VIDEOMERGE_FFMPEG_LINUX_SHA256 }} | |
| jobs: | |
| # 新增:前置任务,用于动态生成矩阵 | |
| setup-matrix: | |
| name: Setup Build Matrix | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - name: Determine Matrix based on Branch | |
| id: set-matrix | |
| run: | | |
| # 默认:全平台打包 (适用于 main, tags, workflow_dispatch) | |
| MATRIX_JSON='[{"os":"windows-latest","label":"windows-x64","artifact_name":"VideoMergingTool-windows-x64","package_path":"dist/installer/VideoMergingTool-Setup.exe"},{"os":"macos-15-intel","label":"macos-intel","artifact_name":"VideoMergingTool-macos-intel","package_path":"dist/VideoMergingTool-macos-intel.dmg"},{"os":"macos-14","label":"macos-apple-silicon","artifact_name":"VideoMergingTool-macos-apple-silicon","package_path":"dist/VideoMergingTool-macos-apple-silicon.dmg"},{"os":"ubuntu-latest","label":"linux-x64","artifact_name":"VideoMergingTool-linux-x64","package_path":"dist/VideoMergingTool"}]' | |
| if [[ "${{ github.ref }}" == "refs/heads/beta" ]]; then | |
| # beta 分支:仅 Windows 和 macOS apple 芯片 | |
| MATRIX_JSON='[{"os":"windows-latest","label":"windows-x64","artifact_name":"VideoMergingTool-windows-x64","package_path":"dist/installer/VideoMergingTool-Setup.exe"},{"os":"macos-14","label":"macos-apple-silicon","artifact_name":"VideoMergingTool-macos-apple-silicon","package_path":"dist/VideoMergingTool-macos-apple-silicon.dmg"}]' | |
| elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then | |
| # dev 分支:仅 Windows | |
| MATRIX_JSON='[{"os":"windows-latest","label":"windows-x64","artifact_name":"VideoMergingTool-windows-x64","package_path":"dist/installer/VideoMergingTool-Setup.exe"}]' | |
| fi | |
| echo "matrix={\"include\":$MATRIX_JSON}" >> $GITHUB_OUTPUT | |
| build: | |
| name: Build ${{ matrix.label }} | |
| needs: setup-matrix # 依赖 setup-matrix 任务 | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| # 核心修改:读取前置任务输出的 JSON 动态生成矩阵 | |
| matrix: ${{ fromJSON(needs.setup-matrix.outputs.matrix) }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| # 快速清理磁盘空间(macOS 专用) | |
| - name: Free up disk space (macOS) | |
| if: runner.os == 'macOS' | |
| run: | | |
| echo "--- Disk space before cleanup ---" | |
| df -h | |
| # 仅删除 Android 和 .NET,速度极快,可腾出约 10GB+ 空间 | |
| sudo rm -rf /Users/runner/Library/Android || true | |
| sudo rm -rf /usr/local/share/dotnet || true | |
| # 快速清理 Homebrew 缓存 | |
| brew cleanup || true | |
| echo "--- Disk space after cleanup ---" | |
| df -h | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| cache: "pip" | |
| - name: Install build dependencies | |
| run: python -m pip install -r requirements-build.txt | |
| - name: Install Inno Setup on Windows | |
| if: runner.os == 'Windows' | |
| run: choco install innosetup --no-progress -y | |
| - name: Build executable on Windows | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| env: | |
| WINDOWS_CERTIFICATE_BASE64: ${{ secrets.WINDOWS_CERTIFICATE_BASE64 }} | |
| WINDOWS_CERTIFICATE_PASSWORD: ${{ secrets.WINDOWS_CERTIFICATE_PASSWORD }} | |
| run: .\scripts\build_windows.ps1 | |
| - name: Build app on macOS | |
| if: runner.os == 'macOS' | |
| run: | | |
| # 清理旧的构建残留 | |
| rm -rf dist build | |
| # 执行构建 | |
| bash scripts/build_local.sh | |
| # 确保目录存在并移动打包好的文件 | |
| mkdir -p dist | |
| mv dist/VideoMergingTool.dmg "${{ matrix.package_path }}" | |
| # 清理临时 build 目录,降低 artifact 收集负担 | |
| rm -rf build | |
| - name: Build executable on Linux | |
| if: runner.os == 'Linux' | |
| run: bash scripts/build_local.sh | |
| - name: Upload build artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.artifact_name }} | |
| path: ${{ matrix.package_path }} | |
| if-no-files-found: error | |
| release: | |
| name: Publish GitHub Release | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| needs: build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: release-assets | |
| merge-multiple: true | |
| - name: Upload release assets | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: release-assets/**/* | |
| generate_release_notes: true |