Repository navigation
0.3.4 #24
Workflow file for this run
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 & Release | |
| on: | |
| # 在 GitHub 上发布 Release 时自动触发构建 | |
| release: | |
| types: [published] | |
| # 手动触发 (用于调试或重新构建) | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: '版本号 (如 1.2.3,不带 v 前缀)' | |
| required: true | |
| type: string | |
| # 同一时间只允许一个构建流水线运行 | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write | |
| actions: read | |
| jobs: | |
| # ── 准备阶段:提取版本号与发布内容 ── | |
| prepare: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.meta.outputs.version }} | |
| release_body: ${{ steps.meta.outputs.release_body }} | |
| tag_name: ${{ steps.meta.outputs.tag_name }} | |
| is_prerelease: ${{ steps.meta.outputs.is_prerelease }} | |
| release_id: ${{ steps.meta.outputs.release_id }} | |
| steps: | |
| - name: Checkout (gh cli needs repo context) | |
| uses: actions/checkout@v4 | |
| - name: Extract release metadata | |
| id: meta | |
| env: | |
| EVENT_NAME: ${{ github.event_name }} | |
| RELEASE_TAG: ${{ github.event.release.tag_name }} | |
| RELEASE_BODY: ${{ github.event.release.body }} | |
| RELEASE_PRERELEASE: ${{ github.event.release.prerelease }} | |
| RELEASE_ID: ${{ github.event.release.id }} | |
| INPUT_VERSION: ${{ github.event.inputs.version }} | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| if [ "$EVENT_NAME" = "release" ]; then | |
| # 从 Release 事件中获取版本号 (去掉 v 前缀) | |
| VERSION="${RELEASE_TAG#v}" | |
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | |
| echo "tag_name=${RELEASE_TAG}" >> "$GITHUB_OUTPUT" | |
| echo "is_prerelease=${RELEASE_PRERELEASE}" >> "$GITHUB_OUTPUT" | |
| echo "release_id=${RELEASE_ID}" >> "$GITHUB_OUTPUT" | |
| # 获取 Release body 内容 (base64 编码避免多行问题) | |
| BODY=$(printf '%s' "$RELEASE_BODY" | base64 -w 0) | |
| echo "release_body=${BODY}" >> "$GITHUB_OUTPUT" | |
| else | |
| # workflow_dispatch 手动触发:通过 tag 查找已有 Release,找不到则创建 | |
| TAG="v${INPUT_VERSION}" | |
| echo "version=${INPUT_VERSION}" >> "$GITHUB_OUTPUT" | |
| echo "tag_name=${TAG}" >> "$GITHUB_OUTPUT" | |
| echo "is_prerelease=false" >> "$GITHUB_OUTPUT" | |
| echo "release_body=$(printf '%s' '手动触发构建' | base64 -w 0)" >> "$GITHUB_OUTPUT" | |
| # 尝试查找已有 Release | |
| if gh release view "$TAG" > /dev/null 2>&1; then | |
| echo "✅ Found existing Release: ${TAG}" | |
| else | |
| # 创建 draft Release | |
| gh release create "$TAG" --title "Release ${TAG}" --notes "手动触发构建" --draft | |
| echo "✅ Created draft Release: ${TAG}" | |
| fi | |
| fi | |
| - name: Print build info | |
| run: | | |
| echo "📦 Version: ${{ steps.meta.outputs.version }}" | |
| echo "🏷️ Tag: ${{ steps.meta.outputs.tag_name }}" | |
| echo "🚀 Pre-release: ${{ steps.meta.outputs.is_prerelease }}" | |
| # ── 多平台构建 ── | |
| build: | |
| needs: prepare | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: windows-latest | |
| platform: win | |
| - os: ubuntu-latest | |
| platform: linux | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.prepare.outputs.tag_name }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| # Linux 需要构建原生模块的依赖 | |
| - name: Install Linux build dependencies | |
| if: matrix.platform == 'linux' | |
| run: sudo apt-get update && sudo apt-get install -y build-essential | |
| - name: Install dependencies | |
| run: npm ci | |
| # 将 Release 版本号同步写入 package.json | |
| - name: Sync version to package.json | |
| run: npm version ${{ needs.prepare.outputs.version }} --no-git-tag-version --allow-same-version | |
| - name: Build (electron-vite) | |
| run: npx electron-vite build | |
| - name: Package (${{ matrix.platform }}) | |
| run: npx electron-builder --${{ matrix.platform }} --publish never | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # Windows 代码签名 (可选) | |
| WIN_CSC_LINK: ${{ secrets.WIN_CSC_LINK || '' }} | |
| WIN_CSC_KEY_PASSWORD: ${{ secrets.WIN_CSC_KEY_PASSWORD || '' }} | |
| # ── 上传构建产物 ── | |
| - name: Upload Windows artifacts | |
| if: matrix.platform == 'win' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: open-cowork-windows | |
| path: | | |
| dist/*.exe | |
| dist/*.exe.blockmap | |
| dist/latest*.yml | |
| if-no-files-found: error | |
| retention-days: 30 | |
| - name: Upload Linux artifacts | |
| if: matrix.platform == 'linux' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: open-cowork-linux | |
| path: | | |
| dist/*.AppImage | |
| dist/*.AppImage.zsync | |
| dist/*.deb | |
| dist/latest*.yml | |
| if-no-files-found: error | |
| retention-days: 30 | |
| # ── 上传产物到 Release ── | |
| upload: | |
| needs: [prepare, build] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout (gh cli needs repo context) | |
| uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| merge-multiple: true | |
| - name: List artifacts | |
| run: ls -lhR artifacts/ | |
| # 使用 gh cli 精确上传到触发的 Release | |
| - name: Upload assets to Release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TAG_NAME: ${{ needs.prepare.outputs.tag_name }} | |
| run: | | |
| echo "📦 Uploading assets to Release: ${TAG_NAME}" | |
| for file in artifacts/*; do | |
| [ -f "$file" ] || continue | |
| echo " ⬆️ $(basename "$file")" | |
| gh release upload "${TAG_NAME}" "$file" --clobber | |
| done | |
| echo "✅ All assets uploaded successfully" |