From 4cbaa925935e01b01ad0d88ed753db02831f2ef5 Mon Sep 17 00:00:00 2001 From: liyi Date: Mon, 22 Sep 2025 18:03:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B5=8B=E8=AF=95ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci.yml | 268 +++++----------------------------------- 1 file changed, 34 insertions(+), 234 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 0ec3351a..5620a055 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -1,253 +1,53 @@ -# .gitea/workflows/ci.yml +# .gitea/workflows/flutter-ci.yml +name: Flutter CI - Develop Sky -name: Flutter CI/CD Pipeline - -# 触发条件 +# 触发条件:仅当推送到 develop_sky 分支时 on: push: branches: - develop_sky - - release_sky - - master_sky - - canary_release_sky - - /^feat_[a-zA-Z]+$/ # 注意:Gitea 不支持正则分支名直接写在 YAML 中,需用 if 判断 - tags: - - v* # 匹配 v1.0.0 等 tag - pull_request: - branches: - - develop_sky - - release_sky - - canary_release_sky - - /^feat_[a-zA-Z]+$/ - -# 全局环境变量 -env: - LC_ALL: en_US.UTF-8 - LANG: en_US.UTF-8 - PUB_HOSTED_URL: https://pub.flutter-io.cn - FLUTTER_STORAGE_BASE_URL: https://storage.flutter-io.cn - -# 所有 job 共用的 runner 标签 -defaults: - run: - shell: bash jobs: - # ============ 1. 打印环境信息 ============ - print_env: - name: Print Environment - runs-on: macos,flutter # 必须匹配你 Runner 的 labels - if: | - contains(github.ref, 'develop_sky') || - contains(github.ref, 'release_sky') || - contains(github.ref, 'canary_release_sky') || - startsWith(github.ref, 'refs/heads/feat_') || - startsWith(github.ref, 'refs/tags/v') - steps: - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Set up Ruby - run: | - export PATH="/opt/homebrew/bin:$PATH" - eval "$(rbenv init -)" - rbenv global 2.6.10 - ruby -v - which ruby - gem env - - - name: Print Env - run: | - java --version - printenv | sort - - - name: Set NEXT_VERSION from file - run: | - echo "NEXT_VERSION=$(cat app_new.version)" >> $GITHUB_ENV - if: always() && !cancelled() - - # ============ 2. 生成 Git Tag(仅 master_sky) ============ - generate_git_tag: - name: Generate Git Tag - needs: print_env + build: + name: Build iOS & Android + # 使用你之前配置的标签 runs-on: macos,flutter - if: github.branch == 'master_sky' + steps: + # 1. 检出代码 - name: Checkout Code uses: actions/checkout@v4 - - name: Setup SSH & Generate Tag + # 2. 获取 Flutter 依赖 + - name: Setup Flutter run: | - bash pre_build.sh sky - project_url=$(echo $CI_GITEA_SERVER_URL | sed 's|http://||') - git remote set-url origin git@gitea.example.com:your-namespace/your-repo.git - bash tag_generator.sh generate_tag - - # ============ 3. 生成下一个版本号 ============ - generate_next_version: - name: Generate Next Version - needs: print_env - runs-on: macos,flutter - if: | - contains(github.ref, 'develop_sky') || - contains(github.ref, 'release_sky') || - contains(github.ref, 'canary_release_sky') || - startsWith(github.ref, 'refs/heads/feat_') - steps: - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Generate Version - run: | - bash tag_generator.sh generate_version - id: version_gen - - - name: Save Version for Downstream - run: | - echo "NEXT_VERSION=$(cat app_new.version)" >> $GITHUB_ENV - if: always() - outputs: - next_version: ${{ env.NEXT_VERSION }} - - # ============ 4. 构建 Android ============ - build_android: - name: Build Android APK/AAB - needs: [print_env, generate_next_version] - runs-on: macos,flutter - steps: - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Setup Flutter & Fastlane (Android) - run: | - export PATH="/opt/homebrew/bin:$PATH" - eval "$(rbenv init -)" - rbenv global 2.6.10 - bundle config mirror.https://rubygems.org https://mirrors.aliyun.com/rubygems/ - bundle install --gemfile android/Gemfile --path vendor/bundle_android --quiet - flutter clean + flutter --version flutter pub get - - name: Build Android - run: | - bash android/build.sh + # 3. 运行测试(可选,但推荐) + - name: Run Tests + run: flutter test + # 4. 分析代码(可选) + - name: Analyze Code + run: flutter analyze + + # 5. 构建 iOS IPA + - name: Build iOS (IPA) + run: flutter build ipa --release --export-method ad-hoc + + # 6. 构建 Android APK 和 AAB + - name: Build Android (APK & AAB) + run: | + flutter build apk --release + flutter build appbundle --release + + # 7. 上传所有构建产物 - name: Upload Artifacts uses: actions/upload-artifact@v4 with: - name: android-artifacts - path: build/app/outputs/flutter-apk/ - - # ============ 5. 构建 iOS ============ - build_ios: - name: Build iOS IPA - needs: [print_env, generate_next_version] - runs-on: macos,flutter - steps: - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Setup Flutter & Fastlane (iOS) - run: | - export PATH="/opt/homebrew/bin:$PATH" - eval "$(rbenv init -)" - rbenv global 2.6.10 - bundle config mirror.https://rubygems.org https://mirrors.aliyun.com/rubygems/ - bundle install --gemfile ios/Gemfile --path vendor/bundle_ios --quiet - flutter clean - flutter pub get - - - name: Build iOS - run: | - bash ios/build.sh - - - name: Upload Artifacts - uses: actions/upload-artifact@v4 - with: - name: ios-artifacts - path: build/app/outputs/flutter-ipa/ - - # ============ 6. 发布 Release(仅当打 tag 时) ============ - create_release: - name: Create Release & Upload Assets - needs: [build_android, build_ios] - runs-on: macos,flutter - if: startsWith(github.ref, 'refs/tags/') - steps: - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Download Artifacts - uses: actions/download-artifact@v4 - - - name: Generate Release Description - run: | - bash release_description_generator.sh - cat changelog.md - - - name: Upload to Gitea Package Registry & Create Release - env: - STARLOCK_VERSION: ${{ split(github.ref, '/')[2] }} # 提取 tag 名,如 v1.0.0 -> v1.0.0 - run: | - TAG_NAME="${STARLOCK_VERSION}" - VERSION_PART="${TAG_NAME#v}" # 去掉 v 前缀 - - # 上传到 Gitea 通用包(Generic Package) - curl -f -i \ - -H "Authorization: Bearer $CI_GITEA_TOKEN" \ - --upload-file "starlock-sky-release-${TAG_NAME}.apk" \ - "$CI_GITEA_SERVER_URL/api/packages/$GITHUB_REPOSITORY_OWNER/StarLock/$VERSION_PART/starlock-sky-release-${TAG_NAME}.apk" - - curl -f -i \ - -H "Authorization: Bearer $CI_GITEA_TOKEN" \ - --upload-file "starlock-sky-release-${TAG_NAME}.aab" \ - "$CI_GITEA_SERVER_URL/api/packages/$GITHUB_REPOSITORY_OWNER/StarLock/$VERSION_PART/starlock-sky-release-${TAG_NAME}.aab" - - curl -f -i \ - -H "Authorization: Bearer $CI_GITEA_TOKEN" \ - --upload-file "starlock-sky-release-${TAG_NAME}.ipa" \ - "$CI_GITEA_SERVER_URL/api/packages/$GITHUB_REPOSITORY_OWNER/StarLock/$VERSION_PART/starlock-sky-release-${TAG_NAME}.ipa" - - # 创建 Gitea Release(使用 Gitea API) - RELEASE_NOTES="$(cat changelog.md)" - curl -f -i -X POST \ - -H "Authorization: Bearer $CI_GITEA_TOKEN" \ - -H "Content-Type: application/json" \ - -d '{ - "tag_name": "'"$TAG_NAME"'", - "target_commitish": "'"$GITHUB_SHA"'", - "title": "Release '"$TAG_NAME"'", - "note": '"$(printf '%s' "$RELEASE_NOTES" | jq -R -s '.')"', - "is_draft": false, - "is_prerelease": false - }' \ - "$CI_GITEA_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/releases" - - # ============ 7. 通知 ============ - notify_success: - name: Notify on Success - needs: [create_release, build_android, build_ios] - runs-on: macos,flutter - if: success() - steps: - - run: bash notify.sh success - - notify_failure: - name: Notify on Failure - needs: [build_android, build_ios, create_release] - runs-on: macos,flutter - if: failure() - steps: - - run: bash notify.sh failure - - # ============ 8. 清理 ============ - clean_up: - name: Clean Workspace - runs-on: macos,flutter - needs: [notify_success, notify_failure] - if: always() - steps: - - name: Reset Git - run: | - git reset --hard - git clean -fdx \ No newline at end of file + name: flutter-builds + path: | + build/app/outputs/flutter-apk/ + build/app/outputs/bundle/ + build/ios/ipa/ \ No newline at end of file