Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Everything of CI/CD in Kyash Android

Everything of CI/CD in Kyash Android

circleci japan meetup: mobile edition

85cab5fdf09afe3ee78ce3667681915a?s=128

Keisuke Kobayashi

August 20, 2017
Tweet

Transcript

  1. Everything of CI/CD in Kyash Android Keisuke Kobayashi / kobakei

    CircleCI Japan Meetup: Mobile Edition
  2. About me • Keisuke Kobayashi • GitHub, Qiita: kobakei •

    Twitter: kobakei122 • Kyash, Inc • Using CircleCI for 3+ years
  3. Kyash Android

  4. Kyash Android • Full Kotlin • About 40 activities +

    Bottom Navigation • Architecture • MVVM + Layered architecture • Library • Rx, Dagger, Data binding, Retrofit & OkHttp, Picasso, Orma, Gson
  5. Continuous Integration

  6. Testing • Unit testing • UI testing

  7. Testing • Unit testing • UI testing

  8. Unit testing • Robolectric + Mockito • No emulator =

    fast • Focus on ViewModel and Model. 
 Activity and Fragment are not target. • Easy to inject mock objects by Dagger 2 • Run by git push on Circle CI
  9. mockito-kotlin • mockito extension for Kotlin • `when` problem •

    NPE on any • Easy to read & write
  10. @Test fun doAction_doesSomething(){ /* Given */ val mock = mock<MyClass>

    { on { getText() } doReturn "text" } val classUnderTest = ClassUnderTest(mock) /* When */ classUnderTest.doAction() /* Then */ verify(mock).doSomething(any()) }
  11. jacoco-android-gradle-plugin • Add gradle tasks to run unit test and

    code coverage • Need to exclude classes generated by kapt • Data binding, ORM, Parcelable, etc • No badge now • Codecov, Coveralls
  12. ktlint-gradle • Coding style checker and formatter for Kotlin •

    Default style is official style from kotlinlang.org • Not same as Android Studio default setting • Override: ktlint —apply-to-idea • Run style check on Circle CI
  13. cookpad/license-tools-plugin • Generate license page by gradle task • Check

    licenses on Circle CI • Avoid missing license
  14. Testing • Unit testing • UI testing

  15. UI testing • Espresso + UI automator • Use Espresso

    basically • Use UI automator to OS/other app UI (ex. permission dialog) • Don’t run on CI due to long exec time • Run before release to confirm important flows don’t degrade • ex. Sign up flow
  16. Mock in UI testing • MockWebServer of Retrofit • Unlike

    Mockito, JSON parse can be tested • Share MockWebServer object between Application class and test classes • Change API response at every test case
  17. Firebase Test Lab • Still experimental • Run UI testing

    on OS x device matrix • In parallel • Video recording in testing • 5 or 10 tests/day in free plan • Run before release manually?
  18. Continuous Delivery

  19. Crashlytics • Share the latest apk to team • master

    branch = debug build • Development endpoint • Debug screen with debot • Deploy at every git push (10~ times / day) • release/1.2.3 branch = beta build • Production endpoint • Deploy at code freeze
  20. Google Play • gradle-play-publisher • Gradle wrapper of Google Play

    Developer API • Need to set up Google API console • Can publish as alpha, beta and staging rollout • Triggered by GitHub Release (git tag) • However CircleCI 2.0 doesn't support tag…
  21. Workaround • Add CircleCI 1.0 deployment block deployment: fake_deploy_for_cci2: tag:

    /.*/ commands: - echo "make tags run in 2.0"
  22. Version name and code // App version def versionMajor =

    1 def versionMinor = 11 def versionPatch = 2 // version code def vc = 0 if (System.getenv("CIRCLE_TAG") != null) { // tag = release build vc = versionMajor * 10000 + versionMinor * 100 + versionPatch } else if ("true" == System.getenv("CI")) { // no tag but CI = dev build vc = System.getenv("CIRCLE_BUILD_NUM") as Integer } else { // otherwise = local build vc = versionMajor * 10000 + versionMinor * 100 + versionPatch }
  23. CircleCI

  24. Like • Can start by free event if private repo

    • Many users • We can search YAML file on GitHub • Kind support • ex. Memory limit of my project has been increased before
  25. Dislike • OOM • Slow build • Official docs is

    still poor
  26. Dislike (CircleCI 2.0) • OOM Fixed? • Slow build Fixed

    • Official docs is still poor
  27. CircleCI 1.0 -> 2.0 Build time 60% down

  28. Breakdown (Total 5:30)

  29. Breakdown (Total 5:30) Unit testing Deploy

  30. I want… • Trigger by git tag • Firebase Test

    Lab on CircleCI 2.0 • Docs • There is only docs for CircleCI 1.0 • May need Docker image?
  31. Thanks!