.gitlab-ci.yml 4.28 KB
Newer Older
1
image: registry.gitlab.com/fdroid/ci-images-client:latest
Daniel Martí's avatar
Daniel Martí committed
2

3 4 5 6 7
cache:
  paths:
    - .gradle/wrapper
    - .gradle/caches

8 9 10 11
stages:
  - test
  - deploy

12 13
before_script:
  - export GRADLE_USER_HOME=$PWD/.gradle
14
  - export ANDROID_COMPILE_SDK=`sed -n 's,.*compileSdkVersion\s*\([0-9][0-9]*\).*,\1,p' app/build.gradle`
15
  - echo y | sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" > /dev/null
16

17
.test-template: &test-template
18
  stage: test
19 20 21 22 23 24 25 26 27 28 29 30
  artifacts:
    name: "${CI_PROJECT_PATH}_${CI_JOB_STAGE}_${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHA}"
    paths:
      - logcat.txt
      - app/build/reports
      - app/build/outputs/*ml
      - app/build/outputs/apk
    expire_in: 1 week
    when: on_failure
  after_script:
    - echo "Download debug artifacts from https://gitlab.com/${CI_PROJECT_PATH}/-/jobs"

31 32
# Run the most important first. Then we can decide whether to ignore
# the style tests if the rest of the more meaningful tests pass.
33
test_lint_pmd_checkstyle:
34
  <<: *test-template
35
  script:
36
    - export EXITVALUE=0
37
    - ./gradlew assemble
38
    # always report on lint errors to the build log
39
    - sed -i -e 's,textReport .*,textReport true,' app/build.gradle
40
    - ./gradlew testFullDebugUnitTest
41
    - ./gradlew lint
42 43
    - ./gradlew pmd || export EXITVALUE=1
    - ./gradlew checkstyle || export EXITVALUE=1
44 45
    - ./tools/check-format-strings.py || export EXITVALUE=1
    - ./tools/remove-unused-and-blank-translations.py || export EXITVALUE=1
46
    - echo "These are unused or blank translations that should be removed:"
47
    - git --no-pager diff --ignore-all-space --name-only --exit-code app/src/*/res/values*/strings.xml || export EXITVALUE=1
48
    - exit $EXITVALUE
49

50 51 52 53 54 55 56
errorprone:
  stage: test
  script:
    - cat config/errorprone.gradle >> app/build.gradle
    - ./gradlew assembleDebug
  allow_failure: true

57 58
# once these prove stable, the task should be switched to
# connectedCheck to test all the build flavors
59
.connected-template: &connected-template
60
  script:
61
    - ./gradlew assembleDebug
62 63 64 65
    - echo y | sdkmanager "platforms;android-$AVD_SDK" > /dev/null
    - if ! avdmanager list avd | grep "Name. avd$AVD_SDK$"; then
          rm -rf ~/.android/avd  $ANDROID_HOME/system-images;
          echo y | sdkmanager "$AVD_PACKAGE" > /dev/null;
66 67 68 69
          echo no | avdmanager create avd --name avd$AVD_SDK --tag "$AVD_TAG" --package "$AVD_PACKAGE" --sdcard 64M --device "Nexus 5";
          export RAMSIZE="$((`sed -n 's,^MemAvailable:[^0-9]*\([0-9][0-9]*\)[^0-9]*$,\1,p' /proc/meminfo` * 3 / 4 / 1024))";
          sed -i '/^hw\.ramSize\s*=.*/d' ~/.android/avd/*.avd/config.ini;
          echo "hw.ramSize=$RAMSIZE" >> ~/.android/avd/*.avd/config.ini;
70 71 72 73
          avdmanager list avd;
      fi
    - emulator64-arm -avd avd$AVD_SDK -no-audio -no-window -no-snapstorage &
    - wait-for-emulator
74
    - adb shell input keyevent 82 &
75
    - ./gradlew connectedFullDebugAndroidTest || (adb -e logcat -d > logcat.txt; exit 1)
76

77
connected24:
78
  retry: 1
79
  <<: *test-template
80
  variables:
81
    AVD_SDK: "24"
82 83 84 85
    AVD_TAG: "default"
    AVD_PACKAGE: "system-images;android-${AVD_SDK};${AVD_TAG};armeabi-v7a"
  <<: *connected-template

86 87 88 89 90
deploy_nightly:
  stage: deploy
  only:
    - master
  script:
91
    - test -z "$DEBUG_KEYSTORE" && exit 0
92 93 94 95
    - sed -i
        's,<string name="app_name">.*</string>,<string name="app_name">F-Nightly</string>,'
        app/src/main/res/values*/strings.xml
    # add this nightly repo as a enabled repo
96 97 98 99
    - sed -i -e '/<\/string-array>/d' -e '/<\/resources>/d' app/src/main/res/values/default_repos.xml
    - echo "<item>${CI_PROJECT_PATH}-nightly</item>" >> app/src/main/res/values/default_repos.xml
    - echo "<item>${CI_PROJECT_URL}-nightly/raw/master/fdroid/repo</item>" >> app/src/main/res/values/default_repos.xml
    - cat config/nightly-repo/repo.xml >> app/src/main/res/values/default_repos.xml
100 101 102
    - export DB=`sed -n 's,.*DB_VERSION *= *\([0-9][0-9]*\).*,\1,p' app/src/main/java/org/fdroid/fdroid/data/DBHelper.java`
    - export versionCode=`printf '%d%05d' $DB $(date '+%s'| cut -b4-8)`
    - sed -i "s,^\(\s*versionCode\)  *[0-9].*,\1 $versionCode," app/build.gradle
103
    # build the APKs!
104 105
    - ./gradlew assembleDebug
    - fdroid nightly -v
106

107 108 109 110
after_script:
    # this file changes every time but should not be cached
    - rm -f $GRADLE_USER_HOME/caches/modules-2/modules-2.lock
    - rm -fr $GRADLE_USER_HOME/caches/*/plugin-resolution/