Files
2026-07-27 22:36:34 +08:00

160 lines
4.9 KiB
YAML

name: Build
on:
push:
tags:
- 'v*' # 仅在推送 v 开头的 tag 时触发打包
jobs:
# tag 推送时官方不评估 paths,用门禁 job 对比上一 v* tag
changes:
runs-on: ubuntu-latest
outputs:
desktop: ${{ steps.check.outputs.desktop }}
steps:
- name: 准备代码
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 检查 desktop-client 是否有变更
id: check
run: |
CURRENT="${{ github.ref_name }}"
PREV=$(git tag -l 'v*' --sort=-v:refname | grep -vxF "$CURRENT" | head -n1 || true)
if [ -z "$PREV" ]; then
echo "No previous v* tag; will build."
echo "desktop=true" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Comparing $PREV..$GITHUB_SHA for desktop-client/"
if git diff --quiet "$PREV" "$GITHUB_SHA" -- desktop-client/; then
echo "No changes in desktop-client/; skip build."
echo "desktop=false" >> "$GITHUB_OUTPUT"
else
echo "desktop-client/ changed; will build."
echo "desktop=true" >> "$GITHUB_OUTPUT"
fi
build:
needs: changes
if: needs.changes.outputs.desktop == 'true'
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
# 固定 runner 大版本,避免 -latest 自动迁移导致构建环境突变
- os: windows-2022
platform: win
artifact_name: windows-build
build_command: build-win
installer_command: build-win-installer
green_command: build-win-green
- os: macos-14
platform: mac
artifact_name: macos-build
build_command: build-mac
installer_command: build-mac-installer
green_command: build-mac-green
- os: macos-15-intel
platform: mac-x64
artifact_name: macos-build-x64
build_command: build-mac-x64
installer_command: build-mac-x64-installer
green_command: build-mac-x64-green
steps:
- name: 准备代码
uses: actions/checkout@v4
- name: 设置Node.js环境
uses: actions/setup-node@v4
with:
node-version: '22.14.0'
cache: 'npm'
cache-dependency-path: desktop-client/package-lock.json
- name: 打印构建环境信息
run: |
echo "Runner OS: ${{ runner.os }}"
echo "Runner image: ${{ matrix.os }}"
node -v
npm -v
shell: bash
- name: 安装Electron依赖
run: npm ci
working-directory: ./desktop-client
- name: 安装前端依赖
run: npm ci
working-directory: ./desktop-client/web
- name: 构建前端
run: npm run build
working-directory: ./desktop-client/web
- name: 更新版本号
run: node scripts/update-version.js
working-directory: ./desktop-client
env:
GITHUB_REF: ${{ github.ref }}
- name: 根据平台打包应用程序
run: npm run ${{ matrix.build_command }}
working-directory: ./desktop-client
- name: 根据平台创建安装包
run: npm run ${{ matrix.installer_command }}
working-directory: ./desktop-client
env:
# 添加环境变量以解决macOS构建问题
CSC_IDENTITY_AUTO_DISCOVERY: false
DEBUG: electron-builder
- name: 构建绿色安装包
if: matrix.green_command != 'null'
run: npm run ${{ matrix.green_command }}
working-directory: ./desktop-client
env:
# 添加环境变量以解决macOS构建问题
CSC_IDENTITY_AUTO_DISCOVERY: false
DEBUG: electron-builder
- name: 列出dist目录内容
run: |
echo "当前操作系统: ${{ runner.os }}"
ls desktop-client/dist/
shell: bash
- name: 上传安装包构件
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}-installer
path: desktop-client/dist/
if-no-files-found: ignore
- name: 上传绿色安装包构件
if: matrix.green_command != 'null'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}-green
path: desktop-client/dist/*.zip
if-no-files-found: ignore
- name: 发布版本
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
files: |
desktop-client/dist/capcut-mate-windows-x64-installer.exe
desktop-client/dist/capcut-mate-macos-arm64-installer.dmg
desktop-client/dist/capcut-mate-macos-x64-installer.dmg
desktop-client/dist/*.zip
overwrite: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}