Skip to content

Instantly share code, notes, and snippets.

@chan-bo
Created March 18, 2019 07:02
Show Gist options
  • Save chan-bo/00e5621df91027bffa80d88dac8af84c to your computer and use it in GitHub Desktop.
Save chan-bo/00e5621df91027bffa80d88dac8af84c to your computer and use it in GitHub Desktop.
version: 2
references:
workspace: &workspace
~/src
android_config: &android_config
working_directory: *workspace
docker:
- image: circleci/android:api-28-alpha
environment:
TERM: dumb
_JAVA_OPTIONS: "-Xmx2048m -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap"
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m"'
gradle_key: &gradle_key
jars-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
gem_key: &gems_key
gems-{{ checksum "Gemfile.lock" }}
restore_gradle_cache: &restore_gradle_cache
restore_cache:
key: *gradle_key
restore_gems_cache: &restore_gems_cache
restore_cache:
key: *gems_key
save_gradle_cache: &save_gradle_cache
save_cache:
key: *gradle_key
paths:
- ~/.gradle
- ~/.m2
save_gems_cache: &save_gems_cache
save_cache:
key: *gems_key
paths:
- vendor/bundle
ruby_dependencies: &ruby_dependencies
run:
name: Download Ruby Dependencies
command: |
gem install bundler
bundle check || bundle install --path vendor/bundle
android_dependencies: &android_dependencies
run:
name: Download Android Dependencies
command: ./gradlew androidDependencies
decode_android_key: &decode_android_key
run:
name: Decode Android key store
command: echo $KEYSTORE | base64 -d | tee keystore app/keystore > /dev/null
create_keystore_properties: &create_keystore_properties
run:
name: Create keystore.properties
command: printf 'releaseKeyAlias=%s\nreleaseKeyPassword=%s\nreleaseKeyStore=%s\nreleaseStorePassword=%s' \
$RELEASE_KEY_ALIAS $RELEASE_KEY_PASSWORD $RELEASE_KEYSTORE $RELEASE_STORE_PASSWORD > keystore.properties
create_google_play_key: &create_google_play_key
run:
name: Create Google Play Key
command: echo $GOOGLE_PLAY_KEY > google-play-key.json
jobs:
#Run Unit Test
test_unit:
<<: *android_config
steps:
- checkout
- *restore_gradle_cache
- *restore_gems_cache
- *ruby_dependencies
- *create_keystore_properties
- *decode_android_key
- *android_dependencies
- *save_gradle_cache
- *save_gems_cache
- run:
name: Run Unit Tests
command: bundle exec fastlane assemble_build build_flavor:$BUILD_FLAVOR build_type:$BUILD_TYPE
- store_artifacts:
path: app/build/reports
destination: /reports/
- store_test_results:
path: app/build/test-results
destination: /test-results
# Run UI Test
test_instrumentation:
<<: *android_config
steps:
- checkout
- *restore_gradle_cache
- *restore_gems_cache
- *ruby_dependencies
- *create_keystore_properties
- *decode_android_key
- *android_dependencies
- *save_gradle_cache
- *save_gems_cache
- run:
name: Run instrumentation tests in Firebase Testlab
command: bundle exec fastlane instrumentation_tests_testlab build_flavor:$BUILD_FLAVOR
- run:
name: Send Debug and Release Apk
command: |
bundle exec fastlane send_apk_to_slack build_flavor:"Dev" build_type:"Debug"
bundle exec fastlane send_apk_to_slack build_flavor:"Pro" build_type:"Release"
- store_artifacts:
path: app/build/outputs/apk
destination: /apk/
- store_artifacts:
path: firebase/
destination: /firebase/
beta_deployment:
<<: *android_config
steps:
- checkout
- *restore_gradle_cache
- *restore_gems_cache
- *ruby_dependencies
- *create_keystore_properties
- *decode_android_key
- *android_dependencies
- *save_gradle_cache
- *save_gems_cache
- *create_google_play_key
- run:
name: Deploy to Play Store
command: bundle exec fastlane beta
- store_artifacts:
path: app/build/outputs/mapping/
destination: /mapping/
# Deploy to google play store
release_deployment:
<<: *android_config
steps:
- checkout
- *restore_gradle_cache
- *restore_gems_cache
- *ruby_dependencies
- *create_keystore_properties
- *decode_android_key
- *android_dependencies
- *save_gradle_cache
- *save_gems_cache
- *create_google_play_key
- run:
name: Deploy to Play Store
command: bundle exec fastlane release
- store_artifacts:
path: app/build/outputs/mapping/
destination: /mapping/
workflows:
version: 2
workflow:
jobs:
- test_unit
- test_instrumentation:
requires:
- test_unit
- beta_deployment:
filters:
branches:
only:
- beta
requires:
- test_unit
- test_instrumentation
- release_deployment:
filters:
branches:
only:
- master
requires:
- test_unit
- test_instrumentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment