draft5
This commit is contained in:
parent
3fec812079
commit
4c230930b7
280
.github/workflows/build.yml
vendored
280
.github/workflows/build.yml
vendored
@ -1,171 +1,159 @@
|
|||||||
name: Build and Release
|
name: KMP Build & Package
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
branches: [ main, develop ] # 在推送到 main 或 develop 分支时触发
|
||||||
tags:
|
tags:
|
||||||
- 'v*.*.*' # 仅在推送符合语义化版本的标签时触发
|
- 'v*' # 在推送版本标签时触发 (例如 v1.0.0)
|
||||||
|
pull_request:
|
||||||
|
branches: [ main, develop ] # 在向 main 或 develop 分支发起 Pull Request 时触发
|
||||||
|
workflow_dispatch: # 允许手动触发
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_android:
|
build:
|
||||||
name: Build Android APK
|
strategy:
|
||||||
runs-on: ubuntu-latest
|
fail-fast: false # 即使一个 job 失败,其他 job 也会继续运行
|
||||||
|
matrix:
|
||||||
|
os: [ ubuntu-latest, macos-latest, windows-latest ] # 根据你的目标平台选择操作系统
|
||||||
|
include:
|
||||||
|
# Android 构建 (通常在 Linux 环境下进行)
|
||||||
|
- os: ubuntu-latest
|
||||||
|
target: android
|
||||||
|
description: "Build Android App"
|
||||||
|
gradle_task: ":shared:assembleRelease :androidApp:assembleRelease" # 替换成你的 Android 打包任务
|
||||||
|
artifact_name: "android-app"
|
||||||
|
artifact_path: |
|
||||||
|
shared/build/outputs/aar/*.aar
|
||||||
|
androidApp/build/outputs/apk/release/*.apk
|
||||||
|
androidApp/build/outputs/bundle/release/*.aab
|
||||||
|
# iOS 构建 (必须在 macOS 环境下进行)
|
||||||
|
- os: macos-latest
|
||||||
|
target: ios
|
||||||
|
description: "Build iOS Framework"
|
||||||
|
# 注意: iOS 构建可能需要特定的 Xcode 版本,可以使用 actions/setup-xcode
|
||||||
|
# gradle_task: ":shared:packForXCFramework" # 常见的 iOS framework 打包任务
|
||||||
|
gradle_task: ":shared:assembleXCFramework" # 或者使用新的 Kotlin 插件的任务名
|
||||||
|
artifact_name: "ios-framework"
|
||||||
|
artifact_path: "shared/build/XCFrameworks/release/*.xcframework" # 检查你的实际输出路径
|
||||||
|
# JVM/Desktop 构建 (可以在多个操作系统上运行)
|
||||||
|
- os: ubuntu-latest # 为 Linux 构建
|
||||||
|
target: jvm_linux
|
||||||
|
description: "Build JVM/Desktop (Linux)"
|
||||||
|
gradle_task: ":desktopApp:packageDistributionForCurrentOS" # 替换成你的 Desktop 打包任务
|
||||||
|
artifact_name: "desktop-app-linux"
|
||||||
|
artifact_path: "desktopApp/build/compose/binaries/main/app/*" # 检查你的实际输出路径
|
||||||
|
- os: macos-latest # 为 macOS 构建
|
||||||
|
target: jvm_macos
|
||||||
|
description: "Build JVM/Desktop (macOS)"
|
||||||
|
gradle_task: ":desktopApp:packageDistributionForCurrentOS"
|
||||||
|
artifact_name: "desktop-app-macos"
|
||||||
|
artifact_path: "desktopApp/build/compose/binaries/main/app/*" # 检查你的实际输出路径
|
||||||
|
- os: windows-latest # 为 Windows 构建
|
||||||
|
target: jvm_windows
|
||||||
|
description: "Build JVM/Desktop (Windows)"
|
||||||
|
gradle_task: ":desktopApp:packageDistributionForCurrentOS"
|
||||||
|
artifact_name: "desktop-app-windows"
|
||||||
|
artifact_path: "desktopApp/build/compose/binaries/main/app/*" # 检查你的实际输出路径
|
||||||
|
# JavaScript 构建 (通常在 Linux 环境下进行)
|
||||||
|
- os: ubuntu-latest
|
||||||
|
target: js
|
||||||
|
description: "Build JavaScript"
|
||||||
|
gradle_task: ":shared:jsBrowserDistribution" # 替换成你的 JS 打包任务
|
||||||
|
artifact_name: "js-app"
|
||||||
|
artifact_path: "shared/build/distributions/*" # 检查你的实际输出路径
|
||||||
|
# Linux Native 构建
|
||||||
|
- os: ubuntu-latest
|
||||||
|
target: linux_native
|
||||||
|
description: "Build Linux Native"
|
||||||
|
gradle_task: ":shared:linkReleaseExecutableLinuxX64" # 替换成你的 Linux Native 编译任务
|
||||||
|
artifact_name: "linux-native-executable"
|
||||||
|
artifact_path: "shared/build/bin/linuxX64/releaseExecutable/*.kexe" # 检查你的实际输出路径
|
||||||
|
# macOS Native 构建 (也可以针对 arm64)
|
||||||
|
- os: macos-latest
|
||||||
|
target: macos_native
|
||||||
|
description: "Build macOS Native"
|
||||||
|
gradle_task: ":shared:linkReleaseExecutableMacosX64" # 或者 linkReleaseExecutableMacosArm64
|
||||||
|
artifact_name: "macos-native-executable"
|
||||||
|
artifact_path: "shared/build/bin/macosX64/releaseExecutable/*.kexe" # 检查你的实际输出路径
|
||||||
|
# Windows Native 构建
|
||||||
|
- os: windows-latest
|
||||||
|
target: windows_native
|
||||||
|
description: "Build Windows Native"
|
||||||
|
gradle_task: ":shared:linkReleaseExecutableMingwX64" # 替换成你的 Windows Native 编译任务
|
||||||
|
artifact_name: "windows-native-executable"
|
||||||
|
artifact_path: "shared/build/bin/mingwX64/releaseExecutable/*.exe" # 检查你的实际输出路径
|
||||||
|
|
||||||
|
# 如果某些平台不需要在所有操作系统上构建,可以在这里排除
|
||||||
|
# exclude:
|
||||||
|
# - os: windows-latest
|
||||||
|
# target: android
|
||||||
|
# - os: ubuntu-latest
|
||||||
|
# target: ios
|
||||||
|
|
||||||
|
name: ${{ matrix.description }} on ${{ matrix.os }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up JDK 17
|
- name: Set up JDK 17 # KMP 通常建议使用较新的 JDK 版本
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
distribution: 'zulu'
|
distribution: 'temurin' # 或者 'zulu', 'adopt' 等
|
||||||
java-version: '17'
|
java-version: '17'
|
||||||
cache: 'gradle' # 添加 Gradle 缓存
|
|
||||||
|
|
||||||
- name: Grant execute permission for gradlew
|
# 仅在 macOS runner 上为 iOS 构建设置 Xcode 版本 (如果需要特定版本)
|
||||||
run: chmod +x gradlew
|
- name: Select Xcode version (for iOS builds)
|
||||||
|
if: matrix.os == 'macos-latest' && matrix.target == 'ios'
|
||||||
|
run: sudo xcode-select -s /Applications/Xcode_15.3.app/Contents/Developer # 替换成你需要的 Xcode 版本路径
|
||||||
|
# 你也可以使用 action 如 maxim-lobanov/setup-xcode@v1
|
||||||
|
|
||||||
- name: Build Android APK
|
# 设置 Gradle (会自动处理 Gradle Wrapper)
|
||||||
run: ./gradlew :androidApp:assembleRelease
|
- name: Setup Gradle
|
||||||
|
uses: gradle/actions/setup-gradle@v3 # 使用 v3 版本
|
||||||
- name: Upload Android APK artifact
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
with:
|
||||||
name: android-apk
|
# gradle-version: wrapper # 默认使用 Gradle Wrapper
|
||||||
path: androidApp/build/outputs/apk/release/*.apk
|
# cache-read-only: ${{ github.ref != 'refs/heads/main' }} # 非 main 分支构建时,缓存只读 (可选)
|
||||||
retention-days: 1 # 保留1天即可,因为马上会被 release job 使用
|
# cache-encryption-key: ${{ secrets.GRADLE_CACHE_ENCRYPTION_KEY }} # 加密缓存 (可选)
|
||||||
|
|
||||||
build_desktop:
|
# Gradle 缓存 (KMP 项目的 .konan 目录和 Gradle 缓存很重要)
|
||||||
name: Build Desktop Artifacts
|
- name: Cache Gradle packages
|
||||||
runs-on: ubuntu-latest # 对于 JAR 和 Linux 包 (如 .deb)
|
uses: actions/cache@v4
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up JDK 17
|
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
with:
|
||||||
distribution: 'zulu'
|
|
||||||
java-version: '17'
|
|
||||||
cache: 'gradle'
|
|
||||||
|
|
||||||
- name: Grant execute permission for gradlew
|
|
||||||
run: chmod +x gradlew
|
|
||||||
|
|
||||||
# 注意: 根据你的 Compose Desktop 配置,任务名和输出路径可能不同
|
|
||||||
# packageUberJar 通常生成一个可执行的 JAR 文件
|
|
||||||
- name: Build Desktop UberJAR
|
|
||||||
run: ./gradlew :desktopApp:packageUberJar # 或其他打包任务如 packageDistribution
|
|
||||||
|
|
||||||
# 如果需要,可以添加其他平台的打包任务,例如 .deb
|
|
||||||
- name: Build Desktop DEB (Linux)
|
|
||||||
run: ./gradlew :desktopApp:packageDeb # 确保你的项目中配置了这个任务
|
|
||||||
|
|
||||||
- name: Upload Desktop artifacts
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: desktop-artifacts
|
|
||||||
# 根据实际生成的产物调整路径
|
|
||||||
path: |
|
path: |
|
||||||
desktopApp/build/compose/jars/*.jar
|
~/.gradle/caches
|
||||||
desktopApp/build/compose/binaries/main/deb/*.deb
|
~/.gradle/wrapper
|
||||||
# desktopApp/build/compose/distributions/*.* # 如果使用 packageDistribution
|
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
||||||
retention-days: 1
|
restore-keys: |
|
||||||
|
${{ runner.os }}-gradle-
|
||||||
|
|
||||||
build_ios:
|
- name: Cache Kotlin Native ($HOME/.konan)
|
||||||
name: Build iOS Framework
|
if: matrix.os == 'macos-latest' || matrix.os == 'ubuntu-latest' # .konan 缓存主要用于 Native 编译
|
||||||
runs-on: macos-latest # iOS 构建需要 macOS 环境
|
uses: actions/cache@v4
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
# KMM 项目的 iOS 构建通常也需要 JDK 来运行 Gradle
|
|
||||||
- name: Set up JDK 17
|
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
with:
|
||||||
distribution: 'zulu'
|
path: ~/.konan
|
||||||
java-version: '17'
|
key: ${{ runner.os }}-konan-${{ hashFiles('**/build.gradle.kts', '**/gradle.properties') }} # 或者更精确的 hash
|
||||||
cache: 'gradle'
|
restore-keys: |
|
||||||
|
${{ runner.os }}-konan-
|
||||||
|
|
||||||
- name: Grant execute permission for gradlew
|
# 授予 Gradle Wrapper 执行权限 (特别是对于 Windows)
|
||||||
run: chmod +x gradlew
|
- name: Make gradlew executable
|
||||||
|
if: runner.os != 'windows-latest'
|
||||||
|
run: chmod +x ./gradlew
|
||||||
|
- name: Make gradlew.bat executable (Windows)
|
||||||
|
if: runner.os == 'windows-latest'
|
||||||
|
run: cmd /c "chmod +x gradlew.bat" # 在 Windows 上,通常 gradlew.bat 默认就有执行权限,此步骤可能非必需
|
||||||
|
|
||||||
# (可选) 如果你需要特定版本的 Xcode
|
# 执行构建任务
|
||||||
# - name: Select Xcode version
|
- name: Build with Gradle
|
||||||
# run: sudo xcode-select -s /Applications/Xcode_15.3.app # 根据需要调整 Xcode 版本
|
run: ./gradlew ${{ matrix.gradle_task }} --no-daemon # --no-daemon 可以在 CI 环境中更稳定
|
||||||
|
|
||||||
# 重点: 确保这是你 KMM 项目中生成 XCFramework 的正确模块和任务名
|
# 上传构建产物
|
||||||
# 通常是 :shared:assembleReleaseXCFramework 或 :<your-shared-module-name>:assembleReleaseXCFramework
|
# 注意: actions/upload-artifact@v4 的用法与 v3 不同
|
||||||
# 如果你的 iOS 框架不是通过 KMM 共享模块生成的,而是 iosApp 直接产出,请调整
|
- name: Upload Artifact - ${{ matrix.artifact_name }}
|
||||||
- name: Build iOS XCFramework
|
|
||||||
run: ./gradlew :shared:assembleReleaseXCFramework # <--- ***请确认此任务名和模块名***
|
|
||||||
|
|
||||||
- name: Prepare XCFramework for upload (Zip it)
|
|
||||||
# XCFramework 是一个目录,最好压缩后再上传
|
|
||||||
# 路径也需要根据你的模块名调整
|
|
||||||
run: |
|
|
||||||
FRAMEWORK_PATH="shared/build/XCFrameworks/release/" # <--- ***请确认此路径***
|
|
||||||
FRAMEWORK_NAME=$(ls $FRAMEWORK_PATH | grep .xcframework)
|
|
||||||
echo "Framework Name: $FRAMEWORK_NAME"
|
|
||||||
ditto -c -k --sequesterRsrc --keepParent "$FRAMEWORK_PATH/$FRAMEWORK_NAME" "release-framework.zip"
|
|
||||||
# 如果你不是使用 :shared 模块,而是 :iosApp,路径可能类似:
|
|
||||||
# run: |
|
|
||||||
# FRAMEWORK_PATH="iosApp/build/Products/Release-iphoneos/"
|
|
||||||
# FRAMEWORK_NAME=$(ls $FRAMEWORK_PATH | grep .framework) # 注意这可能是 .framework 而不是 .xcframework
|
|
||||||
# ditto -c -k --sequesterRsrc --keepParent "$FRAMEWORK_PATH/$FRAMEWORK_NAME" "release-framework.zip"
|
|
||||||
|
|
||||||
|
|
||||||
- name: Upload iOS Framework artifact
|
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ios-framework
|
name: ${{ matrix.artifact_name }}
|
||||||
path: release-framework.zip # 上传压缩后的文件
|
path: ${{ matrix.artifact_path }}
|
||||||
retention-days: 1
|
if-no-files-found: error # 如果没有找到文件则报错
|
||||||
|
|
||||||
create_release:
|
|
||||||
name: Create GitHub Release
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [build_android, build_desktop, build_ios] # 等待所有构建完成
|
|
||||||
permissions:
|
|
||||||
contents: write # 需要写权限来创建 Release 和上传附件
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Download Android APK
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: android-apk
|
|
||||||
path: artifacts/android
|
|
||||||
|
|
||||||
- name: Download Desktop artifacts
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: desktop-artifacts
|
|
||||||
path: artifacts/desktop
|
|
||||||
|
|
||||||
- name: Download iOS Framework
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: ios-framework
|
|
||||||
path: artifacts/ios
|
|
||||||
|
|
||||||
- name: Create Release and Upload Assets
|
|
||||||
uses: softprops/action-gh-release@v2
|
|
||||||
with:
|
|
||||||
tag_name: ${{ github.ref_name }}
|
|
||||||
name: Release ${{ github.ref_name }}
|
|
||||||
body: | # 你可以自定义 Release 的描述信息
|
|
||||||
Automated release for ${{ github.ref_name }}
|
|
||||||
|
|
||||||
**Artifacts:**
|
|
||||||
- Android APK
|
|
||||||
- Desktop (JAR, DEB)
|
|
||||||
- iOS Framework (XCFramework.zip)
|
|
||||||
|
|
||||||
*Built by GitHub Actions*
|
|
||||||
draft: false # 设置为 true 如果你想手动发布草稿
|
|
||||||
prerelease: false # 如果是预发布版本,设置为 true
|
|
||||||
files: | # 列出所有要上传的文件
|
|
||||||
artifacts/android/*.apk
|
|
||||||
artifacts/desktop/*.jar
|
|
||||||
artifacts/desktop/*.deb
|
|
||||||
artifacts/ios/*.zip
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user