Navigation Menu

Skip to content
This repository has been archived by the owner on Feb 17, 2020. It is now read-only.

Set up workflows for CircleCI #586

Merged
merged 1 commit into from Aug 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/ci-scripts/ci-mock-google-services-setup.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

export APP_MODULE_PATH="app"
export APP_MODULE_PATH="workspace/repo/app"
export JSON_PATH="$APP_MODULE_PATH/google-services.json"

if [ ! -e ${JSON_PATH} ]; then
Expand Down
44 changes: 44 additions & 0 deletions .circleci/ci-scripts/circle-ci-android-setup.sh
@@ -0,0 +1,44 @@
#!/usr/bin/bash
set -e

function download() {
if hash curl 2>/dev/null; then
curl -s -L -o "$2" "$1"
elif hash wget 2>/dev/null; then
wget -O "$2" "$1"
else
echo >&2 "No supported download tool installed. Please get either wget or curl."
exit
fi
}

function installsdk() {
# We need an existing SDK with `sdkmanager`, otherwise, install it.
which sdkmanager &> /dev/null || getAndroidSDK

PROXY_ARGS=""
if [[ ! -z "$HTTPS_PROXY" ]]; then
PROXY_HOST="$(echo "$HTTPS_PROXY" | cut -d : -f 1,1)"
PROXY_PORT="$(echo "$HTTPS_PROXY" | cut -d : -f 2,2)"
PROXY_ARGS="--proxy=http --proxy_host=$PROXY_HOST --proxy_port=$PROXY_PORT"
fi

echo y | "$ANDROID_HOME/tools/bin/sdkmanager" $PROXY_ARGS "$@"
}

function getAndroidSDK {
TMP=/tmp/sdk$$.zip
download 'https://dl.google.com/android/repository/tools_r25.2.3-linux.zip' $TMP
unzip -qod "$ANDROID_SDK" $TMP
rm $TMP
}

function installAndroidSDK {
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$PATH"

mkdir -p "$ANDROID_HOME/licenses/"
echo > "$ANDROID_HOME/licenses/android-sdk-license"
echo -n d56f5187479451eabf01fb78af6dfcb131a6481e > "$ANDROID_HOME/licenses/android-sdk-license"

installsdk 'platforms;android-28'
}
170 changes: 129 additions & 41 deletions .circleci/config.yml
@@ -1,62 +1,150 @@
version: 2

jobs:
build:
working_directory: ~/squanchy
aliases:
# Build Tools cache aliases
- &restore-build-tools-cache
name: Restore Android build tools cache
keys:
- v3-build-tools-{{ checksum "workspace/repo/.circleci/config.yml" }}-{{ checksum "workspace/repo/gradle.properties" }}-{{ checksum "workspace/repo/dependencies.gradle" }}
- &save-build-tools-cache
name: Save Android build tools cache
paths:
- /opt/android/sdk/build-tools
key: v3-build-tools-{{ checksum "workspace/repo/.circleci/config.yml" }}-{{ checksum "workspace/repo/gradle.properties" }}-{{ checksum "workspace/repo/dependencies.gradle" }}

docker:
- image: circleci/android:api-27-alpha
# Gradle cache aliases
- &restore-gradle-cache
name: Restore Gradle cache
keys:
- v3-gradle-{{ checksum "workspace/repo/.circleci/config.yml" }}-{{ checksum "workspace/repo/gradle.properties" }}-{{ checksum "workspace/repo/dependencies.gradle" }}
- &save-gradle-cache
name: Save Gradle cache
paths:
- ~/.gradle/caches
- ~/.gradle/wrapper
key: v3-gradle-{{ checksum "workspace/repo/.circleci/config.yml" }}-{{ checksum "workspace/repo/gradle.properties" }}-{{ checksum "workspace/repo/dependencies.gradle" }}

environment:
ANDROID_HOME: /opt/android/sdk
APPLICATION_ID: net.squanchy.example
FABRIC_API_KEY: 0000000000000000000000000000000000000000
ALGOLIA_APPLICATION_ID: ABCDEFGH12
ALGOLIA_API_KEY: 00000000000000000000000000000000
# Android Gradle build cache aliases
- &restore-android-build-cache
name: Restore Android Gradle build cache
keys:
- v3-build-cache-{{ checksum "workspace/repo/.circleci/config.yml" }}-{{ checksum "workspace/repo/gradle.properties" }}-{{ checksum "workspace/repo/dependencies.gradle" }}
- &save-android-build-cache
name: Save Android Gradle build cache
paths:
- ~/.android/build-cache
key: v3-build-cache-{{ checksum "workspace/repo/.circleci/config.yml" }}-{{ checksum "workspace/repo/gradle.properties" }}-{{ checksum "workspace/repo/dependencies.gradle" }}

steps:
- checkout
- &ensure-android-sdk-is-ready
name: Ensure Android SDK install is up-to-date
command: workspace/repo/.circleci/ci-scripts/ensure-sdkmanager.sh

- &download-gradle-dependencies
name: Download Gradle dependencies
command: cd workspace/repo/ && ./gradlew downloadDependencies

circle_ci_android_container_config: &circle_ci_android_container_config
working_directory: ~/squanchy

docker:
- image: circleci/android:api-28-alpha

