Skip to content

Instantly share code, notes, and snippets.

@azisuazusa
Last active August 26, 2019 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azisuazusa/1aefd748bd0927dd3a4e934436710b2d to your computer and use it in GitHub Desktop.
Save azisuazusa/1aefd748bd0927dd3a4e934436710b2d to your computer and use it in GitHub Desktop.
version: 2
orbs:
slack: circleci/slack@3.2.0
references:
## Workspaces
workspace: &workspace
~/src
## Docker image configurations
android_config: &android_config
working_directory: *workspace
docker:
- image: circleci/android:api-28
environment:
JVM_OPTS: "-Xmx64m"
## Cache
gradle_key: &gradle_key
jars-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "build.gradle" }}-{{ checksum "MobileUI/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
commands:
android_dependencies:
description: "Download Android Dependencies"
steps:
- run:
name: "Download Android Dependencies"
command: ./gradlew androidDependencies
build:
description: "Build APK"
parameters:
is-production:
type: boolean
default: false
steps:
- when:
condition: << parameters.is-production >>
steps:
- run:
name: "Build Production"
command: ./gradlew clean assembleProductionRelease --no-daemon --stacktrace
- store_artifacts:
path: MobileUI/production/release/MobileUI-production-release.apk
destination: Kitabisa-Production.apk
- unless:
condition: << parameters.is-production >>
steps:
- run:
name: "Build Staging"
command: ./gradlew clean assembleStagingDebug --no-daemon --stacktrace
- store_artifacts:
path: MobileUI/build/outputs/apk/staging/debug/MobileUI-staging-debug.apk
destination: Kitabisa-Staging.apk
decode_keystore:
description: "Decode Keystore"
steps:
- run:
name: "Decode Keystore"
command: echo $ENCODED_KEYSTORE | base64 --decode >> ${HOME}/src/kitabisa-key.keystore
- run:
name: "Set Environment Variable for Keystore"
command: echo 'export KEYSTORE=${HOME}/src/kitabisa-key.keystore' >> $BASH_ENV
unit_test:
description: "Run Unit Test"
steps:
- run:
name: "Run Unit Tests"
command: ./gradlew test
- run:
name: "Save test results"
command: |
mkdir -p ~/test-results/junit/
find . -type f -regex ".*/build/test-results/.*xml" -exec cp {} ~/test-results/junit/ \;
when: always
- store_test_results:
path: ~/test-results
- store_artifacts:
path: ~/test-results/junit
jobs:
dependencies:
<<: *android_config
steps:
- checkout
- *restore_gradle_cache
- android_dependencies
- *save_gradle_cache
deploy_beta_staging:
<<: *android_config
steps:
- checkout
- *restore_gradle_cache
- build
- run:
name: "Deploy Staging to Fabric 🎉🎉"
command: ./gradlew crashlyticsUploadDistributionStagingDebug --stacktrace --debug --no-daemon
deploy_beta_production:
<<: *android_config
steps:
- checkout
- *restore_gradle_cache
- decode_keystore
- build:
is-production: true
- run:
name: "Deploy Production to Fabric 🎉🎉"
command: ./gradlew crashlyticsUploadDistributionProductionRelease --stacktrace --debug --no-daemon
publish_to_playstore:
<<: *android_config
steps:
- checkout
- *restore_gradle_cache
- decode_keystore
- run:
name: "Decode Deployment Private Key"
command: echo $ENCODED_DEPLOYMENT_PRIVATE_KEY | base64 --decode >> ${HOME}/src/deployment_private_key.json
- run:
name: "Set Environtment Variable for Deployment Private Key"
command: echo 'export DEPLOYMENT_PRIVATE_KEY=${HOME}/src/deployment_private_key.json' >> $BASH_ENV
- build:
is-production: true
- run:
name: "Upload to Google Play"
command: ./gradlew publishProductionReleaseApk
run_unit_test:
<<: *android_config
steps:
- checkout
- *restore_gradle_cache
- unit_test
workflows:
version: 2.0
workflow:
jobs:
- dependencies
- run_unit_test:
requires:
- dependencies
- deploy_beta_staging:
requires:
- dependencies
filters:
branches:
ignore:
- develop
- master
- hotfix
- deploy_beta_production:
requires:
- dependencies
filters:
branches:
only:
- develop
- hotfix
- publish_to_playstore:
requires:
- dependencies
filters:
branches:
only:
- master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment