Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
Adding a basic circleci config. (#73)
Browse files Browse the repository at this point in the history
* Adding a basic circleci config.

* Optimizations.
  • Loading branch information
Blahartinger committed Oct 24, 2019
1 parent 04a6861 commit eee0242
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 12 deletions.
104 changes: 104 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
version: 2.1
executors:
kin-executor:
working_directory: ~/code
docker:
- image: circleci/android:api-28
resource_class: xlarge
environment:
JVM_OPTS: -Xmx3200m

references:
gradle_key: &gradle_key
jars-{{ checksum "build.gradle" }}-{{ checksum "kin-backup-and-restore/kin-backup-and-restore-lib/build.gradle" }}-{{ checksum "kin-backup-and-restore/kin-backup-and-restore-sample/build.gradle" }}-{{ checksum "kin-backup-and-restore/kin-backup-and-restore-ui-tests/build.gradle" }}-{{ checksum "kin-sdk/kin-base/build.gradle" }}-{{ checksum "kin-sdk/kin-sdk-lib/build.gradle" }}-{{ checksum "kin-sdk/kin-sdk-sample/build.gradle" }}

restore_gradle_cache: &restore_gradle_cache
restore_cache:
key: *gradle_key

save_gradle_cache: &save_gradle_cache
save_cache:
key: *gradle_key
paths:
- ~/.gradle
- ~/.m2

android_dependencies: &android_dependencies
run:
name: Download Android Dependencies
command: ./gradlew androidDependencies

gcloud_init: &gcloud_init
run:
name: gcloud Init
command: |
./scripts/ci_gcloud_init.sh
jobs:
build:
executor: kin-executor
steps:
- checkout
- *restore_gradle_cache
- *android_dependencies
- *save_gradle_cache
- run:
name: Assemble
command: ./gradlew assemble

unit_and_integration_test:
executor: kin-executor
steps:
- checkout
- *restore_gradle_cache
- *android_dependencies
- *save_gradle_cache
- run:
name: Run Unit & Integration Tests
command: ./gradlew testDebugUnitTest jacocoTestReport

android_tests_sdk_lib:
executor: kin-executor
steps:
- checkout
- *restore_gradle_cache
- *android_dependencies
- *save_gradle_cache
- *gcloud_init
- run:
name: Run kin-sdk-lib Android Tests
command: ./scripts/ci_android_test_with_firebase.sh kin-sdk kin-sdk-sample kin-sdk-lib 2

android_tests_backup_and_restore:
executor: kin-executor
steps:
- checkout
- *restore_gradle_cache
- *android_dependencies
- *save_gradle_cache
- *gcloud_init
- run:
name: Run kin-backup-and-restore-lib Android Tests
command: ./scripts/ci_android_test_with_firebase.sh kin-backup-and-restore kin-backup-and-restore-sample kin-backup-and-restore-lib 0

ui_autormator_tests:
executor: kin-executor
steps:
- checkout
- *restore_gradle_cache
- *android_dependencies
- *save_gradle_cache
- *gcloud_init
- run:
name: Run kin-backup-and-restore-ui-tests Ui Automator Tests
command: ./scripts/ci_android_test_with_firebase.sh kin-backup-and-restore kin-backup-and-restore-ui-tests kin-backup-and-restore-ui-tests 0

workflows:
version: 2
build-sdk:
jobs:
- build
- unit_and_integration_test
- android_tests_backup_and_restore
- android_tests_sdk_lib
- ui_autormator_tests
File renamed without changes.
Binary file removed firebase-test-lab-key.json.enc
Binary file not shown.
15 changes: 3 additions & 12 deletions scripts/ci_android_test_with_firebase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,8 @@ set -x
./gradlew :$1:$2:assembleDebug
# Build android tests apk
./gradlew :$1:$3:assembleAndroidTest
# decrypt firebase credentials
openssl aes-256-cbc -K $encrypted_ea088b084227_key -iv $encrypted_ea088b084227_iv -in firebase-test-lab-key.json.enc -out firebase-test-lab-key.json -d
# download and extract google cloud sdk, if wasn't cache yet.
if [ ! -f ./google-cloud-sdk/bin/gcloud ]; then
wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-241.0.0-linux-x86_64.tar.gz
tar xf google-cloud-sdk-241.0.0-linux-x86_64.tar.gz
fi
./google-cloud-sdk/bin/gcloud config set project ${FIREBASE_PROJECT_NAME}
./google-cloud-sdk/bin/gcloud auth activate-service-account --key-file firebase-test-lab-key.json
# use travis job number as an unique value, for the folder that firebase will save coverage files
coverageDir=kin-sdk-android-${TRAVIS_JOB_NUMBER}
# use circle job number as an unique value, for the folder that firebase will save coverage files
coverageDir=kin-sdk-android-${CIRCLE_BUILD_NUM}
# run tests with firebase, generate coverage file (.ec) and upload it to "coverageDir" in google cloud storage
./google-cloud-sdk/bin/gcloud firebase test android run --type instrumentation --app $1/$2/build/outputs/apk/debug/$2-debug.apk --test $1/$3/build/outputs/apk/androidTest/debug/$3-debug-androidTest.apk --device model=Nexus5X,version=25,locale=en --no-record-video --no-performance-metrics --num-flaky-test-attempts=$4 --environment-variables coverage=true,coverageFile="/sdcard/coverage.ec" --directories-to-pull /sdcard --results-dir ${coverageDir}
## extract the .ec file name from google cloud
Expand All @@ -28,4 +19,4 @@ echo ${coverageFile}
# copy it locally to our lib build folder
./google-cloud-sdk/bin/gsutil cp $coverageFile $1/$3/build
# jacocoTestReport task will convert .ec file to jacoco format that codecov recognize, codecove will collect those files at the "after script" stage
./gradlew :$1:$3:jacocoTestReport
./gradlew :$1:$3:jacocoTestReport
8 changes: 8 additions & 0 deletions scripts/ci_gcloud_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
# download and extract google cloud sdk, if wasn't cache yet.
if [ ! -f ./google-cloud-sdk/bin/gcloud ]; then
wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-241.0.0-linux-x86_64.tar.gz
tar xf google-cloud-sdk-241.0.0-linux-x86_64.tar.gz
fi
echo $FIREBASE_KEY_FILE | ./google-cloud-sdk/bin/gcloud auth activate-service-account --key-file=-
./google-cloud-sdk/bin/gcloud --quiet config set project ${FIREBASE_PROJECT_NAME}

0 comments on commit eee0242

Please sign in to comment.