mirror of
				https://gitlab.com/foxixus/neomovies_mobile.git
				synced 2025-10-29 02:38:49 +05:00 
			
		
		
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			804253ffcc
			...
			4c58e1b556
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 4c58e1b556 | 
							
								
								
									
										267
									
								
								.gitlab-ci.yml
									
									
									
									
									
								
							
							
						
						
									
										267
									
								
								.gitlab-ci.yml
									
									
									
									
									
								
							| @@ -1,201 +1,202 @@ | |||||||
|  | # GitLab CI/CD Configuration for NeoMovies Mobile | ||||||
|  | # Автоматическая сборка APK и TorrentEngine модуля | ||||||
|  |  | ||||||
| stages: | stages: | ||||||
|   - build |   - build | ||||||
|   - test |   - test | ||||||
|   - deploy |   - deploy | ||||||
|  |  | ||||||
| variables: | variables: | ||||||
|   GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.jvmargs='-Xmx2048m' -Dorg.gradle.parallel=true" |   # Flutter версия | ||||||
|  |   FLUTTER_VERSION: "3.35.5" | ||||||
|  |   # Flutter путь для CI | ||||||
|  |   FLUTTER_ROOT: "/opt/flutter" | ||||||
|  |   # Android SDK (стандартный путь в mingc/android-build-box) | ||||||
|  |   ANDROID_SDK_ROOT: "/opt/android-sdk" | ||||||
|  |   ANDROID_HOME: "/opt/android-sdk" | ||||||
|  |   # Gradle настройки для CI (меньше RAM) | ||||||
|  |   GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.jvmargs='-Xmx1536m -XX:MaxMetaspaceSize=512m' -Dorg.gradle.parallel=true -Dorg.gradle.caching=true" | ||||||
|  |   # Кэш | ||||||
|   GRADLE_USER_HOME: "${CI_PROJECT_DIR}/.gradle" |   GRADLE_USER_HOME: "${CI_PROJECT_DIR}/.gradle" | ||||||
|   PUB_CACHE: "${CI_PROJECT_DIR}/.pub-cache" |   PUB_CACHE: "${CI_PROJECT_DIR}/.pub-cache" | ||||||
|  |  | ||||||
|  | # Кэширование для ускорения сборки | ||||||
| cache: | cache: | ||||||
|   key: ${CI_COMMIT_REF_SLUG} |   key: ${CI_COMMIT_REF_SLUG} | ||||||
|   paths: |   paths: | ||||||
|     - .gradle/ |     - .gradle/ | ||||||
|     - .pub-cache/ |     - .pub-cache/ | ||||||
|     - android/.gradle/ |     - android/.gradle/ | ||||||
|  |     - android/build/ | ||||||
|     - build/ |     - build/ | ||||||
|  |  | ||||||
|  | # ============================================ | ||||||
|  | # Сборка только TorrentEngine модуля | ||||||
|  | # ============================================ | ||||||
| build:torrent-engine: | build:torrent-engine: | ||||||
|   stage: build |   stage: build | ||||||
|   image: mingc/android-build-box:latest |   image: mingc/android-build-box:latest | ||||||
|  |   tags: | ||||||
|  |     - saas-linux-medium-amd64  # GitLab Instance Runner (4GB RAM, 2 cores) | ||||||
|  |   before_script: | ||||||
|  |     - echo "Detecting Android SDK location..." | ||||||
|  |     - export ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT:-${ANDROID_HOME:-/opt/android-sdk}} | ||||||
|  |     - echo "Android SDK: ${ANDROID_SDK_ROOT}" | ||||||
|  |     - echo "Creating local.properties for Flutter..." | ||||||
|  |     - echo "flutter.sdk=${FLUTTER_ROOT}" > android/local.properties | ||||||
|  |     - echo "sdk.dir=${ANDROID_SDK_ROOT}" >> android/local.properties | ||||||
|  |     - cat android/local.properties | ||||||
|   script: |   script: | ||||||
|  |     - echo "Building TorrentEngine library module..." | ||||||
|     - cd android |     - cd android | ||||||
|     - chmod +x gradlew |     # Собираем только модуль torrentengine | ||||||
|     - ./gradlew :torrentengine:assembleRelease --no-daemon --stacktrace |     - ./gradlew :torrentengine:assembleRelease --no-daemon --parallel --build-cache | ||||||
|  |     - ls -lah torrentengine/build/outputs/aar/ | ||||||
|   artifacts: |   artifacts: | ||||||
|  |     name: "torrentengine-${CI_COMMIT_SHORT_SHA}" | ||||||
|     paths: |     paths: | ||||||
|       - android/torrentengine/build/outputs/aar/*.aar |       - android/torrentengine/build/outputs/aar/*.aar | ||||||
|     expire_in: 30 days |     expire_in: 1 week | ||||||
|   rules: |   only: | ||||||
|     - if: $CI_COMMIT_BRANCH == "dev" |     - dev | ||||||
|     - if: $CI_COMMIT_BRANCH == "main" |     - feature/torrent-engine-integration | ||||||
|     - if: $CI_COMMIT_BRANCH =~ /^feature\// |     - merge_requests | ||||||
|     - if: $CI_COMMIT_TAG |   when: on_success | ||||||
|     - if: $CI_PIPELINE_SOURCE == "merge_request_event" |  | ||||||
|  |  | ||||||
|  | # ============================================ | ||||||
|  | # Сборка Debug APK | ||||||
|  | # ============================================ | ||||||
| build:apk-debug: | build:apk-debug: | ||||||
|   stage: build |   stage: build | ||||||
|   image: ghcr.io/cirruslabs/flutter:stable |   image: mingc/android-build-box:latest | ||||||
|   script: |   tags: | ||||||
|  |     - docker | ||||||
|  |   before_script: | ||||||
|  |     - echo "Installing Flutter ${FLUTTER_VERSION}..." | ||||||
|  |     - git clone --depth 1 --branch ${FLUTTER_VERSION} https://github.com/flutter/flutter.git /opt/flutter | ||||||
|  |     - export PATH="/opt/flutter/bin:$PATH" | ||||||
|  |     - flutter --version | ||||||
|  |     - flutter doctor -v | ||||||
|     - flutter pub get |     - flutter pub get | ||||||
|     - flutter build apk --debug |   script: | ||||||
|  |     - echo "Building Debug APK..." | ||||||
|  |     - flutter build apk --debug --target-platform android-arm64 | ||||||
|  |     - ls -lah build/app/outputs/flutter-apk/ | ||||||
|   artifacts: |   artifacts: | ||||||
|  |     name: "neomovies-debug-${CI_COMMIT_SHORT_SHA}" | ||||||
|     paths: |     paths: | ||||||
|       - build/app/outputs/flutter-apk/app-debug.apk |       - build/app/outputs/flutter-apk/app-debug.apk | ||||||
|     expire_in: 1 week |     expire_in: 1 week | ||||||
|   rules: |   only: | ||||||
|     - if: $CI_COMMIT_BRANCH == "dev" |     - dev | ||||||
|     - if: $CI_COMMIT_BRANCH =~ /^feature\// |     - feature/torrent-engine-integration | ||||||
|     - if: $CI_PIPELINE_SOURCE == "merge_request_event" |     - merge_requests | ||||||
|  |   when: on_success | ||||||
|   allow_failure: true |   allow_failure: true | ||||||
|  |  | ||||||
|  | # ============================================ | ||||||
|  | # Сборка Release APK (только для dev) | ||||||
|  | # ============================================ | ||||||
| build:apk-release: | build:apk-release: | ||||||
|   stage: build |   stage: build | ||||||
|   image: ghcr.io/cirruslabs/flutter:stable |   image: mingc/android-build-box:latest | ||||||
|   script: |   tags: | ||||||
|  |     - docker | ||||||
|  |   before_script: | ||||||
|  |     - echo "Installing Flutter ${FLUTTER_VERSION}..." | ||||||
|  |     - git clone --depth 1 --branch ${FLUTTER_VERSION} https://github.com/flutter/flutter.git /opt/flutter | ||||||
|  |     - export PATH="/opt/flutter/bin:$PATH" | ||||||
|  |     - flutter --version | ||||||
|  |     - flutter doctor -v | ||||||
|     - flutter pub get |     - flutter pub get | ||||||
|     - flutter build apk --release --split-per-abi |   script: | ||||||
|  |     - echo "Building Release APK..." | ||||||
|  |     # Сборка с split-per-abi для уменьшения размера | ||||||
|  |     - flutter build apk --release --split-per-abi --target-platform android-arm64 | ||||||
|  |     - ls -lah build/app/outputs/flutter-apk/ | ||||||
|   artifacts: |   artifacts: | ||||||
|  |     name: "neomovies-release-${CI_COMMIT_SHORT_SHA}" | ||||||
|     paths: |     paths: | ||||||
|       - build/app/outputs/flutter-apk/app-arm64-v8a-release.apk |       - build/app/outputs/flutter-apk/app-arm64-v8a-release.apk | ||||||
|       - build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk |  | ||||||
|       - build/app/outputs/flutter-apk/app-x86_64-release.apk |  | ||||||
|     expire_in: 30 days |     expire_in: 30 days | ||||||
|   rules: |   only: | ||||||
|     - if: $CI_COMMIT_BRANCH == "dev" |     - dev | ||||||
|     - if: $CI_COMMIT_BRANCH == "main" |   when: on_success | ||||||
|     - if: $CI_COMMIT_BRANCH =~ /^feature\// |  | ||||||
|     - if: $CI_COMMIT_TAG |  | ||||||
|   allow_failure: true |   allow_failure: true | ||||||
|  |  | ||||||
|  | # ============================================ | ||||||
|  | # Анализ кода Flutter | ||||||
|  | # ============================================ | ||||||
| test:flutter-analyze: | test:flutter-analyze: | ||||||
|   stage: test |   stage: test | ||||||
|   image: ghcr.io/cirruslabs/flutter:stable |   image: mingc/android-build-box:latest | ||||||
|   script: |   tags: | ||||||
|  |     - docker | ||||||
|  |   before_script: | ||||||
|  |     - git clone --depth 1 --branch ${FLUTTER_VERSION} https://github.com/flutter/flutter.git /opt/flutter | ||||||
|  |     - export PATH="/opt/flutter/bin:$PATH" | ||||||
|     - flutter pub get |     - flutter pub get | ||||||
|     - flutter analyze |   script: | ||||||
|   rules: |     - echo "Running Flutter analyze..." | ||||||
|     - if: $CI_COMMIT_BRANCH == "dev" |     - flutter analyze --no-fatal-infos || true | ||||||
|     - if: $CI_PIPELINE_SOURCE == "merge_request_event" |   only: | ||||||
|  |     - dev | ||||||
|  |     - merge_requests | ||||||
|   allow_failure: true |   allow_failure: true | ||||||
|  |  | ||||||
|  | # ============================================ | ||||||
|  | # Kotlin/Android lint | ||||||
|  | # ============================================ | ||||||
| test:android-lint: | test:android-lint: | ||||||
|   stage: test |   stage: test | ||||||
|   image: mingc/android-build-box:latest |   image: mingc/android-build-box:latest | ||||||
|  |   tags: | ||||||
|  |     - docker | ||||||
|  |   before_script: | ||||||
|  |     - echo "Creating local.properties for Flutter..." | ||||||
|  |     - echo "flutter.sdk=${FLUTTER_ROOT}" > android/local.properties | ||||||
|  |     - echo "sdk.dir=${ANDROID_SDK_ROOT}" >> android/local.properties | ||||||
|   script: |   script: | ||||||
|  |     - echo "Running Android Lint..." | ||||||
|     - cd android |     - cd android | ||||||
|     - chmod +x gradlew |     - ./gradlew lint --no-daemon || true | ||||||
|     - ./gradlew lint --no-daemon |  | ||||||
|   artifacts: |   artifacts: | ||||||
|  |     name: "lint-reports-${CI_COMMIT_SHORT_SHA}" | ||||||
|     paths: |     paths: | ||||||
|       - android/app/build/reports/lint-*.html |       - android/app/build/reports/lint-results*.html | ||||||
|       - android/torrentengine/build/reports/lint-*.html |       - android/torrentengine/build/reports/lint-results*.html | ||||||
|     expire_in: 1 week |     expire_in: 1 week | ||||||
|     when: always |   only: | ||||||
|   rules: |     - dev | ||||||
|     - if: $CI_COMMIT_BRANCH == "dev" |     - merge_requests | ||||||
|     - if: $CI_PIPELINE_SOURCE == "merge_request_event" |  | ||||||
|   allow_failure: true |   allow_failure: true | ||||||
|  |  | ||||||
|  | # ============================================ | ||||||
|  | # Deploy к релизам (опционально) | ||||||
|  | # ============================================ | ||||||
| deploy:release: | deploy:release: | ||||||
|   stage: deploy |   stage: deploy | ||||||
|   image: alpine:latest |   image: alpine:latest | ||||||
|   needs: |   tags: | ||||||
|     - build:apk-release |     - docker | ||||||
|     - build:torrent-engine |  | ||||||
|   before_script: |   before_script: | ||||||
|     - apk add --no-cache curl jq |     - apk add --no-cache curl jq | ||||||
|   script: |   script: | ||||||
|  |     - echo "Creating GitLab Release..." | ||||||
|     - | |     - | | ||||||
|       # Определяем версию релиза |       if [ -f "build/app/outputs/flutter-apk/app-arm64-v8a-release.apk" ]; then | ||||||
|       if [ -n "$CI_COMMIT_TAG" ]; then |         echo "Release APK found" | ||||||
|         VERSION="$CI_COMMIT_TAG" |         # Здесь можно добавить публикацию в GitLab Releases или другой deployment | ||||||
|       else |  | ||||||
|         # Автоматическая версия из коммита |  | ||||||
|         VERSION="v0.0.${CI_PIPELINE_ID}" |  | ||||||
|       fi |       fi | ||||||
|  |   only: | ||||||
|  |     - tags | ||||||
|  |   when: manual | ||||||
|  |  | ||||||
|       echo "📦 Creating GitLab Release: $VERSION" | # ============================================ | ||||||
|       echo "📝 Commit: ${CI_COMMIT_SHORT_SHA}" | # Уведомление об успешной сборке | ||||||
|       echo "🔗 Branch: ${CI_COMMIT_BRANCH}" | # ============================================ | ||||||
|        | .notify_success: | ||||||
|       # Проверяем наличие APK файлов |   after_script: | ||||||
|       APK_ARM64="build/app/outputs/flutter-apk/app-arm64-v8a-release.apk" |     - echo "✅ Build completed successfully!" | ||||||
|       APK_ARM32="build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk" |     - echo "📦 Artifacts are available in the pipeline artifacts" | ||||||
|       APK_X86="build/app/outputs/flutter-apk/app-x86_64-release.apk" |     - echo "🔗 Download URL: ${CI_JOB_URL}/artifacts/download" | ||||||
|       AAR_TORRENT="android/torrentengine/build/outputs/aar/torrentengine-release.aar" |  | ||||||
|        |  | ||||||
|       # Создаем описание релиза |  | ||||||
|       RELEASE_DESCRIPTION="## NeoMovies Mobile ${VERSION} |  | ||||||
|        |  | ||||||
|       **Build Info:** |  | ||||||
|       - Commit: \`${CI_COMMIT_SHORT_SHA}\` |  | ||||||
|       - Branch: \`${CI_COMMIT_BRANCH}\` |  | ||||||
|       - Pipeline: [#${CI_PIPELINE_ID}](${CI_PIPELINE_URL}) |  | ||||||
|        |  | ||||||
|       **Downloads:** |  | ||||||
|       " |  | ||||||
|        |  | ||||||
|       # Подсчитываем файлы |  | ||||||
|       FILE_COUNT=0 |  | ||||||
|       [ -f "$APK_ARM64" ] && FILE_COUNT=$((FILE_COUNT+1)) && RELEASE_DESCRIPTION="${RELEASE_DESCRIPTION}\n- ARM64 APK: \`app-arm64-v8a-release.apk\`" |  | ||||||
|       [ -f "$APK_ARM32" ] && FILE_COUNT=$((FILE_COUNT+1)) && RELEASE_DESCRIPTION="${RELEASE_DESCRIPTION}\n- ARM32 APK: \`app-armeabi-v7a-release.apk\`" |  | ||||||
|       [ -f "$APK_X86" ] && FILE_COUNT=$((FILE_COUNT+1)) && RELEASE_DESCRIPTION="${RELEASE_DESCRIPTION}\n- x86_64 APK: \`app-x86_64-release.apk\`" |  | ||||||
|       [ -f "$AAR_TORRENT" ] && FILE_COUNT=$((FILE_COUNT+1)) && RELEASE_DESCRIPTION="${RELEASE_DESCRIPTION}\n- TorrentEngine Library: \`torrentengine-release.aar\`" |  | ||||||
|        |  | ||||||
|       if [ $FILE_COUNT -eq 0 ]; then |  | ||||||
|         echo "❌ No release artifacts found!" |  | ||||||
|         exit 1 |  | ||||||
|       fi |  | ||||||
|        |  | ||||||
|       echo "✅ Found $FILE_COUNT artifact(s) to release" |  | ||||||
|        |  | ||||||
|       # Создаем релиз через GitLab API |  | ||||||
|       RELEASE_PAYLOAD=$(cat <<EOF |  | ||||||
|       { |  | ||||||
|         "name": "NeoMovies ${VERSION}", |  | ||||||
|         "tag_name": "${VERSION}", |  | ||||||
|         "description": "${RELEASE_DESCRIPTION}", |  | ||||||
|         "ref": "${CI_COMMIT_SHA}", |  | ||||||
|         "assets": { |  | ||||||
|           "links": [] |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|       EOF |  | ||||||
|       ) |  | ||||||
|        |  | ||||||
|       echo "🚀 Creating release via GitLab API..." |  | ||||||
|        |  | ||||||
|       RESPONSE=$(curl --fail-with-body -s -X POST \ |  | ||||||
|         "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/releases" \ |  | ||||||
|         --header "PRIVATE-TOKEN: ${CI_JOB_TOKEN}" \ |  | ||||||
|         --header "Content-Type: application/json" \ |  | ||||||
|         --data "${RELEASE_PAYLOAD}" || echo "FAILED") |  | ||||||
|        |  | ||||||
|       if [ "$RESPONSE" = "FAILED" ]; then |  | ||||||
|         echo "⚠️  Release API call failed, trying alternative method..." |  | ||||||
|         # Если релиз уже существует, пробуем обновить |  | ||||||
|         curl -s -X PUT \ |  | ||||||
|           "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/releases/${VERSION}" \ |  | ||||||
|           --header "PRIVATE-TOKEN: ${CI_JOB_TOKEN}" \ |  | ||||||
|           --header "Content-Type: application/json" \ |  | ||||||
|           --data "${RELEASE_PAYLOAD}" |  | ||||||
|       fi |  | ||||||
|        |  | ||||||
|       echo "" |  | ||||||
|       echo "✅ Release created successfully!" |  | ||||||
|       echo "🔗 View release: ${CI_PROJECT_URL}/-/releases/${VERSION}" |  | ||||||
|       echo "📦 Pipeline artifacts: ${CI_JOB_URL}/artifacts/browse" |  | ||||||
|   artifacts: |  | ||||||
|     paths: |  | ||||||
|       - build/app/outputs/flutter-apk/*.apk |  | ||||||
|       - android/torrentengine/build/outputs/aar/*.aar |  | ||||||
|     expire_in: 90 days |  | ||||||
|   rules: |  | ||||||
|     - if: $CI_COMMIT_TAG |  | ||||||
|       when: always |  | ||||||
|     - if: $CI_COMMIT_BRANCH == "dev" |  | ||||||
|       when: on_success |  | ||||||
|     - if: $CI_COMMIT_BRANCH == "main" |  | ||||||
|       when: on_success |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user