修复 artifact 名称:将中文名称改为英文,避免下载 URL 编码错误 #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 🍎 iOS构建(Flutter) | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - main | |
| paths: | |
| - 'lib/**' | |
| - 'pubspec.yaml' | |
| - 'ios/**' | |
| - '.github/workflows/build-ios.yml' | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| build_type: | |
| description: '构建类型' | |
| required: true | |
| default: 'archive' | |
| type: choice | |
| options: | |
| - archive | |
| - ipa | |
| jobs: | |
| # 清理旧的工作流运行和构建产物 | |
| cleanup-old-runs: | |
| name: 🧹 清理旧工作流和构建产物 | |
| runs-on: ubuntu-latest | |
| permissions: | |
| actions: write | |
| contents: read | |
| steps: | |
| - name: 🗑️ 删除旧的工作流运行 | |
| uses: Mattraks/delete-workflow-runs@v2 | |
| with: | |
| token: ${{ github.token }} | |
| repository: ${{ github.repository }} | |
| retain_days: 0 | |
| keep_minimum_runs: 1 | |
| delete_workflow_pattern: '🍎 iOS构建(Flutter)' | |
| - name: 🗑️ 删除旧的构建产物(Artifacts) | |
| run: | | |
| # 安装 jq(如果未安装) | |
| brew install jq || true | |
| # 获取所有未过期的 artifacts | |
| response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/actions/artifacts?per_page=100") | |
| artifacts=$(echo "$response" | jq -r '.artifacts[] | select(.expired == false) | .id' | sort -rn) | |
| total=$(echo "$artifacts" | grep -c . || echo "0") | |
| echo "当前共有 $total 个构建产物" | |
| # 删除每个 artifact(保留最新的3个) | |
| if [ "$total" -gt 3 ]; then | |
| echo "$artifacts" | tail -n +4 | while read artifact; do | |
| if [ -n "$artifact" ] && [ "$artifact" != "null" ]; then | |
| echo "删除 artifact ID: $artifact" | |
| curl -s -X DELETE \ | |
| -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/actions/artifacts/$artifact" | |
| fi | |
| done | |
| echo "已删除旧构建产物(保留最新的3个)" | |
| else | |
| echo "构建产物数量不超过3个,无需删除" | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| continue-on-error: true | |
| # iOS构建 | |
| build-ios: | |
| needs: cleanup-old-runs | |
| name: 🍎 iOS应用构建 | |
| runs-on: macos-latest | |
| steps: | |
| - name: 📥 检出代码 | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: 🎯 设置Flutter环境 | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: '3.38.5' | |
| channel: 'stable' | |
| cache: true | |
| - name: 📌 读取版本号 | |
| id: get_version | |
| run: | | |
| VERSION=$(grep -E '^version:' pubspec.yaml | sed 's/version: //' | sed 's/+.*$//') | |
| echo "APP_VERSION=$VERSION" >> $GITHUB_ENV | |
| echo "版本号: $VERSION" | |
| shell: bash | |
| - name: 📦 获取依赖 | |
| run: flutter pub get | |
| shell: bash | |
| - name: ☕ 安装CocoaPods依赖 | |
| run: | | |
| cd ios | |
| pod install | |
| cd .. | |
| shell: bash | |
| - name: 🔍 验证Flutter环境 | |
| run: flutter doctor -v | |
| shell: bash | |
| - name: 🔨 构建iOS应用(Archive模式 + 代码混淆) | |
| if: github.event.inputs.build_type != 'ipa' | |
| run: | | |
| # 创建调试信息目录 | |
| mkdir -p build/debug-info | |
| # 构建并启用代码混淆 | |
| flutter build ios --release --no-codesign --obfuscate --split-debug-info=build/debug-info | |
| shell: bash | |
| - name: 📦 创建IPA文件(需要签名) | |
| if: github.event.inputs.build_type == 'ipa' && github.event_name == 'release' | |
| run: | | |
| echo "构建IPA需要Apple Developer账号和代码签名" | |
| echo "请在本地使用Xcode进行Archive和导出IPA" | |
| echo "或者配置Apple Developer证书和描述文件到GitHub Secrets" | |
| exit 1 | |
| shell: bash | |
| - name: 📁 准备构建产物 | |
| run: | | |
| BUILD_DIR="build/ios/iphoneos" | |
| if [ -d "$BUILD_DIR" ]; then | |
| echo "构建产物位于: $BUILD_DIR" | |
| ls -la "$BUILD_DIR" | |
| else | |
| echo "构建产物目录不存在" | |
| fi | |
| shell: bash | |
| - name: 📤 上传构建产物(Archive) | |
| if: github.event.inputs.build_type != 'ipa' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: xiaochun-ios-archive-v${{ env.APP_VERSION }} | |
| path: | | |
| build/ios/iphoneos/ | |
| ios/Pods/ | |
| retention-days: 7 | |
| if-no-files-found: warn | |
| - name: 📝 创建构建说明 | |
| run: | | |
| { | |
| echo "# iOS 构建说明" | |
| echo "" | |
| echo "重要提示:" | |
| echo "" | |
| echo "1. GitHub Actions 构建的 iOS 应用无法直接安装到设备,因为需要代码签名" | |
| echo "2. 要创建可安装的 IPA 文件,需要:" | |
| echo " - Apple Developer 账号(99美元/年)" | |
| echo " - 在 Xcode 中配置证书和描述文件" | |
| echo " - 使用 Xcode 进行 Archive 和导出" | |
| echo "" | |
| echo "3. 当前构建产物位于 build/ios/iphoneos/ 目录" | |
| echo " - 这是一个未签名的构建" | |
| echo " - 可以在 Xcode 中打开项目进行签名和导出" | |
| echo "" | |
| echo "4. 本地构建步骤:" | |
| echo " - 打开 ios/Runner.xcworkspace" | |
| echo " - 选择 Product > Archive" | |
| echo " - 在 Organizer 中点击 Distribute App" | |
| echo " - 选择分发方式并导出 IPA" | |
| echo "" | |
| echo "版本: ${{ env.APP_VERSION }}" | |
| echo "构建时间: $(date '+%Y-%m-%d %H:%M:%S')" | |
| } > iOS构建说明.txt | |
| cat iOS构建说明.txt | |
| shell: bash | |
| - name: 📤 上传说明文件 | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ios-readme | |
| path: iOS构建说明.txt | |
| retention-days: 30 |