mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-07-08 16:43:59 +08:00
### What this PR does Before this PR: The `release.yml` workflow triggers on `pull_request_target` with `opened` and `synchronize` event types. Every commit pushed to a release PR (e.g. editing release notes in `electron-builder.yml`) re-triggers the full 3-platform release build (macOS + Windows + Linux), wasting significant CI resources. After this PR: The workflow only triggers when the release PR is **merged** into `main`, not on every push. This is achieved by: 1. Changing `pull_request_target` types from `opened`/`synchronize` to `closed` 2. Adding `github.event.pull_request.merged == true` to the job condition Fixes # ### Why we need it and why it was done in this way The following tradeoffs were made: - Release builds no longer run during PR review phase. If a pre-merge test build is needed, `workflow_dispatch` can be used manually. The following alternatives were considered: - **Remove `synchronize` only (keep `opened`)**: Would still trigger on PR creation but not subsequent pushes. However, this loses automation on merge. - **Path filtering**: `pull_request_target` doesn't support `paths` filter, would require a separate job to check changed files — more complex for the same result. - **Label-based triggering**: Adds manual steps, defeats automation purpose. ### Breaking changes None. The `tag push` and `workflow_dispatch` triggers remain unchanged. The only behavioral change is that release builds now happen on merge instead of on PR open/push. ### Special notes for your reviewer - The `workflow_dispatch` trigger still allows manual release builds at any time - The `push: tags: v*.*.*` trigger is unaffected - The removed `head.repo.full_name == github.repository` check is redundant since `merged == true` already implies the PR was accepted ### Checklist - [x] PR: The PR description is expressive enough and will help future contributors - [x] Code: [Write code that humans can understand](https://en.wikiquote.org/wiki/Martin_Fowler#code-for-humans) and [Keep it simple](https://en.wikipedia.org/wiki/KISS_principle) - [x] Refactor: You have [left the code cleaner than you found it (Boy Scout Rule)](https://learning.oreilly.com/library/view/97-things-every/9780596809515/ch08.html) - [x] Upgrade: Impact of this change on upgrade flows was considered and addressed if required - [ ] Documentation: A [user-guide update](https://docs.cherry-ai.com) was considered and is present (link) or not required. Check this only when the PR introduces or changes a user-facing feature or behavior. - [x] Self-review: I have reviewed my own code (e.g., via [`/gh-pr-review`](/.claude/skills/gh-pr-review/SKILL.md), `gh pr diff`, or GitHub UI) before requesting review from others ### Release note ```release-note NONE ``` --------- Signed-off-by: suyao <sy20010504@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
165 lines
5.9 KiB
YAML
165 lines
5.9 KiB
YAML
name: Release
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
tag:
|
|
description: "Release tag (e.g. v1.0.0)"
|
|
required: true
|
|
default: "v1.0.0"
|
|
platform:
|
|
description: "Build platform"
|
|
required: true
|
|
default: "all"
|
|
type: choice
|
|
options:
|
|
- all
|
|
- windows
|
|
- mac
|
|
- linux
|
|
push:
|
|
tags:
|
|
- v*.*.*
|
|
pull_request_target:
|
|
branches:
|
|
- main
|
|
types:
|
|
- closed
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
release:
|
|
# Only run for tag push, workflow_dispatch, or PR from release branches
|
|
if: |
|
|
github.event_name == 'push' ||
|
|
github.event_name == 'workflow_dispatch' ||
|
|
(github.event_name == 'pull_request_target' && github.event.pull_request.merged == true && github.event.pull_request.head.repo.full_name == github.repository && startsWith(github.event.pull_request.head.ref, 'release/v'))
|
|
runs-on: ${{ matrix.os }}
|
|
|
|
strategy:
|
|
matrix:
|
|
os: ${{ fromJSON(
|
|
github.event_name == 'push' && '["macos-latest", "windows-latest", "ubuntu-latest"]' ||
|
|
github.event_name == 'pull_request_target' && '["macos-latest", "windows-latest", "ubuntu-latest"]' ||
|
|
github.event.inputs.platform == 'all' && '["macos-latest", "windows-latest", "ubuntu-latest"]' ||
|
|
github.event.inputs.platform == 'linux' && '["ubuntu-latest"]' ||
|
|
github.event.inputs.platform == 'windows' && '["windows-latest"]' ||
|
|
github.event.inputs.platform == 'mac' && '["macos-latest"]' ||
|
|
'["macos-latest", "windows-latest", "ubuntu-latest"]'
|
|
) }}
|
|
fail-fast: false
|
|
|
|
steps:
|
|
- name: Check out Git repository
|
|
uses: actions/checkout@v6
|
|
with:
|
|
fetch-depth: 0
|
|
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || '' }}
|
|
|
|
- name: Get release tag
|
|
id: get-tag
|
|
shell: bash
|
|
run: |
|
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
|
echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
|
|
elif [ "${{ github.event_name }}" = "pull_request_target" ]; then
|
|
# Extract version from branch name (release/v1.0.0 -> v1.0.0)
|
|
BRANCH="${{ github.event.pull_request.head.ref }}"
|
|
echo "tag=${BRANCH#release/}" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Set package.json version
|
|
shell: bash
|
|
run: |
|
|
TAG="${{ steps.get-tag.outputs.tag }}"
|
|
VERSION="${TAG#v}"
|
|
npm version "$VERSION" --no-git-tag-version --allow-same-version
|
|
|
|
- name: Install Node.js
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version-file: '.node-version'
|
|
|
|
- name: macos-latest dependencies fix
|
|
if: matrix.os == 'macos-latest'
|
|
run: |
|
|
brew install python-setuptools
|
|
|
|
- name: Install pnpm
|
|
uses: pnpm/action-setup@v4
|
|
|
|
- name: Get pnpm store directory
|
|
id: pnpm-cache
|
|
shell: bash
|
|
run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Cache pnpm dependencies
|
|
uses: actions/cache@v5
|
|
with:
|
|
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
|
|
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pnpm-
|
|
|
|
- name: Install Dependencies
|
|
run: pnpm install
|
|
|
|
- name: Build Linux
|
|
if: matrix.os == 'ubuntu-latest'
|
|
run: |
|
|
sudo apt-get install -y rpm
|
|
pnpm build:linux
|
|
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
NODE_OPTIONS: --max-old-space-size=8192
|
|
MAIN_VITE_CHERRYAI_CLIENT_SECRET: ${{ secrets.MAIN_VITE_CHERRYAI_CLIENT_SECRET }}
|
|
MAIN_VITE_MINERU_API_KEY: ${{ secrets.MAIN_VITE_MINERU_API_KEY }}
|
|
RENDERER_VITE_AIHUBMIX_SECRET: ${{ secrets.RENDERER_VITE_AIHUBMIX_SECRET }}
|
|
RENDERER_VITE_PPIO_APP_SECRET: ${{ secrets.RENDERER_VITE_PPIO_APP_SECRET }}
|
|
|
|
- name: Build Mac
|
|
if: matrix.os == 'macos-latest'
|
|
run: |
|
|
sudo -H pip install setuptools
|
|
pnpm build:mac
|
|
env:
|
|
CSC_FOR_PULL_REQUEST: true
|
|
CSC_LINK: ${{ secrets.CSC_LINK }}
|
|
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
|
|
APPLE_ID: ${{ secrets.APPLE_ID }}
|
|
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
|
|
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
NODE_OPTIONS: --max-old-space-size=8192
|
|
MAIN_VITE_CHERRYAI_CLIENT_SECRET: ${{ secrets.MAIN_VITE_CHERRYAI_CLIENT_SECRET }}
|
|
MAIN_VITE_MINERU_API_KEY: ${{ secrets.MAIN_VITE_MINERU_API_KEY }}
|
|
RENDERER_VITE_AIHUBMIX_SECRET: ${{ secrets.RENDERER_VITE_AIHUBMIX_SECRET }}
|
|
RENDERER_VITE_PPIO_APP_SECRET: ${{ secrets.RENDERER_VITE_PPIO_APP_SECRET }}
|
|
|
|
- name: Build Windows
|
|
if: matrix.os == 'windows-latest'
|
|
run: |
|
|
pnpm build:win
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
NODE_OPTIONS: --max-old-space-size=8192
|
|
MAIN_VITE_CHERRYAI_CLIENT_SECRET: ${{ secrets.MAIN_VITE_CHERRYAI_CLIENT_SECRET }}
|
|
MAIN_VITE_MINERU_API_KEY: ${{ secrets.MAIN_VITE_MINERU_API_KEY }}
|
|
RENDERER_VITE_AIHUBMIX_SECRET: ${{ secrets.RENDERER_VITE_AIHUBMIX_SECRET }}
|
|
RENDERER_VITE_PPIO_APP_SECRET: ${{ secrets.RENDERER_VITE_PPIO_APP_SECRET }}
|
|
|
|
- name: Release
|
|
uses: ncipollo/release-action@v1
|
|
with:
|
|
draft: true
|
|
allowUpdates: true
|
|
makeLatest: false
|
|
tag: ${{ steps.get-tag.outputs.tag }}
|
|
artifacts: "dist/*.exe,dist/*.zip,dist/*.dmg,dist/*.AppImage,dist/*.snap,dist/*.deb,dist/*.rpm,dist/*.tar.gz,dist/latest*.yml,dist/rc*.yml,dist/beta*.yml,dist/*.blockmap"
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|