构建可执行文件 #69
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: 构建可执行文件 | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| name: 构建于 ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| env: | |
| PYTHONUTF8: "1" | |
| UV_DEFAULT_INDEX: https://pypi.org/simple | |
| SIGNPATH_AVAILABLE: ${{ secrets.SIGNPATH_API_TOKEN != '' }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: windows-latest | |
| sign: true | |
| executable: dist/XHS-Downloader/XHS-Downloader.exe | |
| artifact: XHS-Downloader_Windows_X64 | |
| - os: windows-11-arm | |
| sign: true | |
| executable: dist/XHS-Downloader/XHS-Downloader.exe | |
| artifact: XHS-Downloader_Windows_ARM64 | |
| - os: macos-15-intel | |
| sign: false | |
| executable: dist/XHS-Downloader/XHS-Downloader | |
| artifact: XHS-Downloader_macOS_X64 | |
| - os: macos-latest | |
| sign: false | |
| executable: dist/XHS-Downloader/XHS-Downloader | |
| artifact: XHS-Downloader_macOS_ARM64 | |
| steps: | |
| - name: 签出存储库 | |
| uses: actions/checkout@v7 | |
| - name: 设置 uv | |
| uses: astral-sh/setup-uv@v9.0.0 | |
| with: | |
| enable-cache: true | |
| - name: 安装依赖项 | |
| run: | | |
| uv python install 3.12 | |
| uv sync --frozen --no-dev --no-install-project --python 3.12 | |
| uv pip install cx_Freeze | |
| - name: 获取构建日期 | |
| run: >- | |
| uv run python -c | |
| "from datetime import datetime; from os import environ; open(environ['GITHUB_ENV'], 'a', encoding='utf-8').write(f'DATE={datetime.now():%Y%m%d}\n')" | |
| - name: 构建可执行文件 | |
| run: uv run python setup.py build_exe --build-exe dist/XHS-Downloader | |
| - name: 验证可执行文件 | |
| run: >- | |
| uv run python -c | |
| "import subprocess; subprocess.run([r'${{ matrix.executable }}', '--version'], check=True)" | |
| - name: 上传待签名构建产物 | |
| if: matrix.sign && env.SIGNPATH_AVAILABLE == 'true' | |
| id: upload-artifact | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: ${{ matrix.artifact }}_${{ env.DATE }} | |
| path: dist/XHS-Downloader | |
| if-no-files-found: error | |
| - name: SignPath 签名 | |
| if: matrix.sign && env.SIGNPATH_AVAILABLE == 'true' | |
| uses: signpath/github-action-submit-signing-request@v2 | |
| with: | |
| api-token: ${{ secrets.SIGNPATH_API_TOKEN }} | |
| organization-id: bddfd48a-44b7-4ab4-a51c-cd6e84db7534 | |
| project-slug: XHS-Downloader | |
| signing-policy-slug: test-signing | |
| github-artifact-id: ${{ steps.upload-artifact.outputs.artifact-id }} | |
| wait-for-completion: true | |
| output-artifact-directory: signed | |
| - name: 上传签名版本 | |
| if: matrix.sign && env.SIGNPATH_AVAILABLE == 'true' | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: ${{ matrix.artifact }}_${{ env.DATE }} | |
| path: signed | |
| overwrite: true | |
| if-no-files-found: error | |
| - name: 上传未签名 Windows 版本 | |
| if: matrix.sign && env.SIGNPATH_AVAILABLE != 'true' | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: ${{ matrix.artifact }}_${{ env.DATE }} | |
| path: dist/XHS-Downloader | |
| if-no-files-found: error | |
| - name: 上传 macOS 构建产物 | |
| if: ${{ !matrix.sign }} | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: ${{ matrix.artifact }}_${{ env.DATE }} | |
| path: dist/XHS-Downloader | |
| if-no-files-found: error |