From a8cc945d61bb64176a6b72821d19269267658801 Mon Sep 17 00:00:00 2001 From: liyi Date: Mon, 22 Sep 2025 17:46:41 +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 | 262 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 248 insertions(+), 14 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index f78b7449..0ec3351a 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -1,19 +1,253 @@ -name: Gitea Actions Demo -run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 -on: [push] +# .gitea/workflows/ci.yml + +name: Flutter CI/CD Pipeline + +# 触发条件 +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: - Explore-Gitea-Actions: - runs-on: flutter + # ============ 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: - - run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!" - - run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." - - name: Check out repository code + - name: Checkout Code uses: actions/checkout@v4 - - run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - - name: List files in the repository + + - name: Set up Ruby run: | - ls ${{ gitea.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." \ No newline at end of file + 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 + runs-on: macos,flutter + if: github.branch == 'master_sky' + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Setup SSH & Generate Tag + 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 pub get + + - name: Build Android + run: | + bash android/build.sh + + - 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