Files
xiaozhi-esp32-server/.github/workflows/build-apk.yml
T
2025-08-12 13:54:47 +08:00

213 lines
7.3 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Build Android APK
on:
push:
tags:
- 'v*.*.*' # 只在以 v 开头的标签推送时触发,例如 v1.0.0
workflow_dispatch:
inputs:
version:
description: 'Version number (e.g., 1.0.0)'
required: true
default: 'dev'
create_release:
description: 'Create GitHub Release'
required: false
default: true
type: boolean
jobs:
build-android:
name: Build Android APK
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
id-token: write
issues: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.10.0
run_install: false
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'pnpm'
cache-dependency-path: 'main/manager-mobile/pnpm-lock.yaml'
- name: Extract version from tag or input
id: get_version
run: |
if [[ "$GITHUB_REF" =~ ^refs/tags/v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
# 从标签获取版本号
echo "VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
echo "IS_VERSION=true" >> $GITHUB_ENV
echo "BUILD_TYPE=tag" >> $GITHUB_ENV
echo "CREATE_RELEASE=true" >> $GITHUB_ENV
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
# 手动触发时从输入获取版本号
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
echo "IS_VERSION=${{ github.event.inputs.create_release }}" >> $GITHUB_ENV
echo "BUILD_TYPE=manual" >> $GITHUB_ENV
echo "CREATE_RELEASE=${{ github.event.inputs.create_release }}" >> $GITHUB_ENV
else
# 其他情况使用默认版本
echo "VERSION=latest" >> $GITHUB_ENV
echo "IS_VERSION=false" >> $GITHUB_ENV
echo "BUILD_TYPE=other" >> $GITHUB_ENV
echo "CREATE_RELEASE=false" >> $GITHUB_ENV
fi
echo "Version: ${{ env.VERSION }}"
echo "Is Version: ${{ env.IS_VERSION }}"
echo "Build Type: ${{ env.BUILD_TYPE }}"
echo "Create Release: ${{ env.CREATE_RELEASE }}"
- name: Install dependencies
run: |
cd main/manager-mobile
pnpm install --frozen-lockfile
- name: Build uni-app project
run: |
cd main/manager-mobile
pnpm build:app-android
env:
NODE_ENV: production
- name: Check build output
run: |
cd main/manager-mobile
echo "=== Build output directory structure ==="
find . -name "unpackage" -type d
if [ -d "unpackage" ]; then
echo "=== unpackage directory contents ==="
find unpackage -type f 2>/dev/null || echo "unpackage directory not found"
fi
# 检查dist目录
if [ -d "dist" ]; then
echo "=== dist directory contents ==="
find dist -type f 2>/dev/null
fi
- name: Create build package
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
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.BUILD_TYPE == 'tag' && github.ref || format('v{0}', env.VERSION) }}
release_name: Release ${{ env.VERSION }}
body: |
## What's Changed
### 🚀 New Features
- Mobile app build package included
### 📱 Mobile App
- Build Package: `xiaozhi-mobile-${{ env.VERSION }}.zip`
- Contains uni-app build artifacts for Android
### 🔧 Build Info
- Build Type: ${{ env.BUILD_TYPE }}
- 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
${{ 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
prerelease: ${{ env.BUILD_TYPE == 'manual' }}
- name: Upload Build Package to Release
if: steps.create_release.outputs.upload_url != '' && env.PACKAGE_FOUND == 'true'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: main/manager-mobile/${{ env.PACKAGE_PATH }}
asset_name: xiaozhi-mobile-${{ env.VERSION }}.zip
asset_content_type: application/zip
- name: Upload Build Package as Artifact
if: env.PACKAGE_FOUND == 'true'
uses: actions/upload-artifact@v4
with:
name: mobile-build-${{ env.VERSION }}
path: main/manager-mobile/${{ env.PACKAGE_PATH }}
retention-days: 30
- name: Show build info
run: |
echo "Build completed!"
echo "Version: ${{ env.VERSION }}"
echo "Build Type: ${{ env.BUILD_TYPE }}"
echo "Package found: ${{ env.PACKAGE_FOUND }}"
echo "Create Release: ${{ env.CREATE_RELEASE }}"
if [ "${{ env.PACKAGE_FOUND }}" = "true" ]; then
echo "Package path: ${{ env.PACKAGE_PATH }}"
fi
if [ "${{ env.CREATE_RELEASE }}" = "true" ]; then
echo "✅ Release will be created"
else
echo "️ No Release created (manual build with create_release=false or no version)"
fi