mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-04-27 15:29:49 +08:00
161 lines
4.3 KiB
YAML
161 lines
4.3 KiB
YAML
name: Build and Release
|
||
|
||
on:
|
||
# 手动触发
|
||
workflow_dispatch:
|
||
inputs:
|
||
version:
|
||
description: '版本号 (如 0.1.0)'
|
||
required: true
|
||
type: string
|
||
# 推送 tag 时自动触发
|
||
push:
|
||
tags:
|
||
- 'v*'
|
||
|
||
jobs:
|
||
build-mac:
|
||
runs-on: macos-latest
|
||
steps:
|
||
- name: Checkout code
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Setup Node.js
|
||
uses: actions/setup-node@v4
|
||
with:
|
||
node-version: '20'
|
||
|
||
- name: Setup pnpm
|
||
uses: pnpm/action-setup@v4
|
||
with:
|
||
version: 9
|
||
|
||
- name: Get pnpm store directory
|
||
shell: bash
|
||
run: |
|
||
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
||
|
||
- name: Setup pnpm cache
|
||
uses: actions/cache@v4
|
||
with:
|
||
path: ${{ env.STORE_PATH }}
|
||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||
restore-keys: |
|
||
${{ runner.os }}-pnpm-store-
|
||
|
||
- name: Install dependencies
|
||
run: pnpm install
|
||
|
||
# macOS 签名和公证需要的 API Key 文件
|
||
- name: Create Apple API Key File
|
||
run: |
|
||
mkdir -p ~/private_keys
|
||
echo "${{ secrets.APPLE_API_KEY }}" > ~/private_keys/AuthKey_${{ secrets.APPLE_API_KEY_ID }}.p8
|
||
|
||
- name: Build Electron app for macOS
|
||
env:
|
||
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
||
# 代码签名
|
||
CSC_LINK: ${{ secrets.CSC_LINK }}
|
||
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
|
||
# 公证
|
||
APPLE_API_KEY: ~/private_keys/AuthKey_${{ secrets.APPLE_API_KEY_ID }}.p8
|
||
APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
|
||
APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
|
||
run: pnpm build:mac
|
||
|
||
- name: Upload macOS artifacts
|
||
uses: actions/upload-artifact@v4
|
||
with:
|
||
name: ChatLab-mac
|
||
path: |
|
||
dist/*.dmg
|
||
dist/*.zip
|
||
dist/*.yml
|
||
dist/*.json
|
||
dist/*.blockmap
|
||
if-no-files-found: warn
|
||
retention-days: 1 # 只保留1天,Release后会上传到GitHub Releases
|
||
|
||
build-win:
|
||
runs-on: windows-latest
|
||
steps:
|
||
- name: Checkout code
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Setup Node.js
|
||
uses: actions/setup-node@v4
|
||
with:
|
||
node-version: '20'
|
||
|
||
- name: Setup pnpm
|
||
uses: pnpm/action-setup@v4
|
||
with:
|
||
version: 9
|
||
|
||
- name: Get pnpm store directory
|
||
shell: bash
|
||
run: |
|
||
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
||
|
||
- name: Setup pnpm cache
|
||
uses: actions/cache@v4
|
||
with:
|
||
path: ${{ env.STORE_PATH }}
|
||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||
restore-keys: |
|
||
${{ runner.os }}-pnpm-store-
|
||
|
||
- name: Install dependencies
|
||
run: pnpm install
|
||
|
||
- name: Build Electron app for Windows
|
||
env:
|
||
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
||
run: pnpm build:win
|
||
|
||
- name: Upload Windows artifacts
|
||
uses: actions/upload-artifact@v4
|
||
with:
|
||
name: ChatLab-win
|
||
path: |
|
||
dist/*.exe
|
||
dist/*.yml
|
||
dist/*.json
|
||
dist/*.blockmap
|
||
if-no-files-found: warn
|
||
retention-days: 1 # 只保留1天,Release后会上传到GitHub Releases
|
||
|
||
release:
|
||
needs: [build-mac, build-win]
|
||
runs-on: ubuntu-latest
|
||
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
|
||
|
||
steps:
|
||
- name: Download macOS artifacts
|
||
uses: actions/download-artifact@v4
|
||
with:
|
||
name: ChatLab-mac
|
||
path: dist
|
||
|
||
- name: Download Windows artifacts
|
||
uses: actions/download-artifact@v4
|
||
with:
|
||
name: ChatLab-win
|
||
path: dist
|
||
|
||
- name: List files
|
||
run: ls -la dist/
|
||
|
||
- name: Create Release
|
||
uses: softprops/action-gh-release@v2
|
||
with:
|
||
tag_name: ${{ github.event_name == 'workflow_dispatch' && format('v{0}', inputs.version) || github.ref_name }}
|
||
name: ChatLab ${{ github.event_name == 'workflow_dispatch' && inputs.version || github.ref_name }}
|
||
files: |
|
||
dist/*.exe
|
||
dist/*.dmg
|
||
dist/*.zip
|
||
env:
|
||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|