Some checks failed
Flutter Build - Sky Develop / 🧮 Determine Version (push) Has been cancelled
Flutter Build - Sky Develop / 📦 Build APK (Develop) (push) Has been cancelled
Flutter Build - Sky Develop / 📦 Build AAB (Develop) (push) Has been cancelled
Flutter Build - Sky Develop / 🍎 Build iOS (Develop) (push) Has been cancelled
Flutter Build - Sky Develop / 🏷️ Create Tag & Notify (push) Has been cancelled
242 lines
9.3 KiB
YAML
242 lines
9.3 KiB
YAML
name: Flutter Build - Sky Develop
|
||
|
||
on:
|
||
push:
|
||
branches:
|
||
- develop_sky
|
||
|
||
jobs:
|
||
# 第一个 job:只负责计算版本号(所有 job 依赖它)
|
||
determine-version:
|
||
name: 🧮 Determine Version
|
||
runs-on: sky
|
||
outputs:
|
||
next_version: ${{ steps.version.outputs.next_version }}
|
||
next_version_full: ${{ steps.version.outputs.next_version_full }}
|
||
build_number: ${{ steps.version.outputs.build_number }}
|
||
steps:
|
||
- name: Checkout Code
|
||
uses: actions/checkout@v4
|
||
with:
|
||
fetch-depth: 0
|
||
|
||
- name: Determine Version
|
||
id: version
|
||
run: |
|
||
# 获取上一次构建成功的tag(匹配vX.X.X_sky格式)
|
||
LAST_TAG=$(git describe --tags --match "v*.*.*_sky" --abbrev=0 2>/dev/null || echo "v1.0.0_sky")
|
||
echo "Last tag found: $LAST_TAG"
|
||
|
||
# 提取基础版本号(去除_sky后缀)
|
||
BASE_VERSION=$(echo "$LAST_TAG" | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | head -1)
|
||
[ -z "$BASE_VERSION" ] && BASE_VERSION="v1.0.0"
|
||
echo "Base version: $BASE_VERSION"
|
||
|
||
# 解析版本号各部分
|
||
MAJOR=$(echo $BASE_VERSION | cut -d'.' -f1 | sed 's/v//')
|
||
MINOR=$(echo $BASE_VERSION | cut -d'.' -f2)
|
||
PATCH=$(echo $BASE_VERSION | cut -d'.' -f3)
|
||
echo "Current version: Major=$MAJOR, Minor=$MINOR, Patch=$PATCH"
|
||
|
||
# 计算不重复的commit消息数量
|
||
COMMIT_COUNT=$(git log --pretty=%B "${LAST_TAG}.." | grep -v '^$' | sort -u | wc -l | tr -d ' ')
|
||
echo "Unique commit messages count: $COMMIT_COUNT"
|
||
|
||
# 计算新的patch版本,并处理进位
|
||
NEW_PATCH=$((PATCH + COMMIT_COUNT))
|
||
NEW_MINOR=$MINOR
|
||
NEW_MAJOR=$MAJOR
|
||
|
||
# 处理第三位版本号进位(超过1000时进位到第二位)
|
||
if [ $NEW_PATCH -ge 1000 ]; then
|
||
NEW_MINOR=$((MINOR + NEW_PATCH / 1000))
|
||
NEW_PATCH=$((NEW_PATCH % 1000))
|
||
echo "Patch overflow detected, new Minor: $NEW_MINOR, new Patch: $NEW_PATCH"
|
||
fi
|
||
|
||
# 处理第二位版本号进位(超过10时进位到第一位)
|
||
if [ $NEW_MINOR -ge 10 ]; then
|
||
NEW_MAJOR=$((MAJOR + NEW_MINOR / 10))
|
||
NEW_MINOR=$((NEW_MINOR % 10))
|
||
echo "Minor overflow detected, new Major: $NEW_MAJOR, new Minor: $NEW_MINOR"
|
||
fi
|
||
|
||
# 生成新版本号
|
||
NEXT_VERSION="v${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
|
||
NEXT_VERSION_FULL="${NEXT_VERSION}_sky_develop" # develop环境标识
|
||
BUILD_NUMBER=$NEW_PATCH
|
||
|
||
echo "Next version: $NEXT_VERSION"
|
||
echo "Next version full: $NEXT_VERSION_FULL"
|
||
echo "Build number: $BUILD_NUMBER"
|
||
|
||
echo "NEXT_VERSION=$NEXT_VERSION" >> $GITEA_ENV
|
||
echo "NEXT_VERSION_FULL=$NEXT_VERSION_FULL" >> $GITEA_ENV
|
||
echo "BUILD_NUMBER=$BUILD_NUMBER" >> $GITEA_ENV
|
||
|
||
# 输出给其他 job 使用
|
||
echo "::set-output name=next_version::$NEXT_VERSION"
|
||
echo "::set-output name=next_version_full::$NEXT_VERSION_FULL"
|
||
echo "::set-output name=build_number::$BUILD_NUMBER"
|
||
|
||
# 并行 Job 1:Android APK (Develop环境)
|
||
build-apk:
|
||
name: 📦 Build APK (Develop)
|
||
needs: determine-version
|
||
runs-on: sky
|
||
steps:
|
||
- name: Checkout Code
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Setup Flutter
|
||
run: flutter pub get
|
||
|
||
- name: Build APK (Develop环境)
|
||
run: |
|
||
flutter build apk \
|
||
--no-tree-shake-icons \
|
||
--flavor sky \
|
||
-t lib/main_sky_dev.dart \
|
||
--build-number=${{ needs.determine-version.outputs.build_number }} \
|
||
--build-name=${{ needs.determine-version.outputs.next_version }} \
|
||
--debug # Develop环境使用debug构建
|
||
|
||
- name: Rename APK with Version
|
||
run: |
|
||
# 重命名APK文件,添加版本号
|
||
OLD_PATH="build/app/outputs/flutter-apk/app-sky_dev-debug.apk"
|
||
NEW_NAME="starlock-sky-${{ needs.determine-version.outputs.next_version_full }}.apk"
|
||
cp "$OLD_PATH" "$NEW_NAME"
|
||
echo "Renamed APK to: $NEW_NAME"
|
||
|
||
- name: Upload APK Artifact
|
||
uses: actions/upload-artifact@v4
|
||
with:
|
||
name: ${{ needs.determine-version.outputs.next_version_full }}-apk
|
||
path: starlock-sky-${{ needs.determine-version.outputs.next_version_full }}.apk
|
||
|
||
# 并行 Job 2:Android AAB (Develop环境)
|
||
build-aab:
|
||
name: 📦 Build AAB (Develop)
|
||
needs: determine-version
|
||
runs-on: sky
|
||
steps:
|
||
- name: Checkout Code
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Setup Flutter
|
||
run: flutter pub get
|
||
|
||
- name: Build App Bundle (Develop环境)
|
||
run: |
|
||
flutter build appbundle \
|
||
--no-tree-shake-icons \
|
||
--flavor sky \
|
||
-t lib/main_sky_dev.dart \
|
||
--build-number=${{ needs.determine-version.outputs.build_number }} \
|
||
--build-name=${{ needs.determine-version.outputs.next_version }} \
|
||
--debug # Develop环境使用debug构建
|
||
|
||
- name: Rename AAB with Version
|
||
run: |
|
||
# 重命名AAB文件,添加版本号
|
||
OLD_PATH="build/app/outputs/bundle/skyDebug/app-sky-debug.aab"
|
||
NEW_NAME="starlock-sky-${{ needs.determine-version.outputs.next_version_full }}.aab"
|
||
cp "$OLD_PATH" "$NEW_NAME"
|
||
echo "Renamed AAB to: $NEW_NAME"
|
||
|
||
- name: Upload AAB Artifact
|
||
uses: actions/upload-artifact@v4
|
||
with:
|
||
name: ${{ needs.determine-version.outputs.next_version_full }}-aab
|
||
path: starlock-sky-${{ needs.determine-version.outputs.next_version_full }}.aab
|
||
|
||
# 并行 Job 3:iOS IPA (Develop环境)
|
||
build-ios:
|
||
name: 🍎 Build iOS (Develop)
|
||
needs: determine-version
|
||
runs-on: macos # 必须使用 macOS runner
|
||
steps:
|
||
- name: Checkout Code
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Setup Flutter
|
||
run: flutter pub get
|
||
|
||
- name: Build iOS (Develop环境)
|
||
run: |
|
||
flutter build ios \
|
||
--no-codesign \
|
||
--flavor sky \
|
||
-t lib/main_sky_dev.dart \
|
||
--build-number=${{ needs.determine-version.outputs.build_number }} \
|
||
--build-name=${{ needs.determine-version.outputs.next_version }} \
|
||
--debug # Develop环境使用debug构建
|
||
|
||
- name: Rename IPA with Version
|
||
run: |
|
||
# 重命名IPA文件,添加版本号
|
||
OLD_PATH="build/ios/iphoneos/Runner.app"
|
||
NEW_NAME="starlock-sky-${{ needs.determine-version.outputs.next_version_full }}.ipa"
|
||
# 对于iOS,需要先打包成IPA
|
||
xcodebuild -exportArchive -archivePath build/ios/archive/Runner.xcarchive \
|
||
-exportOptionsPlist ExportOptions.plist \
|
||
-exportPath build/ios/ipa \
|
||
-allowProvisioningUpdates
|
||
cp "build/ios/ipa/Runner.ipa" "$NEW_NAME"
|
||
echo "Renamed IPA to: $NEW_NAME"
|
||
|
||
- name: Upload IPA Artifact
|
||
uses: actions/upload-artifact@v4
|
||
with:
|
||
name: ${{ needs.determine-version.outputs.next_version_full }}-ipa
|
||
path: starlock-sky-${{ needs.determine-version.outputs.next_version_full }}.ipa
|
||
|
||
# 最后一个 job:汇总、打tag并通知
|
||
publish:
|
||
name: 🏷️ Create Tag & Notify
|
||
needs: [build-apk, build-aab, build-ios]
|
||
runs-on: sky
|
||
if: success()
|
||
steps:
|
||
- name: Checkout Code
|
||
uses: actions/checkout@v4
|
||
with:
|
||
fetch-depth: 0
|
||
|
||
- name: Create and Push New Tag
|
||
run: |
|
||
NEW_TAG=${{ needs.determine-version.outputs.next_version_full }}
|
||
git config user.name "Gitea Runner"
|
||
git config user.email "runner@gitea.local"
|
||
|
||
# 检查tag是否已存在,如果不存在则创建并推送
|
||
if ! git rev-parse "$NEW_TAG" >/dev/null 2>&1; then
|
||
git tag "$NEW_TAG"
|
||
git push origin "$NEW_TAG"
|
||
echo "✅ New tag created and pushed: $NEW_TAG"
|
||
else
|
||
echo "ℹ️ Tag $NEW_TAG already exists, skipping creation"
|
||
fi
|
||
|
||
- name: Notify Build Success
|
||
run: |
|
||
echo "🚀 Build Successful!"
|
||
echo "📦 Generated artifacts:"
|
||
echo " - APK: starlock-sky-${{ needs.determine-version.outputs.next_version_full }}.apk"
|
||
echo " - AAB: starlock-sky-${{ needs.determine-version.outputs.next_version_full }}.aab"
|
||
echo " - IPA: starlock-sky-${{ needs.determine-version.outputs.next_version_full }}.ipa"
|
||
echo "🏷️ New version tag: ${{ needs.determine-version.outputs.next_version_full }}"
|
||
echo "🔢 Version: ${{ needs.determine-version.outputs.next_version }}"
|
||
echo "📊 Build number: ${{ needs.determine-version.outputs.build_number }}"
|
||
|
||
- name: Upload All Artifacts to Gitea
|
||
uses: actions/upload-artifact@v4
|
||
with:
|
||
name: starlock-sky-develop-${{ needs.determine-version.outputs.next_version_full }}
|
||
path: |
|
||
starlock-sky-${{ needs.determine-version.outputs.next_version_full }}.apk
|
||
starlock-sky-${{ needs.determine-version.outputs.next_version_full }}.aab
|
||
starlock-sky-${{ needs.determine-version.outputs.next_version_full }}.ipa
|
||
retention-days: 30
|