From 642bc79353a871bfaf339c4480f3b3d2aea0fdaf Mon Sep 17 00:00:00 2001 From: Foxix Date: Sun, 13 Jul 2025 15:11:57 +0300 Subject: [PATCH] fix ci/cd --- .gitlab-ci.yml | 138 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 119 insertions(+), 19 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8c9e2a5..4e71226 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,35 +1,135 @@ -image: ghcr.io/cirruslabs/flutter:beta +stages: + - test + - build + - deploy -stages: [build] +variables: + FLUTTER_VERSION: "3.16.0" + ANDROID_SDK_VERSION: "34" + GRADLE_OPTS: "-Dorg.gradle.daemon=false" +# Кэш для оптимизации сборки cache: - key: $CI_JOB_NAME + key: flutter-cache paths: - - .pub-cache - - build + - .pub-cache/ + - android/.gradle/ + - build/ -# -------------------------------------------------------------------------------- -build_android: - image: ghcr.io/cirruslabs/flutter:beta-android # уже содержит SDK - stage: build - script: +# Тестирование +test: + stage: test + image: cirrusci/flutter:${FLUTTER_VERSION} + before_script: + - flutter --version - flutter pub get - - flutter build apk --release --dart-define=ENV=production + script: + - flutter analyze + - flutter test + artifacts: + reports: + junit: test-results.xml + paths: + - coverage/ + expire_in: 1 week + +# Сборка Android APK +build_android: + stage: build + image: cirrusci/flutter:${FLUTTER_VERSION} + before_script: + - flutter --version + - flutter pub get + script: + - flutter build apk --release + - flutter build appbundle --release artifacts: paths: - build/app/outputs/flutter-apk/app-release.apk - expire_in: 1 week + - build/app/outputs/bundle/release/app-release.aab + expire_in: 1 month + only: + - main + - develop + - tags -# -------------------------------------------------------------------------------- +# Сборка Linux приложения build_linux: stage: build + image: ubuntu:22.04 before_script: - # Cirrus image уже имеет GTK и CMake; добавляем dev-libs для plugins - - apt-get update && apt-get install -y libjsoncpp-dev libsecret-1-dev - script: + - apt-get update -y + - apt-get install -y curl git unzip xz-utils zip libglu1-mesa + - apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev + - apt-get install -y libblkid-dev liblzma-dev + # Установка Flutter + - git clone https://github.com/flutter/flutter.git -b stable --depth 1 + - export PATH="$PATH:`pwd`/flutter/bin" + - flutter --version + - flutter config --enable-linux-desktop - flutter pub get - - flutter build linux --release --dart-define=ENV=production + script: + - flutter build linux --release artifacts: paths: - - build/linux/**/release/bundle - expire_in: 1 week \ No newline at end of file + - build/linux/x64/release/bundle/ + expire_in: 1 month + only: + - main + - develop + - tags + +# Деплой в Google Play (опционально) +deploy_android: + stage: deploy + image: ruby:3.0 + before_script: + - gem install fastlane + script: + - cd android + - fastlane supply --aab ../build/app/outputs/bundle/release/app-release.aab + dependencies: + - build_android + only: + - tags + when: manual + +# Деплой Linux приложения в GitLab Package Registry +deploy_linux: + stage: deploy + image: ubuntu:22.04 + before_script: + - apt-get update -y + - apt-get install -y curl zip + script: + - cd build/linux/x64/release/bundle + - zip -r ../../../../../${CI_PROJECT_NAME}-linux-${CI_COMMIT_TAG}.zip . + - cd ../../../../../ + - | + curl --header "JOB-TOKEN: $CI_JOB_TOKEN" \ + --upload-file ${CI_PROJECT_NAME}-linux-${CI_COMMIT_TAG}.zip \ + "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${CI_COMMIT_TAG}/${CI_PROJECT_NAME}-linux-${CI_COMMIT_TAG}.zip" + dependencies: + - build_linux + only: + - tags + when: manual + +# Релиз на GitLab +release: + stage: deploy + image: registry.gitlab.com/gitlab-org/release-cli:latest + script: + - | + release-cli create \ + --name "Release $CI_COMMIT_TAG" \ + --tag-name $CI_COMMIT_TAG \ + --description "Release $CI_COMMIT_TAG" \ + --assets-link "{\"name\":\"Android APK\",\"url\":\"${CI_PROJECT_URL}/-/jobs/artifacts/$CI_COMMIT_TAG/download?job=build_android\"}" \ + --assets-link "{\"name\":\"Linux App\",\"url\":\"${CI_PROJECT_URL}/-/jobs/artifacts/$CI_COMMIT_TAG/download?job=build_linux\"}" + dependencies: + - build_android + - build_linux + only: + - tags + when: manual \ No newline at end of file