Update build-apk.yml

This commit is contained in:
hrz
2025-08-12 13:54:47 +08:00
committed by GitHub
parent a9199171df
commit cdfe24fcdb
+88 -32
View File
@@ -13,7 +13,7 @@ on:
create_release: create_release:
description: 'Create GitHub Release' description: 'Create GitHub Release'
required: false required: false
default: false default: true
type: boolean type: boolean
jobs: jobs:
@@ -50,92 +50,147 @@ jobs:
echo "VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV echo "VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
echo "IS_VERSION=true" >> $GITHUB_ENV echo "IS_VERSION=true" >> $GITHUB_ENV
echo "BUILD_TYPE=tag" >> $GITHUB_ENV echo "BUILD_TYPE=tag" >> $GITHUB_ENV
echo "CREATE_RELEASE=true" >> $GITHUB_ENV
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
# 手动触发时从输入获取版本号 # 手动触发时从输入获取版本号
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
echo "IS_VERSION=${{ github.event.inputs.create_release }}" >> $GITHUB_ENV echo "IS_VERSION=${{ github.event.inputs.create_release }}" >> $GITHUB_ENV
echo "BUILD_TYPE=manual" >> $GITHUB_ENV echo "BUILD_TYPE=manual" >> $GITHUB_ENV
echo "CREATE_RELEASE=${{ github.event.inputs.create_release }}" >> $GITHUB_ENV
else else
# 其他情况使用默认版本 # 其他情况使用默认版本
echo "VERSION=latest" >> $GITHUB_ENV echo "VERSION=latest" >> $GITHUB_ENV
echo "IS_VERSION=false" >> $GITHUB_ENV echo "IS_VERSION=false" >> $GITHUB_ENV
echo "BUILD_TYPE=other" >> $GITHUB_ENV echo "BUILD_TYPE=other" >> $GITHUB_ENV
echo "CREATE_RELEASE=false" >> $GITHUB_ENV
fi fi
echo "Version: ${{ env.VERSION }}" echo "Version: ${{ env.VERSION }}"
echo "Is Version: ${{ env.IS_VERSION }}" echo "Is Version: ${{ env.IS_VERSION }}"
echo "Build Type: ${{ env.BUILD_TYPE }}" echo "Build Type: ${{ env.BUILD_TYPE }}"
echo "Create Release: ${{ env.CREATE_RELEASE }}"
- name: Install dependencies - name: Install dependencies
run: | run: |
cd main/manager-mobile cd main/manager-mobile
pnpm install --frozen-lockfile pnpm install --frozen-lockfile
- name: Build Android APK - name: Build uni-app project
run: | run: |
cd main/manager-mobile cd main/manager-mobile
pnpm build:app-android pnpm build:app-android
env: env:
NODE_ENV: production NODE_ENV: production
- name: Find APK file - name: Check build output
id: find_apk
run: | run: |
cd main/manager-mobile cd main/manager-mobile
APK_PATH=$(find unpackage -name "*.apk" | head -1) echo "=== Build output directory structure ==="
if [ -n "$APK_PATH" ]; then find . -name "unpackage" -type d
echo "APK_PATH=$APK_PATH" >> $GITHUB_ENV if [ -d "unpackage" ]; then
echo "APK_NAME=$(basename $APK_PATH)" >> $GITHUB_ENV echo "=== unpackage directory contents ==="
echo "APK_FOUND=true" >> $GITHUB_ENV find unpackage -type f 2>/dev/null || echo "unpackage directory not found"
else fi
echo "APK_FOUND=false" >> $GITHUB_ENV
echo "APK_NAME=" >> $GITHUB_ENV # 检查dist目录
if [ -d "dist" ]; then
echo "=== dist directory contents ==="
find dist -type f 2>/dev/null
fi fi
- name: Create Release (only for version tags or manual with create_release=true) - name: Create build package
if: env.IS_VERSION == 'true' && env.BUILD_TYPE == 'tag' id: create_package
run: |
cd main/manager-mobile
# 创建构建包目录
mkdir -p build-package
# 复制构建产物
if [ -d "unpackage" ]; then
cp -r unpackage build-package/
echo "Copied unpackage directory"
fi
if [ -d "dist" ]; then
cp -r dist build-package/
echo "Copied dist directory"
fi
# 创建构建信息文件
cat > build-package/build-info.json << EOF
{
"version": "${{ env.VERSION }}",
"buildType": "${{ env.BUILD_TYPE }}",
"buildDate": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
"commit": "${{ github.sha }}",
"branch": "${{ github.ref_name }}"
}
EOF
# 创建ZIP包
cd build-package
zip -r "../xiaozhi-mobile-${{ env.VERSION }}.zip" .
cd ..
echo "PACKAGE_PATH=xiaozhi-mobile-${{ env.VERSION }}.zip" >> $GITHUB_ENV
echo "PACKAGE_FOUND=true" >> $GITHUB_ENV
echo "Created build package: xiaozhi-mobile-${{ env.VERSION }}.zip"
- name: Create Release (for version tags or manual with create_release=true)
if: env.CREATE_RELEASE == 'true'
id: create_release id: create_release
uses: actions/create-release@v1 uses: actions/create-release@v1
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
tag_name: ${{ github.ref }} tag_name: ${{ env.BUILD_TYPE == 'tag' && github.ref || format('v{0}', env.VERSION) }}
release_name: Release ${{ env.VERSION }} release_name: Release ${{ env.VERSION }}
body: | body: |
## What's Changed ## What's Changed
### 🚀 New Features ### 🚀 New Features
- Android APK build included - Mobile app build package included
### 📱 Mobile App ### 📱 Mobile App
- APK: `xiaozhi-server-${{ env.VERSION }}.apk` - Build Package: `xiaozhi-mobile-${{ env.VERSION }}.zip`
- Contains uni-app build artifacts for Android
### 🔧 Build Info ### 🔧 Build Info
- Build Type: ${{ env.BUILD_TYPE }} - Build Type: ${{ env.BUILD_TYPE }}
- Version: ${{ env.VERSION }} - Version: ${{ env.VERSION }}
- Build Date: ${{ github.event.head_commit.timestamp || 'Manual build' }}
- Commit: ${{ github.sha }}
### 📋 Installation Instructions
1. Download the build package
2. Extract the ZIP file
3. Use HBuilderX to open the project
4. Build for Android platform
### 📋 Full Changelog ### 📋 Full Changelog
${{ env.BUILD_TYPE == 'tag' && format('See the [commit history](https://github.com/{0}/compare/...{1})', github.repository, github.ref) || 'Manual build - no changelog available' }} ${{ env.BUILD_TYPE == 'tag' && format('See the [commit history](https://github.com/{0}/compare/...{1})', github.repository, github.ref) || 'Manual build - no changelog available' }}
draft: false draft: false
prerelease: ${{ env.BUILD_TYPE == 'manual' }} prerelease: ${{ env.BUILD_TYPE == 'manual' }}
- name: Upload APK to Release - name: Upload Build Package to Release
if: steps.create_release.outputs.upload_url != '' && env.APK_FOUND == 'true' && env.BUILD_TYPE == 'tag' if: steps.create_release.outputs.upload_url != '' && env.PACKAGE_FOUND == 'true'
uses: actions/upload-release-asset@v1 uses: actions/upload-release-asset@v1
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
upload_url: ${{ steps.create_release.outputs.upload_url }} upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: main/manager-mobile/${{ steps.find_apk.outputs.APK_PATH }} asset_path: main/manager-mobile/${{ env.PACKAGE_PATH }}
asset_name: xiaozhi-server-${{ env.VERSION }}.apk asset_name: xiaozhi-mobile-${{ env.VERSION }}.zip
asset_content_type: application/vnd.android.package-archive asset_content_type: application/zip
- name: Upload APK as Artifact (for debugging) - name: Upload Build Package as Artifact
if: env.APK_FOUND == 'true' if: env.PACKAGE_FOUND == 'true'
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: android-apk-${{ env.VERSION }} name: mobile-build-${{ env.VERSION }}
path: main/manager-mobile/${{ steps.find_apk.outputs.APK_PATH }} path: main/manager-mobile/${{ env.PACKAGE_PATH }}
retention-days: 30 retention-days: 30
- name: Show build info - name: Show build info
@@ -143,14 +198,15 @@ jobs:
echo "Build completed!" echo "Build completed!"
echo "Version: ${{ env.VERSION }}" echo "Version: ${{ env.VERSION }}"
echo "Build Type: ${{ env.BUILD_TYPE }}" echo "Build Type: ${{ env.BUILD_TYPE }}"
echo "APK found: ${{ env.APK_FOUND }}" echo "Package found: ${{ env.PACKAGE_FOUND }}"
if [ "${{ env.APK_FOUND }}" = "true" ]; then echo "Create Release: ${{ env.CREATE_RELEASE }}"
echo "APK path: ${{ steps.find_apk.outputs.APK_PATH }}"
echo "APK name: ${{ steps.find_apk.outputs.APK_NAME }}" if [ "${{ env.PACKAGE_FOUND }}" = "true" ]; then
echo "Package path: ${{ env.PACKAGE_PATH }}"
fi fi
if [ "${{ env.IS_VERSION }}" = "true" ]; then if [ "${{ env.CREATE_RELEASE }}" = "true" ]; then
echo "✅ Release will be created" echo "✅ Release will be created"
else else
echo "️ No Release created (manual build or no version)" echo "️ No Release created (manual build with create_release=false or no version)"
fi fi