.gitlab-ci.yml 5.31 KB
Newer Older
1
2
3
4
stages:
  - test
  - deploy

proletarius101's avatar
proletarius101 committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
.base:
  image: registry.gitlab.com/fdroid/ci-images-client:latest
  before_script:
    - export GRADLE_USER_HOME=$PWD/.gradle
    - export ANDROID_COMPILE_SDK=`sed -n 's,.*compileSdkVersion\s*\([0-9][0-9]*\).*,\1,p' app/build.gradle`
    - alias sdkmanager="sdkmanager --no_https"
    - echo y | sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" > /dev/null
    # limit RAM usage for all gradle runs
    - export maxmem=$(expr $(sed -n 's,^MemAvailable:[^0-9]*\([0-9][0-9]*\)[^0-9]*$,\1,p' /proc/meminfo) / 1024 / 2 / 1024 \* 1024)
    - printf '\norg.gradle.jvmargs=-Xmx${maxmem}m -XX:MaxPermSize=${maxmem}m\norg.gradle.daemon=false\norg.gradle.parallel=false\n' >> local.properties
  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/
  cache:
    paths:
      - .gradle/wrapper
      - .gradle/caches
23

24
.test-template: &test-template
proletarius101's avatar
proletarius101 committed
25
  extends: .base
26
  stage: test
27
28
29
  artifacts:
    name: "${CI_PROJECT_PATH}_${CI_JOB_STAGE}_${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHA}"
    paths:
30
      - kernel.log
31
      - logcat.txt
32
33
      - app/core*
      - app/*.log
34
35
36
37
38
39
40
41
      - 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"

42
43
# Run the most important first. Then we can decide whether to ignore
# the style tests if the rest of the more meaningful tests pass.
44
test_lint_pmd_checkstyle:
45
  <<: *test-template
46
  script:
47
    - export EXITVALUE=0
48
    - function set_error() { export EXITVALUE=1; printf "\x1b[31mERROR `history|tail -2|head -1|cut -b 6-500`\x1b[0m\n"; }
49
    - ./gradlew assemble
50
    # always report on lint errors to the build log
51
    - sed -i -e 's,textReport .*,textReport true,' app/build.gradle
52
    - ./gradlew testFullDebugUnitTest || set_error
53
54
55
56
57
58
    - ./gradlew lint || set_error
    - ./gradlew pmd || set_error
    - ./gradlew checkstyle || set_error
    - ./tools/check-format-strings.py || set_error
    - ./tools/check-fastlane-whitespace.py || set_error
    - ./tools/remove-unused-and-blank-translations.py || set_error
59
    - echo "These are unused or blank translations that should be removed:"
60
    - git --no-pager diff --ignore-all-space --name-only --exit-code app/src/*/res/values*/strings.xml || set_error
61
    - exit $EXITVALUE
62

63
errorprone:
proletarius101's avatar
proletarius101 committed
64
  extends: .base
65
66
  stage: test
  script:
67
68
69
70
    - apt-get update
    - apt-get install -t stretch-backports openjdk-11-jdk-headless
    - update-java-alternatives --set java-1.11.0-openjdk-amd64
    - export JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
71
    - cat config/errorprone.gradle >> app/build.gradle
72
    - ./gradlew -Dorg.gradle.dependency.verification=lenient assembleDebug
73

74
75
76
77
# Run the tests in the emulator.  Each step is broken out to run on
# its own since the CI runner can have limited RAM, and the emulator
# can take a while to start.
#
78
79
# once these prove stable, the task should be switched to
# connectedCheck to test all the build flavors
80
.connected-template: &connected-template
proletarius101's avatar
proletarius101 committed
81
  extends: .base
82
  script:
83
    - ./gradlew assembleFullDebug
84
85
86
87
88
    - 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
89

90
    - alias sdkmanager
91
    - ls -l ~/.android
92
93
94

    - adb start-server
    - start-emulator
95
    - wait-for-emulator
96
    - adb devices
97
    - adb shell input keyevent 82 &
98
99
    - ./gradlew installFullDebug
    - adb shell am start -n org.fdroid.fdroid.debug/org.fdroid.fdroid.views.main.MainActivity
100
    - if [ $AVD_SDK -lt 25 ] || ! emulator -accel-check; then
101
          export FLAG=-Pandroid.testInstrumentationRunnerArguments.notAnnotation=androidx.test.filters.LargeTest;
102
      fi
103
    - ./gradlew connectedFullDebugAndroidTest $FLAG
104

105
no-accel 22 default x86:
106
107
108
  <<: *test-template
  <<: *connected-template

109
110
111
112
.kvm-template: &kvm-template
  tags:
    - fdroid
    - kvm
113
114
115
  only:
    variables:
      - $RUN_KVM_JOBS
116
117
118
  <<: *test-template
  <<: *connected-template

119
kvm 29 microg x86_64:
120
121
  <<: *kvm-template

122
deploy_nightly:
proletarius101's avatar
proletarius101 committed
123
  extends: .base
124
125
126
127
  stage: deploy
  only:
    - master
  script:
128
    - test -z "$DEBUG_KEYSTORE" && exit 0
129
130
131
132
    - 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
133
134
135
136
    - 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
137
138
139
    - 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
140
    # build the APKs!
141
142
    - ./gradlew assembleDebug
    - fdroid nightly -v