192 lines
6.0 KiB
YAML
192 lines
6.0 KiB
YAML
name: Android APK 构建
|
||
|
||
# 触发条件:
|
||
# 1. 每次推送代码到 main 分支:自动构建并更新名为 "latest" 的 Release (Rolling Release)
|
||
# 2. 推送 v* 格式的 tag(如 v1.0):自动构建并发布正式 Release
|
||
# 3. 手动触发(workflow_dispatch):手动指定 tag 发布
|
||
on:
|
||
push:
|
||
branches: [ main ]
|
||
tags: [ 'v*' ]
|
||
workflow_dispatch:
|
||
inputs:
|
||
release_tag:
|
||
description: '上传到已有标签 (如 v1.0)'
|
||
required: true
|
||
default: 'v1.0'
|
||
|
||
env:
|
||
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
|
||
|
||
permissions:
|
||
contents: write
|
||
|
||
jobs:
|
||
# ── 中文版 APK 构建 ──────────────────────────────────────────────────────────
|
||
build-android-zh:
|
||
name: Build EmbyX-zh APK
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- uses: actions/checkout@v4
|
||
|
||
- name: Setup JDK 17
|
||
uses: actions/setup-java@v4
|
||
with:
|
||
java-version: '17'
|
||
distribution: 'temurin'
|
||
|
||
- name: Setup Node.js
|
||
uses: actions/setup-node@v4
|
||
with:
|
||
node-version: 18
|
||
|
||
# 动态生成中文版 capacitor.config.json(webDir 指向 zh/ 目录)
|
||
- name: Create capacitor.config.json (zh)
|
||
run: |
|
||
cat > capacitor.config.json << 'EOF'
|
||
{
|
||
"appId": "juneix.embyx",
|
||
"appName": "EmbyX",
|
||
"webDir": "zh",
|
||
"server": {
|
||
"androidScheme": "http",
|
||
"cleartext": true
|
||
},
|
||
"plugins": {
|
||
"SplashScreen": {
|
||
"launchAutoHide": true,
|
||
"backgroundColor": "#000000",
|
||
"androidScaleType": "CENTER",
|
||
"showSpinner": false
|
||
}
|
||
}
|
||
}
|
||
EOF
|
||
|
||
- name: Install Capacitor dependencies
|
||
run: npm install
|
||
|
||
- name: Add & Sync Android Platform
|
||
run: |
|
||
npx cap add android
|
||
npx cap sync android
|
||
|
||
# 运行补丁脚本:替换图标、注册屏保、添加全屏模式
|
||
- name: Patch Android Project (zh)
|
||
run: python .github/patch_android.py --lang zh
|
||
|
||
- name: Build Debug APK
|
||
run: |
|
||
cd android
|
||
chmod +x gradlew
|
||
./gradlew assembleDebug
|
||
|
||
- name: Rename to EmbyX-zh.apk
|
||
run: mv android/app/build/outputs/apk/debug/app-debug.apk EmbyX-zh.apk
|
||
|
||
- name: Upload Artifact
|
||
uses: actions/upload-artifact@v4
|
||
with:
|
||
name: embyx-zh
|
||
path: EmbyX-zh.apk
|
||
|
||
# ── 英文版 APK 构建 ──────────────────────────────────────────────────────────
|
||
build-android-en:
|
||
name: Build EmbyX-en APK
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- uses: actions/checkout@v4
|
||
|
||
- name: Setup JDK 17
|
||
uses: actions/setup-java@v4
|
||
with:
|
||
java-version: '17'
|
||
distribution: 'temurin'
|
||
|
||
- name: Setup Node.js
|
||
uses: actions/setup-node@v4
|
||
with:
|
||
node-version: 18
|
||
|
||
# 动态生成英文版 capacitor.config.json(webDir 指向 en/ 目录)
|
||
- name: Create capacitor.config.json (en)
|
||
run: |
|
||
cat > capacitor.config.json << 'EOF'
|
||
{
|
||
"appId": "juneix.embyx",
|
||
"appName": "EmbyX",
|
||
"webDir": "en",
|
||
"server": {
|
||
"androidScheme": "http",
|
||
"cleartext": true
|
||
},
|
||
"plugins": {
|
||
"SplashScreen": {
|
||
"launchAutoHide": true,
|
||
"backgroundColor": "#000000",
|
||
"androidScaleType": "CENTER",
|
||
"showSpinner": false
|
||
}
|
||
}
|
||
}
|
||
EOF
|
||
|
||
- name: Install Capacitor dependencies
|
||
run: npm install
|
||
|
||
- name: Add & Sync Android Platform
|
||
run: |
|
||
npx cap add android
|
||
npx cap sync android
|
||
|
||
# 运行补丁脚本:替换图标、注册屏保、添加全屏模式
|
||
- name: Patch Android Project (en)
|
||
run: python .github/patch_android.py --lang en
|
||
|
||
- name: Build Debug APK
|
||
run: |
|
||
cd android
|
||
chmod +x gradlew
|
||
./gradlew assembleDebug
|
||
|
||
- name: Rename to EmbyX-en.apk
|
||
run: mv android/app/build/outputs/apk/debug/app-debug.apk EmbyX-en.apk
|
||
|
||
- name: Upload Artifact
|
||
uses: actions/upload-artifact@v4
|
||
with:
|
||
name: embyx-en
|
||
path: EmbyX-en.apk
|
||
|
||
# ── 发布 Release ─────────────────────────────────────────────────────────────
|
||
# 当推送到 main 分支、打 v* 标签或手动触发时执行
|
||
release:
|
||
name: Create GitHub Release
|
||
needs: [build-android-zh, build-android-en]
|
||
runs-on: ubuntu-latest
|
||
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main'
|
||
steps:
|
||
- name: Download all artifacts
|
||
uses: actions/download-artifact@v4
|
||
|
||
- name: Verify APK files exist
|
||
run: |
|
||
ls -R
|
||
test -f "embyx-zh/EmbyX-zh.apk"
|
||
test -f "embyx-en/EmbyX-en.apk"
|
||
|
||
- name: Create Release
|
||
uses: softprops/action-gh-release@v2
|
||
with:
|
||
# 如果是 main 分支,固定使用 latest 标签以便滚动更新
|
||
tag_name: ${{ github.ref_name == 'main' && 'latest' || (github.event_name == 'workflow_dispatch' && inputs.release_tag || github.ref_name) }}
|
||
name: ${{ github.ref_name == 'main' && 'Latest Build (Rolling)' || (github.event_name == 'workflow_dispatch' && inputs.release_tag || github.ref_name) }}
|
||
prerelease: ${{ github.ref_name == 'main' }}
|
||
draft: false
|
||
fail_on_unmatched_files: true
|
||
files: |
|
||
embyx-zh/EmbyX-zh.apk
|
||
embyx-en/EmbyX-en.apk
|
||
env:
|
||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|