Skip to content
代码片段 群组 项目
.gitlab-ci.yml 2.9 KB
Newer Older
image: $CI_REGISTRY_IMAGE/flutter:1.1.0
stages:
  ANDROID_APK_PATH: build/app/outputs/apk/debug/
Zhou YANG's avatar
Zhou YANG 已提交
  PUB_HOSTED_URL: https://pub.flutter-io.cn
  FLUTTER_STORAGE_BASE_URL: https://storage.flutter-io.cn
  before_script:
    - flutter pub get

code_quality:
Zhou YANG's avatar
Zhou YANG 已提交
  stage: build
  script:
    - flutter analyze --no-fatal-infos
    - dart pub global activate flutter_analyze_reporter
    - dart pub global run flutter_analyze_reporter --output=gl-code-quality-report.json --reporter=gitlab
  artifacts:
    reports:
      codequality: gl-code-quality-report.json
Zhou YANG's avatar
Zhou YANG 已提交
unit_test:
  stage: build
  script:
    - flutter test --coverage --dart-define=REQUEST_ENV=test
    - lcov -r coverage/lcov.info '*/__test*__/*' -o coverage/lcov_cleaned.info
    - genhtml coverage/lcov_cleaned.info --output=coverage
  coverage: '/lines\.*: \d+\.\d+\%/'
  artifacts:
    name: "test-coverage-report-$CI_COMMIT_SHORT_SHA"
    paths:
      - coverage
    expire_in: 5 days

build_android:
  script:
    - VERSION_NAME=$(cat pubspec.yaml | grep version | head -1 | awk '{print $2}' | awk -F+ '{print $1}')
    - VERSION_CODE=$(cat pubspec.yaml | grep version | head -1 | awk '{print $2}' | awk -F+ '{print $1}')
    - VERSION_CODE_NEW=$(date +%s)
    - VERSION_NEW=$VERSION_NAME+$VERSION_CODE_NEW
    - 'sed -i "s/version:.*/version: $VERSION_NEW/g" pubspec.yaml'
    - 'sed -i "s/\"versionCode\":.*/\"versionCode\": $VERSION_CODE_NEW,/g" updater.json'
    - 'sed -i "s/\"versionName\":.*/\"versionName\": \"$VERSION_NAME\",/g" updater.json'
    - echo $TEST_STORE_FILE | base64 -d > test-keystore.jks
    - flutter build apk --debug -v --dart-define=REQUEST_ENV=prod_env --dart-define=KEY_ALIAS=$TEST_KEY_ALIAS --dart-define=KEY_PASSWORD=$TEST_KEY_PASSWORD --dart-define=STORE_FILE=$(pwd)/test-keystore.jks --dart-define=STORE_PASSWORD=$TEST_STORE_PASSWORD --dart-define=ANDROID_BUILD_TYPE=debug
    - echo "VERSION_NAME=$VERSION_NAME" >> build.env
    name: "android-apk"
      - ${ANDROID_APK_PATH}
      - updater.json
      dotenv: build.env
upload_apk:
  environment: production
Zhou YANG's avatar
Zhou YANG 已提交
  needs: ["build_android"]
  image: rancher/curlimages-curl:7.73.0
  before_script:
    - ''
    - echo $VERSION_NAME
    - APK_FILENAME=$(basename build/app/outputs/apk/debug/*.apk)
    - echo $APK_FILENAME
    - APK_URL_PATH="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/jihu-gitlab-app/${VERSION_NAME}/"
    - echo $APK_URL_PATH
    - 'curl -i --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file ${ANDROID_APK_PATH}/${APK_FILENAME} "${APK_URL_PATH}"'
    - APK_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/jihu-gitlab-app/${VERSION_NAME}/${APK_FILENAME}"
    - echo $APK_URL
    - 'sed -i "s#\"url\":.*#\"url\": \"$APK_URL\"#g" updater.json'
    - 'curl -i --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file updater.json "${APK_URL_PATH}"'