.gitlab-ci.yml 6.54 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
  - alias sdkmanager="sdkmanager --no_https"
16
  - echo y | sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" > /dev/null
17

18
.test-template: &test-template
19
  stage: test
20 21 22 23 24 25 26 27 28 29 30 31
  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"

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

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

58 59
# once these prove stable, the task should be switched to
# connectedCheck to test all the build flavors
60
.connected-template: &connected-template
61
  script:
62
    - ./gradlew assembleFullDebug
63 64 65 66 67
    - export AVD_SDK=`echo $CI_JOB_NAME | awk '{print $2}'`
    - export AVD_TAG=`echo $CI_JOB_NAME | awk '{print $3}'`
    - export AVD_ARCH=`echo $CI_JOB_NAME | awk '{print $4}'`
    - export AVD_PACKAGE="system-images;android-${AVD_SDK};${AVD_TAG};${AVD_ARCH}"
    - echo $AVD_PACKAGE
68
    - emulator -accel-check || true
69

70 71
    # Use bleeding edge for Q, or download proven emulator version, based on
    # https://aur.archlinux.org/android-emulator.git
72 73
    - if [[ "$AVD_SDK" == Q ]]; then
          set -x; echo y | sdkmanager --channel=3 "emulator" > /dev/null; set +x;
74 75 76 77 78 79 80
      else
          set -x;
          rm -rf $ANDROID_HOME/emulator;
          wget -q http://dl.google.com/android/repository/emulator-linux-5264690.zip;
          echo "48c1cda2bdf3095d9d9d5c010fbfb3d6d673e3ea  emulator-linux-5264690.zip" | sha1sum -c;
          unzip -qq -d $ANDROID_HOME emulator-linux-5264690.zip;
          set +x;
81
      fi
82 83
    - grep -v '^License' $ANDROID_HOME/tools/source.properties
                         $ANDROID_HOME/emulator/source.properties
84

85
    - alias sdkmanager
86
    - echo y | sdkmanager "platforms;android-$AVD_SDK" > /dev/null
87
    - if ! avdmanager list avd | grep "Name. avd$AVD_SDK$"; then
88
          set -x;
89 90
          rm -rf ~/.android/avd  $ANDROID_HOME/system-images;
          echo y | sdkmanager "$AVD_PACKAGE" > /dev/null;
91
          echo no | avdmanager create avd --name avd$AVD_SDK --tag "$AVD_TAG" --package "$AVD_PACKAGE" --sdcard 64M --device "Nexus 5";
92 93
          export RAMSIZE="`sed -n 's,^MemAvailable:[^0-9]*\([0-9][0-9]*\)[^0-9]*$,\1,p' /proc/meminfo`";
          if [ $RAMSIZE -le 2048 ]; then
94
              sed -i '/^hw\.ramSize\s*=.*/d' ~/.android/avd/*.avd/config.ini;
95
              echo "hw.ramSize=1024" >> ~/.android/avd/*.avd/config.ini;
96
          fi;
97
          avdmanager list avd;
98
          set +x;
99
      fi
100
    - grep -v '^License' $ANDROID_HOME/system-images/android-$AVD_SDK/$AVD_TAG/$AVD_ARCH/source.properties
101 102
    - adb start-server
    - ls -l ~/.android
103
    - emulator -version
104 105 106 107 108 109 110 111
    - emulator -avd avd$AVD_SDK
        -no-audio
        -no-jni
        -no-snapstorage
        -no-window
        -skip-adb-auth
        -verbose
        -wipe-data
112
        -debug all,-hw_control,-qemud,-sensors,-surface
113
        &
114
    - wait-for-emulator
115
    - adb devices
116
    - adb shell input keyevent 82 &
117
    - test $AVD_SDK -ge 25 || export FLAG=-Pandroid.testInstrumentationRunnerArguments.notAnnotation=android.support.test.filters.LargeTest
118 119 120 121
    - ./gradlew connectedFullDebugAndroidTest $FLAG
      || ./gradlew connectedFullDebugAndroidTest $FLAG
      || ./gradlew connectedFullDebugAndroidTest $FLAG
      || (adb -e logcat -d > logcat.txt; exit 1)
122

123
connected 22 default armeabi-v7a:
124
  retry: 1
125 126 127
  <<: *test-template
  <<: *connected-template

128 129 130 131
.kvm-template: &kvm-template
  tags:
    - fdroid
    - kvm
132
  allow_failure: true
133
  only:
134
    - branches@eighthave/fdroidclient
135 136 137
  <<: *test-template
  <<: *connected-template

138
connected 23 default x86:
139 140 141 142 143 144 145
  <<: *kvm-template

connected 25 default x86:
  <<: *kvm-template

connected 26 google_apis x86:
  <<: *kvm-template
146 147 148
  only:
    - branches@fdroid/fdroidclient
    - branches@eighthave/fdroidclient
149 150 151 152 153 154 155

connected 27 google_apis_playstore x86:
  <<: *kvm-template

connected 28 default x86_64:
  <<: *kvm-template

156 157 158
connected Q default x86_64:
  <<: *kvm-template

159

160
deploy_nightly:
161 162 163 164
  stage: deploy
  only:
    - master
  script:
165
    - test -z "$DEBUG_KEYSTORE" && exit 0
166 167 168 169
    - 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
170 171 172 173
    - 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
174 175 176
    - 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
177
    # build the APKs!
178 179
    - ./gradlew assembleDebug
    - fdroid nightly -v
180

181 182 183 184
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/