.github/workflows/build-desktop.yml #6
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 Desktop | |
| # 由 prepare-release.yml 手动触发,或 push tag 时触发 | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Version to build" | |
| required: true | |
| type: string | |
| tag: | |
| description: "Git tag" | |
| required: true | |
| type: string | |
| release_id: | |
| description: "GitHub release database ID" | |
| required: true | |
| type: string | |
| channel: | |
| description: "Release channel" | |
| required: true | |
| default: "dev" | |
| type: string | |
| push: | |
| tags: | |
| - "v*" | |
| permissions: | |
| contents: write | |
| # 矩阵策略: | |
| # - 每个目标平台一个 job | |
| # - 现在只启用 windows-latest(开源测试版) | |
| # - 未来扩展 macOS/Linux 时,取消注释对应项并添加签名 secrets | |
| jobs: | |
| build: | |
| name: Build desktop (${{ matrix.platform.name }}) | |
| runs-on: ${{ matrix.platform.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| platform: | |
| - name: windows | |
| os: windows-latest | |
| package_script: package:win | |
| artifact_pattern: "dist/opennovel-desktop-win-*.exe" | |
| updater_pattern: "dist/latest.yml" | |
| # TODO: 未来启用 macOS | |
| # - name: macos | |
| # os: macos-latest | |
| # package_script: package:mac | |
| # artifact_pattern: "dist/opennovel-desktop-mac-*.dmg" | |
| # updater_pattern: "dist/latest-mac.yml" | |
| # TODO: 未来启用 Linux | |
| # - name: linux | |
| # os: ubuntu-latest | |
| # package_script: package:linux | |
| # artifact_pattern: "dist/opennovel-desktop-linux-*.AppImage" | |
| # updater_pattern: "dist/latest-linux.yml" | |
| defaults: | |
| run: | |
| shell: bash | |
| env: | |
| # 让 electron-builder 知道当前 channel,图标复制脚本会用到 | |
| OPENNOVEL_CHANNEL: ${{ inputs.channel || 'dev' }} | |
| # 无签名模式(开源测试版) | |
| # 未来购买证书后,通过 GitHub Secrets 注入 WIN_CSC_LINK 等 | |
| WIN_CSC_LINK: "" | |
| WIN_CSC_KEY_PASSWORD: "" | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| # 如果是 tag 触发,checkout 到对应 tag | |
| ref: ${{ inputs.tag || github.ref }} | |
| - name: Setup Bun | |
| uses: ./.github/actions/setup-bun | |
| # 如果是 workflow_dispatch 触发但没有 inputs(例如从 prepare-release 触发), | |
| # 下载 release-info artifact 获取参数 | |
| - name: Download release info artifact | |
| if: inputs.version == '' | |
| uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 | |
| with: | |
| name: release-info | |
| path: .release-info | |
| - name: Read release info | |
| id: info | |
| run: | | |
| if [ -f .release-info/info.json ]; then | |
| echo "version=$(jq -r '.version' .release-info/info.json)" >> "$GITHUB_OUTPUT" | |
| echo "tag=$(jq -r '.tag' .release-info/info.json)" >> "$GITHUB_OUTPUT" | |
| echo "release_id=$(jq -r '.release_id' .release-info/info.json)" >> "$GITHUB_OUTPUT" | |
| echo "channel=$(jq -r '.channel' .release-info/info.json)" >> "$GITHUB_OUTPUT" | |
| else | |
| # push tag 触发时从 tag 解析 | |
| TAG="${{ github.ref_name }}" | |
| VERSION="${TAG#v}" | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
| echo "release_id=" >> "$GITHUB_OUTPUT" | |
| echo "channel=dev" >> "$GITHUB_OUTPUT" | |
| fi | |
| # Windows 需要额外安装 Python 依赖以便 node-gyp 编译原生模块 | |
| - name: Setup Python (Windows) | |
| if: runner.os == 'Windows' | |
| uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 | |
| with: | |
| python-version: "3.12" | |
| - name: Build and package | |
| working-directory: packages/desktop | |
| env: | |
| OPENNOVEL_CHANNEL: ${{ steps.info.outputs.channel || inputs.channel || 'dev' }} | |
| run: | | |
| bun run build | |
| bun run ${{ matrix.platform.package_script }} | |
| - name: List dist contents | |
| working-directory: packages/desktop | |
| run: ls -la dist/ | |
| # 上传产物到对应 GitHub release | |
| - name: Upload artifacts to release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| RELEASE_ID: ${{ steps.info.outputs.release_id || inputs.release_id || '' }} | |
| TAG: ${{ steps.info.outputs.tag || inputs.tag || github.ref_name }} | |
| working-directory: packages/desktop | |
| run: | | |
| shopt -s nullglob | |
| files=( ${{ matrix.platform.artifact_pattern }} ${{ matrix.platform.updater_pattern }} ) | |
| if [ ${#files[@]} -eq 0 ]; then | |
| echo "No artifacts found" | |
| exit 1 | |
| fi | |
| for f in "${files[@]}"; do | |
| echo "Uploading $f to release $TAG" | |
| gh release upload "$TAG" "$f" --clobber --repo ${{ github.repository }} | |
| done | |
| # 把 release info 继续传递下去,供 publish-release 使用 | |
| - name: Re-upload release info artifact | |
| if: steps.info.outputs.release_id != '' | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | |
| with: | |
| name: release-info-${{ matrix.platform.name }} | |
| path: .release-info/info.json | |
| retention-days: 7 | |
| if-no-files-found: ignore |