- test job: testDebugUnitTest + lintDebug,上传 XML 测试报告和 lint 报告 - build-debug job: assembleDebug,上传 Debug APK artifact - build-release job: assembleRelease + APK 完整性验证(manifest/arsc/res/),上传 Release APK artifact - test 通过后才构建,三个 job 串行依赖 - 所有 artifact 保留 14 天
113 lines
3.2 KiB
YAML
113 lines
3.2 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
|
|
jobs:
|
|
test:
|
|
name: Unit Tests & Lint
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/setup-java@v4
|
|
with:
|
|
java-version: '17'
|
|
distribution: 'temurin'
|
|
- uses: android-actions/setup-android@v3
|
|
with:
|
|
packages: 'platforms;android-35 build-tools;35.0.0'
|
|
|
|
- name: Grant execute permission for gradlew
|
|
run: chmod +x gradlew
|
|
|
|
- name: Run unit tests
|
|
run: ./gradlew testDebugUnitTest
|
|
|
|
- name: Upload test results
|
|
if: always()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: unit-test-results
|
|
path: app/build/test-results/testDebugUnitTest/*.xml
|
|
retention-days: 14
|
|
|
|
- name: Run lint
|
|
run: ./gradlew lintDebug
|
|
|
|
- name: Upload lint results
|
|
if: always()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: lint-results
|
|
path: app/build/reports/lint-results-debug.*
|
|
retention-days: 14
|
|
|
|
build-debug:
|
|
name: Debug APK
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/setup-java@v4
|
|
with:
|
|
java-version: '17'
|
|
distribution: 'temurin'
|
|
- uses: android-actions/setup-android@v3
|
|
with:
|
|
packages: 'platforms;android-35 build-tools;35.0.0'
|
|
|
|
- name: Grant execute permission for gradlew
|
|
run: chmod +x gradlew
|
|
|
|
- name: Assemble Debug
|
|
run: ./gradlew assembleDebug
|
|
|
|
- name: Upload Debug APK
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: debug-apk
|
|
path: app/build/outputs/apk/debug/app-debug.apk
|
|
retention-days: 14
|
|
|
|
build-release:
|
|
name: Release APK (no signing)
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/setup-java@v4
|
|
with:
|
|
java-version: '17'
|
|
distribution: 'temurin'
|
|
- uses: android-actions/setup-android@v3
|
|
with:
|
|
packages: 'platforms;android-35 build-tools;35.0.0'
|
|
|
|
- name: Grant execute permission for gradlew
|
|
run: chmod +x gradlew
|
|
|
|
- name: Assemble Release
|
|
run: ./gradlew assembleRelease
|
|
|
|
- name: Verify Release APK
|
|
run: |
|
|
APK=app/build/outputs/apk/release/app-release.apk
|
|
if [ ! -f "$APK" ]; then
|
|
echo "❌ Release APK not found"
|
|
exit 1
|
|
fi
|
|
echo "✅ Release APK size: $(du -h "$APK" | cut -f1)"
|
|
# Verify APK contains essential resources
|
|
unzip -l "$APK" | grep -q "AndroidManifest.xml" || { echo "❌ AndroidManifest.xml missing"; exit 1; }
|
|
unzip -l "$APK" | grep -q "resources.arsc" || { echo "❌ resources.arsc missing"; exit 1; }
|
|
unzip -l "$APK" | grep -q "res/" || { echo "❌ res/ directory missing"; exit 1; }
|
|
echo "✅ APK integrity verified: manifest + arsc + res/ all present"
|
|
|
|
- name: Upload Release APK
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: release-apk
|
|
path: app/build/outputs/apk/release/app-release.apk
|
|
retention-days: 14 |