|
| 1 | +name: Build Assets |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + upload_to_release: |
| 7 | + description: '上传产物到指定 GitHub Release' |
| 8 | + required: false |
| 9 | + type: boolean |
| 10 | + default: false |
| 11 | + release_tag: |
| 12 | + description: 'Release tag,例如 v1.2.4;仅在上传到 Release 时需要' |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + default: '' |
| 16 | + workflow_call: |
| 17 | + inputs: |
| 18 | + upload_to_release: |
| 19 | + required: false |
| 20 | + type: boolean |
| 21 | + default: false |
| 22 | + release_tag: |
| 23 | + required: false |
| 24 | + type: string |
| 25 | + default: '' |
| 26 | + |
| 27 | +permissions: |
| 28 | + contents: write |
| 29 | + |
| 30 | +jobs: |
| 31 | + build-assets: |
| 32 | + name: Build demo assets |
| 33 | + runs-on: macOS-latest |
| 34 | + env: |
| 35 | + ARTIFACT_DIR: release-artifacts |
| 36 | + steps: |
| 37 | + - name: Check out code |
| 38 | + uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - name: Validate release upload inputs |
| 41 | + if: inputs.upload_to_release |
| 42 | + run: | |
| 43 | + if [ -z "${{ inputs.release_tag }}" ]; then |
| 44 | + echo "release_tag 不能为空,因为 upload_to_release=true" >&2 |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | +
|
| 48 | + - name: Set up JDK 17 |
| 49 | + uses: actions/setup-java@v4 |
| 50 | + with: |
| 51 | + distribution: 'zulu' |
| 52 | + java-version: 17 |
| 53 | + |
| 54 | + - name: Set up Python |
| 55 | + uses: actions/setup-python@v4 |
| 56 | + with: |
| 57 | + python-version: '3.x' |
| 58 | + |
| 59 | + - name: Set up Node.js |
| 60 | + uses: actions/setup-node@v4 |
| 61 | + with: |
| 62 | + node-version: '20' |
| 63 | + |
| 64 | + - name: Set up Yarn |
| 65 | + run: | |
| 66 | + echo "📦 安装 Yarn..." |
| 67 | + npm install -g yarn |
| 68 | + yarn --version |
| 69 | +
|
| 70 | + - name: Set version variables |
| 71 | + id: version |
| 72 | + run: | |
| 73 | + if [ -n "${{ inputs.release_tag }}" ]; then |
| 74 | + VERSION="${{ inputs.release_tag }}" |
| 75 | + else |
| 76 | + VERSION=$(python scripts/read_version.py) |
| 77 | + fi |
| 78 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 79 | + echo "📦 当前构建版本: $VERSION" |
| 80 | +
|
| 81 | + - name: Validate Gradle wrapper |
| 82 | + uses: gradle/wrapper-validation-action@v1 |
| 83 | + |
| 84 | + - name: Install WASM dependencies |
| 85 | + run: | |
| 86 | + echo "📦 安装 WASM 构建依赖..." |
| 87 | + if [ -f "kotlin-js-store/wasm/yarn.lock" ]; then |
| 88 | + cd kotlin-js-store/wasm |
| 89 | + yarn install --frozen-lockfile |
| 90 | + cd ../.. |
| 91 | + echo "✅ WASM 依赖安装完成" |
| 92 | + else |
| 93 | + echo "ℹ️ 未找到 WASM 依赖文件,跳过安装" |
| 94 | + fi |
| 95 | +
|
| 96 | + - name: Setup Gradle |
| 97 | + uses: gradle/gradle-build-action@v2 |
| 98 | + with: |
| 99 | + gradle-home-cache-cleanup: true |
| 100 | + |
| 101 | + - name: Build Android Debug APK |
| 102 | + run: ./gradlew :composeApp:assembleDebug --stacktrace |
| 103 | + |
| 104 | + - name: Build Wasm distribution |
| 105 | + run: ./gradlew :composeApp:wasmJsBrowserDistribution --stacktrace |
| 106 | + |
| 107 | + - name: Build Desktop DMG |
| 108 | + run: ./gradlew :composeApp:packageReleaseDmg --stacktrace |
| 109 | + |
| 110 | + - name: Build iOS simulator app |
| 111 | + run: | |
| 112 | + xcodebuild \ |
| 113 | + -project iosApp/iosApp.xcodeproj \ |
| 114 | + -target iosApp \ |
| 115 | + -configuration Debug \ |
| 116 | + -sdk iphonesimulator \ |
| 117 | + -derivedDataPath build/ios-simulator \ |
| 118 | + CODE_SIGNING_ALLOWED=NO \ |
| 119 | + CODE_SIGNING_REQUIRED=NO \ |
| 120 | + build |
| 121 | +
|
| 122 | + - name: Collect release artifacts |
| 123 | + run: | |
| 124 | + set -euo pipefail |
| 125 | + mkdir -p "$ARTIFACT_DIR" |
| 126 | +
|
| 127 | + ANDROID_APK=$(find composeApp/build/outputs/apk/debug -name "*.apk" -print -quit) |
| 128 | + if [ -z "$ANDROID_APK" ]; then |
| 129 | + echo "Android Debug APK 未找到" >&2 |
| 130 | + exit 1 |
| 131 | + fi |
| 132 | + cp "$ANDROID_APK" "$ARTIFACT_DIR/compose-data-saver-android-debug.apk" |
| 133 | +
|
| 134 | + WASM_DIR="composeApp/build/dist/wasmJs/productionExecutable" |
| 135 | + if [ ! -d "$WASM_DIR" ]; then |
| 136 | + echo "Wasm 产物目录未找到: $WASM_DIR" >&2 |
| 137 | + exit 1 |
| 138 | + fi |
| 139 | + ditto -c -k --sequesterRsrc --keepParent "$WASM_DIR" "$ARTIFACT_DIR/compose-data-saver-wasm.zip" |
| 140 | +
|
| 141 | + DESKTOP_DMG=$(find composeApp/build/compose -name "*.dmg" -print -quit) |
| 142 | + if [ -z "$DESKTOP_DMG" ]; then |
| 143 | + echo "Desktop DMG 未找到" >&2 |
| 144 | + exit 1 |
| 145 | + fi |
| 146 | + cp "$DESKTOP_DMG" "$ARTIFACT_DIR/compose-data-saver-desktop-macos.dmg" |
| 147 | +
|
| 148 | + IOS_APP="build/ios-simulator/Build/Products/Debug-iphonesimulator/ComposeDataSaver.app" |
| 149 | + if [ ! -d "$IOS_APP" ]; then |
| 150 | + echo "iOS Simulator App 未找到: $IOS_APP" >&2 |
| 151 | + exit 1 |
| 152 | + fi |
| 153 | + ditto -c -k --sequesterRsrc --keepParent "$IOS_APP" "$ARTIFACT_DIR/compose-data-saver-ios-simulator-debug.zip" |
| 154 | +
|
| 155 | + ls -lah "$ARTIFACT_DIR" |
| 156 | +
|
| 157 | + - name: Upload workflow artifacts |
| 158 | + uses: actions/upload-artifact@v4 |
| 159 | + with: |
| 160 | + name: compose-data-saver-release-assets |
| 161 | + path: ${{ env.ARTIFACT_DIR }}/* |
| 162 | + if-no-files-found: error |
| 163 | + |
| 164 | + - name: Upload assets to GitHub Release |
| 165 | + if: inputs.upload_to_release |
| 166 | + uses: softprops/action-gh-release@v2 |
| 167 | + with: |
| 168 | + tag_name: ${{ inputs.release_tag }} |
| 169 | + files: ${{ env.ARTIFACT_DIR }}/* |
| 170 | + fail_on_unmatched_files: true |
| 171 | + overwrite_files: true |
| 172 | + |
| 173 | + - name: Summary |
| 174 | + run: | |
| 175 | + echo "🎉 产物构建完成!" |
| 176 | + echo "📦 版本: ${{ steps.version.outputs.version }}" |
| 177 | + echo "📱 Android Debug APK: compose-data-saver-android-debug.apk" |
| 178 | + echo "🧩 Wasm: compose-data-saver-wasm.zip" |
| 179 | + echo "🖥️ Desktop (macOS): compose-data-saver-desktop-macos.dmg" |
| 180 | + echo "📦 iOS Simulator Debug: compose-data-saver-ios-simulator-debug.zip" |
| 181 | + if [ "${{ inputs.upload_to_release }}" = "true" ]; then |
| 182 | + echo "🔗 Release Tag: ${{ inputs.release_tag }}" |
| 183 | + else |
| 184 | + echo "🔧 当前为调试构建,产物已上传为 workflow artifact" |
| 185 | + fi |
0 commit comments