Commit f95ca07e authored by Eric Eastwood's avatar Eric Eastwood
Browse files

Add GitLab CI build/tests

parent f9bd0c83
Pipeline #27297944 passed with stages
in 7 minutes and 35 seconds
image: openjdk:8-jdk
variables:
# Just matched `app/build.gradle`
ANDROID_COMPILE_SDK: "24"
# Just matched `app/build.gradle`
ANDROID_BUILD_TOOLS: "27.0.3"
# Version from https://developer.android.com/studio/releases/sdk-tools
ANDROID_SDK_TOOLS: "24.4.1"
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.tgz https://dl.google.com/android/android-sdk_r${ANDROID_SDK_TOOLS}-linux.tgz
- tar --extract --gzip --file=android-sdk.tgz
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_COMPILE_SDK}
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter platform-tools
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter build-tools-${ANDROID_BUILD_TOOLS}
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew
stages:
- build
- test
build:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
unitTests:
stage: test
script:
- ./gradlew test
# This can't be enabled because `ERROR: x86 emulation currently requires hardware acceleration!`, https://gitlab.com/gitlab-org/gitlab-runner/issues/2242
#
# functionalTests:
# stage: test
# script:
# - wget --quiet --output-document=android-wait-for-emulator https://raw.githubusercontent.com/travis-ci/travis-cookbooks/0f497eb71291b52a703143c5cd63a217c8766dc9/community-cookbooks/android-sdk/files/default/android-wait-for-emulator
# - chmod +x android-wait-for-emulator
# - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter sys-img-x86-google_apis-${ANDROID_COMPILE_SDK}
# - echo no | android-sdk-linux/tools/android create avd -n test -t android-${ANDROID_COMPILE_SDK} --abi google_apis/x86
# - android-sdk-linux/tools/emulator64-x86 -avd test -no-window -no-audio &
# - ./android-wait-for-emulator
# - adb shell input keyevent 82
# - ./gradlew cAT
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="5">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
......
apply plugin: 'com.android.application'
def secretsPropertiesFile = rootProject.file("secrets.properties");
// Try reading secrets from file
def secretsPropertiesFile = rootProject.file("secrets.properties")
def secretProperties = new Properties()
secretProperties.load(new FileInputStream(secretsPropertiesFile))
if (secretsPropertiesFile.exists()) {
secretProperties.load(new FileInputStream(secretsPropertiesFile))
}
// Otherwise read from environment variables, this happens in CI
else {
secretProperties.setProperty("oauth_client_id", System.getenv('oauth_client_id'))
secretProperties.setProperty("oauth_client_secret", System.getenv('oauth_client_secret'))
secretProperties.setProperty("oauth_redirect_uri", System.getenv('oauth_redirect_uri'))
secretProperties.setProperty("google_project_id", System.getenv('google_project_id') ?: "null")
}
android {
compileSdkVersion 24
......@@ -15,10 +25,10 @@ android {
versionCode 81
versionName "3.2.0"
buildConfigField("String", "oauth_client_id", secretProperties['oauth_client_id'])
buildConfigField("String", "oauth_client_secret", secretProperties['oauth_client_secret'])
buildConfigField("String", "oauth_redirect_uri", secretProperties['oauth_redirect_uri'])
buildConfigField("String", "google_project_id", secretProperties['google_project_id'] ?: "null")
buildConfigField("String", "oauth_client_id", "\"${secretProperties['oauth_client_id']}\"")
  • @MadLittleMods I just started diving into Gitter here! The character escaping here generates double quoted strings in the generated file app/build/generated/source/buildConfig/debug/im/gitter/gitter/BuildConfig.java like the following:

    public static final String google_project_id = ""null"";
    ...
    ...
    public static final String oauth_redirect_uri = ""https://gitter.im/login/oauth/callback"";

    It think it's safe to change this to the following. What do you think?

    buildConfigField("String", "oauth_client_id", "${secretProperties['oauth_client_id']}")
    ...
    Edited by George Tsiolis
  • @gtsiolis From my experience, the double quotes were needed as it literally puts the value in quotes into the build config file output.

    You can see an example here,

  • @MadLittleMods but generating the BuildConfig.java as the following won't allow the app to build successfully. Maybe there's a another way around this, but I could be wrong.

    public static final String google_project_id = ""null"";
    public static final String oauth_client_id = ""xxx"";
    public static final String oauth_client_secret = ""..."";
    public static final String oauth_redirect_uri = ""https://gitter.im/login/oauth/callback"";
  • @gtsiolis My app/build/generated/source/buildConfig/debug/im/gitter/gitter/BuildConfig.java looks the same and I am seeing the syntax errors.

    Have you tested it in CI? Copy oauth_client_id, oauth_client_secret, oauth_redirect_uri into your project settings -> CI / CD -> Variables to get the build going

    Currently the build is green and working AFAICT 🤔

    Edited by Eric Eastwood
  • Sorry for responding late @MadLittleMods, I see exactly the same syntax errors but the build is failing locally. Indeed, pipeline passes when using the variables, but this should also build successfully locally to allow deployment on a device, right?

  • @gtsiolis Your changes build locally but fail in CI, ex. https://gitlab.com/gitlab-org/gitter/gitter-android-app/-/jobs/106224296

    But perhaps we could just concat the necessary quotes where we set the properties from the environment variables, https://gitlab.com/gitlab-org/gitter/gitter-android-app/commit/9265e39bd3ecd7ac78ae517005dd2a861727dcd6. I went with this for now 💪

  • @MadLittleMods the pipeline you linked to is running on the master on my fork. The pipeline for these changes running on the branch on my fork is passing and the changes build locally. However, the pipeline on the master now (including 9265e39b) on my fork is passing and changes build locally, too!

  • 9265e39b passes because I amended the commit with the changes I mentioned.

    You're totally right. Thanks again for making this clear @MadLittleMods!

Please register or sign in to reply
buildConfigField("String", "oauth_client_secret", "\"${secretProperties['oauth_client_secret']}\"")
buildConfigField("String", "oauth_redirect_uri", "\"${secretProperties['oauth_redirect_uri']}\"")
buildConfigField("String", "google_project_id", "\"${secretProperties['google_project_id']}\"" ?: "null")
}
buildTypes {
release {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment