209 lines
7.5 KiB
YAML
209 lines
7.5 KiB
YAML
name: HyperChat electron app
|
|
|
|
on:
|
|
workflow_dispatch: {}
|
|
workflow_call:
|
|
inputs:
|
|
publish_tag:
|
|
description: 'NPM publish tag (alpha/latest)'
|
|
required: true
|
|
type: string
|
|
branch_name:
|
|
description: 'Branch name that triggered the npm publish'
|
|
required: true
|
|
type: string
|
|
secrets:
|
|
APPLE_ID:
|
|
description: 'Apple ID for notarization'
|
|
required: true
|
|
APPLE_APP_SPECIFIC_PASSWORD:
|
|
description: 'Apple app-specific password'
|
|
required: true
|
|
CSC_LINK:
|
|
description: 'Code signing certificate'
|
|
required: true
|
|
CSC_KEY_PASSWORD:
|
|
description: 'Code signing certificate password'
|
|
required: true
|
|
APPLE_TEAM_ID:
|
|
description: 'Apple Team ID'
|
|
required: true
|
|
GH_TOKEN:
|
|
description: 'GitHub token for releases'
|
|
required: true
|
|
TELEGRAM_CHAT_ID:
|
|
description: 'Telegram chat ID for notifications'
|
|
required: true
|
|
TELEGRAM_BOT_TOKEN:
|
|
description: 'Telegram bot token'
|
|
required: true
|
|
|
|
|
|
permissions:
|
|
contents: write
|
|
discussions: write
|
|
|
|
jobs:
|
|
release:
|
|
name: electron app
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
|
|
runs-on: ${{ matrix.os }}
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0 # 获取完整的 git 历史
|
|
|
|
- name: Get event details
|
|
id: details
|
|
shell: bash
|
|
run: |
|
|
if [ "${{ github.event_name }}" = "push" ]; then
|
|
echo "type=推送" >> $GITHUB_OUTPUT
|
|
echo "message=$(git log -1 --pretty=format:%s)" >> $GITHUB_OUTPUT
|
|
echo "author=$(git log -1 --pretty=format:%an)" >> $GITHUB_OUTPUT
|
|
echo "sha=$(git log -1 --pretty=format:%h)" >> $GITHUB_OUTPUT
|
|
echo "url=${{ github.event.head_commit.url }}" >> $GITHUB_OUTPUT
|
|
elif [ "${{ github.event_name }}" = "pull_request" ]; then
|
|
echo "type=拉取请求" >> $GITHUB_OUTPUT
|
|
echo "message=${{ github.event.pull_request.title }}" >> $GITHUB_OUTPUT
|
|
echo "author=${{ github.event.pull_request.user.login }}" >> $GITHUB_OUTPUT
|
|
echo "url=${{ github.event.pull_request.html_url }}" >> $GITHUB_OUTPUT
|
|
elif [ "${{ github.event_name }}" = "issues" ]; then
|
|
echo "type=议题${{ github.event.action }}" >> $GITHUB_OUTPUT
|
|
echo "message=${{ github.event.issue.title }}" >> $GITHUB_OUTPUT
|
|
echo "author=${{ github.event.issue.user.login }}" >> $GITHUB_OUTPUT
|
|
echo "url=${{ github.event.issue.html_url }}" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Get changed files
|
|
id: files
|
|
if: github.event_name == 'push' || github.event_name == 'pull_request'
|
|
shell: bash
|
|
run: |
|
|
if [ "${{ github.event_name }}" = "push" ]; then
|
|
echo "changed=$(git diff --name-only HEAD^1 HEAD | tr '\n' ', ')" >> $GITHUB_OUTPUT
|
|
elif [ "${{ github.event_name }}" = "pull_request" ]; then
|
|
echo "changed=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | tr '\n' ', ')" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Setup Node.js and Dependencies
|
|
uses: ./.github/actions/setup-node-deps
|
|
with:
|
|
node-version: '20.19.1'
|
|
install-python-setuptools: 'true'
|
|
|
|
|
|
# 构建Sync Version脚本
|
|
- name: Build Sync Version Script
|
|
run: npm run version:sync
|
|
|
|
# 构建共享库
|
|
- name: Build shared package
|
|
run: cd packages/shared && npm run build
|
|
|
|
# 构建核心包
|
|
- name: Build core package
|
|
run: cd packages/core && npm run build
|
|
|
|
# 构建Web包
|
|
- name: Build web package
|
|
run: cd packages/web && npm run build
|
|
|
|
# 缓存构建产物
|
|
- name: Cache build outputs
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: |
|
|
packages/shared/dist
|
|
packages/core/dist
|
|
packages/web/build
|
|
key: ${{ matrix.os }}-build-${{ github.sha }}
|
|
restore-keys: |
|
|
${{ matrix.os }}-build-
|
|
|
|
# 根据分支设置发布类型
|
|
- name: Set release type for stable
|
|
if: github.ref == 'refs/heads/stable' || (github.event_name == 'workflow_call' && inputs.branch_name == 'stable')
|
|
run: |
|
|
cd packages/electron
|
|
sed -i 's/"releaseType": "prerelease"/"releaseType": "release"/' package.json
|
|
|
|
# 发布应用
|
|
- name: Publish App (macOS)
|
|
if: |
|
|
(
|
|
(github.ref == 'refs/heads/dev2' || github.ref == 'refs/heads/stable') ||
|
|
(github.event_name == 'workflow_call' && (inputs.branch_name == 'dev2' || inputs.branch_name == 'stable'))
|
|
) && matrix.os == 'macos-latest'
|
|
run: cd packages/electron && npm run publish
|
|
env:
|
|
APPLE_ID: ${{ secrets.APPLE_ID }}
|
|
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
|
|
CSC_LINK: ${{ secrets.CSC_LINK }}
|
|
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
|
|
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
|
|
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
|
USE_HARD_LINKS: false
|
|
|
|
- name: Publish App (Windows/Linux)
|
|
if: |
|
|
(
|
|
(github.ref == 'refs/heads/dev2' || github.ref == 'refs/heads/stable') ||
|
|
(github.event_name == 'workflow_call' && (inputs.branch_name == 'dev2' || inputs.branch_name == 'stable'))
|
|
) && (matrix.os == 'windows-latest' || matrix.os == 'ubuntu-latest')
|
|
run: cd packages/electron && npm run publish
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
|
|
|
# Pull Request 时只构建不发布
|
|
- name: Build only (Pull Request)
|
|
if: github.event_name == 'pull_request'
|
|
run: cd packages/electron && npm run build:electron
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
|
|
|
- name: Send Telegram Message
|
|
if: matrix.os == 'ubuntu-latest'
|
|
uses: appleboy/telegram-action@master
|
|
with:
|
|
to: ${{ secrets.TELEGRAM_CHAT_ID }}
|
|
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
|
format: html
|
|
message: |
|
|
🔔 <b>Electron App ${{ steps.details.outputs.type }}通知</b>
|
|
|
|
📂 <b>仓库:</b> ${{ github.repository }}
|
|
🌿 <b>分支:</b> <code>${{ github.ref_name }}</code>
|
|
👤 <b>作者:</b> ${{ steps.details.outputs.author }}
|
|
🔍 <b>提交:</b> <code>${{ steps.details.outputs.sha }}</code>
|
|
|
|
📝 <b>标题:</b> ${{ steps.details.outputs.message }}
|
|
📄 <b>修改的文件:</b>
|
|
<code>${{ steps.files.outputs.changed }}</code>
|
|
|
|
🔗 <b>详情链接:</b> ${{ steps.details.outputs.url }}
|
|
⏰ <b>时间:</b> ${{ github.event.head_commit.timestamp || github.event.pull_request.updated_at || github.event.issue.updated_at }}
|
|
|
|
#GitHub #${{ steps.details.outputs.type }}
|
|
|
|
- name: Send Error Notification
|
|
if: failure() && matrix.os == 'ubuntu-latest'
|
|
uses: appleboy/telegram-action@master
|
|
with:
|
|
to: ${{ secrets.TELEGRAM_CHAT_ID }}
|
|
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
|
format: html
|
|
message: |
|
|
❌ <b>GitHub Action 失败</b>
|
|
|
|
📂 <b>仓库:</b> ${{ github.repository }}
|
|
🔍 <b>工作流:</b> ${{ github.workflow }}
|
|
|
|
请检查 GitHub Actions 日志以获取更多详情。
|