environment:
ANDROID_HOME: /opt/android/sdk
APPLICATION_ID: net.squanchy.example
FABRIC_API_KEY: 0000000000000000000000000000000000000000
ALGOLIA_APPLICATION_ID: ABCDEFGH12
ALGOLIA_API_KEY: 00000000000000000000000000000000

attach_workspace: &attach_workspace
attach_workspace:
at: workspace

# Restore cached dependencies (if any)
- restore_cache:
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
jobs:
checkout:
<<: *circle_ci_android_container_config
steps:
- checkout:
path: workspace/repo

# Prepare the container for the build
- run:
name: Ensure Android SDK install is up-to-date
command: .circleci/ci-scripts/ensure-sdkmanager.sh
- run: *ensure-android-sdk-is-ready
- run:
name: Create mock Play Services JSON
command: .circleci/ci-scripts/ci-mock-google-services-setup.sh
command: workspace/repo/.circleci/ci-scripts/ci-mock-google-services-setup.sh

# Run the main job commands, delegating to Gradle
# See https://issuetracker.google.com/issues/62217354 for the parallelism option
- run:
name: Run static analysis
command: ./gradlew evaluateViolations -Djava.util.concurrent.ForkJoinPool.common.parallelism=2
- run:
name: Run tests
command: ./gradlew testRelease -Djava.util.concurrent.ForkJoinPool.common.parallelism=2
# Persist repo code
- persist_to_workspace:
root: workspace
paths:
- repo

# Store all the downloaded dependencies in the CI cache
- save_cache:
prepare_for_checks:
<<: *circle_ci_android_container_config
steps:
- *attach_workspace
- restore_cache: *restore-gradle-cache
- restore_cache: *restore-android-build-cache
- restore_cache: *restore-build-tools-cache

- run: *download-gradle-dependencies

- save_cache: *save-android-build-cache
- save_cache: *save-gradle-cache
- save_cache: *save-build-tools-cache

# Persist built app code
- persist_to_workspace:
root: workspace
paths:
# Android SDK
- /usr/local/android-sdk-linux/tools
- /usr/local/android-sdk-linux/platform-tools
- /usr/local/android-sdk-linux/build-tools
- /usr/local/android-sdk-linux/licenses
- /usr/local/android-sdk-linux/extras/google/m2repository
- repo/app/build

# Gradle dependencies
- ~/.gradle
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
static_analysis:
<<: *circle_ci_android_container_config
steps:
- *attach_workspace
- restore_cache: *restore-gradle-cache
- restore_cache: *restore-android-build-cache
- restore_cache: *restore-build-tools-cache

# See https://issuetracker.google.com/issues/62217354 for the parallelism option
- run:
name: Run static analysis
command: cd workspace/repo && ./gradlew evaluateViolations -Djava.util.concurrent.ForkJoinPool.common.parallelism=2

# Collect static analysis reports as build artifacts
- store_artifacts:
path: app/build/reports
path: workspace/repo/app/build/reports
destination: reports

tests:
<<: *circle_ci_android_container_config
steps:
- *attach_workspace
- restore_cache: *restore-gradle-cache
- restore_cache: *restore-android-build-cache
- restore_cache: *restore-build-tools-cache

# See https://issuetracker.google.com/issues/62217354 for the parallelism option
- run:
name: Run unit tests
command: cd workspace/repo && ./gradlew testRelease -Djava.util.concurrent.ForkJoinPool.common.parallelism=2

# Collect JUnit test results
- store_test_results:
path: app/build/test-results
path: workspace/repo/app/build/test-results

workflows:
version: 2
build_and_test:
jobs:
- checkout
- prepare_for_checks:
requires:
- checkout
- static_analysis:
requires:
- prepare_for_checks
- tests:
requires:
- prepare_for_checks
1 change: 0 additions & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build.gradle
Expand Up @@ -51,3 +51,4 @@ subprojects {
}

apply from: teamPropsFile('setup-root-tasks.gradle')
apply from: teamPropsFile('warm-gradle-caches.gradle')
35 changes: 35 additions & 0 deletions team-props/warm-gradle-caches.gradle
@@ -0,0 +1,35 @@
// Adapted from: https://gist.github.com/matthiasbalke/3c9ecccbea1d460ee4c3fbc5843ede4a

task downloadDependencies {
dependsOn ':app:androidDependencies'
dependsOn 'app:dependencies'
doLast {
project.rootProject.allprojects.each { subProject ->
subProject.buildscript.configurations.each { configuration ->
resolveConfiguration(configuration)
}
subProject.configurations.each { configuration ->
resolveConfiguration(configuration)
}
}
}
}

private static void resolveConfiguration(configuration) {
if (isResolveableConfiguration(configuration)) {
configuration.resolve()
}
}

private static boolean isResolveableConfiguration(configuration) {
if (configuration.isCanBeResolved() == false) {
return false
}

def blacklistedConfigurations = [
'detekt', 'ktlint', 'apiElements', 'implementation', 'runtimeelements', 'runtimeonly', 'testimplementation', 'testruntimeonly',
'generatedimplementation', 'generatedruntimeonly', 'classpath'
]
def configurationName = configuration.name.toLowerCase(Locale.US)
return !blacklistedConfigurations.any { configurationName.contains(it) }
}