|
@@ -91,6 +91,7 @@ jobs:
|
|
uses: actions/setup-node@v4
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
with:
|
|
node-version: '22'
|
|
node-version: '22'
|
|
|
|
+ cache: 'npm' # 缓存 npm 依赖
|
|
|
|
|
|
- name: 安装 Android SDK (Windows)
|
|
- name: 安装 Android SDK (Windows)
|
|
if: runner.os == 'Windows'
|
|
if: runner.os == 'Windows'
|
|
@@ -98,8 +99,26 @@ jobs:
|
|
|
|
|
|
- name: 安装依赖
|
|
- name: 安装依赖
|
|
run: npm install --force --registry=https://registry.npmmirror.com/
|
|
run: npm install --force --registry=https://registry.npmmirror.com/
|
|
|
|
+
|
|
|
|
+ - name: 缓存 H5 构建产物
|
|
|
|
+ id: cache-h5-build
|
|
|
|
+ uses: actions/cache@v4
|
|
|
|
+ with:
|
|
|
|
+ path: dist/h5
|
|
|
|
+ key: h5-build-${{ runner.os }}-${{ hashFiles('src/**', 'config/**', 'package-lock.json', '.build/h5_for_production.js') }}
|
|
|
|
+ restore-keys: |
|
|
|
|
+ h5-build-${{ runner.os }}-
|
|
|
|
+
|
|
|
|
+ - name: 显示缓存状态
|
|
|
|
+ run: |
|
|
|
|
+ if [ "${{ steps.cache-h5-build.outputs.cache-hit }}" == "true" ]; then
|
|
|
|
+ echo "✅ H5 构建缓存命中,跳过构建"
|
|
|
|
+ else
|
|
|
|
+ echo "❌ H5 构建缓存未命中,需要重新构建"
|
|
|
|
+ fi
|
|
|
|
|
|
- name: 构建h5
|
|
- name: 构建h5
|
|
|
|
+ if: steps.cache-h5-build.outputs.cache-hit != 'true'
|
|
run: node .build/h5_for_production.js
|
|
run: node .build/h5_for_production.js
|
|
|
|
|
|
- name: Set up JDK 17
|
|
- name: Set up JDK 17
|
|
@@ -108,62 +127,5 @@ jobs:
|
|
java-version: '17'
|
|
java-version: '17'
|
|
distribution: 'temurin'
|
|
distribution: 'temurin'
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- - name: 手动安装 Android SDK (Linux)
|
|
|
|
- if: runner.os == 'Linux'
|
|
|
|
- shell: bash
|
|
|
|
- run: |
|
|
|
|
- # 下载 Linux 版本的 command line tools
|
|
|
|
- wget https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -O /tmp/cmdtools.zip
|
|
|
|
-
|
|
|
|
- # 解压
|
|
|
|
- SDK_ROOT=$HOME/android-sdk
|
|
|
|
- mkdir -p $SDK_ROOT/cmdline-tools/latest
|
|
|
|
- unzip -q /tmp/cmdtools.zip -d $SDK_ROOT/cmdline-tools/latest
|
|
|
|
-
|
|
|
|
- # 设置环境变量
|
|
|
|
- echo "ANDROID_HOME=$SDK_ROOT" >> $GITHUB_ENV
|
|
|
|
- echo "ANDROID_SDK_ROOT=$SDK_ROOT" >> $GITHUB_ENV
|
|
|
|
-
|
|
|
|
- # 安装包
|
|
|
|
- yes | $SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --install "platforms;android-35" "build-tools;35.0.0" --sdk_root=$SDK_ROOT
|
|
|
|
- yes | $SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --licenses --sdk_root=$SDK_ROOT
|
|
|
|
-
|
|
|
|
- - name: Cache Android SDK # 新增:缓存 SDK,避免每次下载
|
|
|
|
- uses: actions/cache@v4
|
|
|
|
- with:
|
|
|
|
- path: |
|
|
|
|
- %LOCALAPPDATA%\Android\Sdk # 备选用户目录
|
|
|
|
- key: android-sdk-${{ runner.os }}-${{ hashFiles('**/*.xml') }} # 基于项目文件 hash
|
|
|
|
-
|
|
|
|
- - name: Set up Node.js (for Cordova)
|
|
|
|
- uses: actions/setup-node@v4
|
|
|
|
- with:
|
|
|
|
- node-version: '20'
|
|
|
|
- cache: 'npm' # 缓存 npm 依赖
|
|
|
|
-
|
|
|
|
- - name: Install Cordova globally
|
|
|
|
- run: npm install -g cordova@latest --no-optional
|
|
|
|
-
|
|
|
|
- - name: Add Cordova Android platform 14.0.1
|
|
|
|
- run: |
|
|
|
|
- cordova platform add android@14.0.1 --save
|
|
|
|
- cordova requirements android # 检查环境(PowerShell 会自动处理路径)
|
|
|
|
-
|
|
|
|
- - name: Verify Environment Variables (PowerShell)
|
|
|
|
- run: |
|
|
|
|
- Write-Output "JAVA_HOME: $env:JAVA_HOME"
|
|
|
|
- Write-Output "ANDROID_HOME: $env:ANDROID_HOME"
|
|
|
|
- Write-Output "PATH includes Gradle: $(if ($env:PATH -like '*gradle*') { 'Yes' } else { 'No' })"
|
|
|
|
-
|
|
|
|
- - name: Update Gradle Wrapper to 9.0
|
|
|
|
- run: |
|
|
|
|
- # PowerShell 语法更新 wrapper
|
|
|
|
- (Get-Content gradle/wrapper/gradle-wrapper.properties) -replace 'gradle-[0-9]+\.[0-9]+-bin\.zip', 'gradle-9.0-bin.zip' | Set-Content gradle/wrapper/gradle-wrapper.properties
|
|
|
|
- # 确保 gradlew 可执行(Windows 上是 .bat)
|
|
|
|
- if (Test-Path 'gradlew.bat') { Write-Output "Gradle wrapper ready" }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- name: 构建 Android APK
|
|
- name: 构建 Android APK
|
|
run: npm run build:android
|
|
run: npm run build:android
|