Skip to content

Instantly share code, notes, and snippets.

@lordcodes
Created January 22, 2019 18:53
Show Gist options
  • Save lordcodes/65101116156a44b075ce2a126313b9c6 to your computer and use it in GitHub Desktop.
Save lordcodes/65101116156a44b075ce2a126313b9c6 to your computer and use it in GitHub Desktop.
Android Circle CI config involving workflows, caching and sharing the workspace between steps in workflow.
#!/usr/bin/env bash
# Accept licenses
${ANDROID_HOME}/tools/bin/sdkmanager --licenses
# Install dependencies
./gradlew androidDependencies || true
version: 2.0
references:
workspace_root: &workspace_root
~/workspace
container_config: &container_config
docker:
- image: circleci/android:api-28
working_directory: *workspace_root
environment:
TERM: dumb
JVM_OPTS: -Xmx4096m
attach_workspace: &attach_workspace
attach_workspace:
at: *workspace_root
general_cache_key: &general_cache_key
key: app-{{ checksum "build.gradle.kts" }}-{{ checksum "app/build.gradle.kts" }}-{{ checksum ".circleci/config.yml" }}-{{ checksum "gradle.properties" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
jobs:
build:
<<: *container_config
steps:
- checkout
- restore_cache:
<<: *general_cache_key
- run:
name: Setup environment
command: scripts/ci-setup.sh
- save_cache:
<<: *general_cache_key
paths:
- "~/.gradle"
- "~/.m2"
- "/opt/android-sdk-linux/licenses/"
- run:
name: Build
command: ./gradlew assembleDebug
- store_artifacts:
path: app/build/outputs/apk/
destination: apks/
- persist_to_workspace:
root: *workspace_root
paths:
- .
check:
<<: *container_config
steps:
- *attach_workspace
- restore_cache:
<<: *general_cache_key
- run:
name: Run checks
command: ./gradlew lintDebug ktlintCheck
- store_artifacts:
path: app/build/reports/
destination: lint_reports/app/
test:
<<: *container_config
steps:
- *attach_workspace
- restore_cache:
<<: *general_cache_key
- run:
name: Run tests
command: ./gradlew testDebugUnitTest
- store_artifacts:
path: app/build/reports/tests/
destination: tests_reports/
- store_test_results:
path: app/build/test-results
workflows:
version: 2
build_check_tests:
jobs:
- build
- check:
requires:
- build
- test:
requires:
- build
@Bhavnaharitsa
Copy link

Should the circle ci directory have 2 files
one - config.yml
two-ci-setup.sh ?
Kindly reply

@anandtrojan
Copy link

Should the circle ci directory have 2 files
one - config.yml
two-ci-setup.sh ?
Kindly reply

file location is your choice. Here I feel dev has a script folder where he is keeping all his scripts. If you want to put it in .cricleci folder then change scripts/ci-setup.sh to ./.circleci/ci-setup.sh at line 36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment