Caching on Bitrise Android

Caching on Bitrise Android

When using caching on Bitrise, you would use cache-pull&csche-push steps. In this talk I talked about how to use them and how we can customize to enable/disable caching using git command and envman tool.

F9856cc7a15ed2cb9e6ebfab41fdf1cf?s=128

Shohei Kawano

August 16, 2018
Tweet

Transcript

  1. Caching on Bitrise @shaunkawano

  2. git clone bitrise.yml
 (bitrise.io) bitrise.yml
 (in-repository)

  3. None
  4. Caching on Bitrise

  5. IUUQTEFWDFOUFSCJUSJTFJPDBDIJOHBCPVUDBDIJOH

  6. •Stored securely in Amazon S3 •Per specific branches •By default:

    will be deleted after 7 days without any build Caching on Bitrise
  7. IUUQTEFWDFOUFSCJUSJTFJPDBDIJOHBCPVUDBDIJOH

  8. IUUQTEFWDFOUFSCJUSJTFJPDBDIJOHBCPVUDBDIJOH Caching
 gradle & maven

  9. •cache-pull •Pull cache from remote server if available •cache-push •Check

    if cache needs to be updated •Upload the caching content if required Caching Steps
  10. cache-pull _prepare: title: Prepare fastlane steps: - script: inputs: -

    content: |- bundle install --path vendor/bundle - cache-pull: {}
  11. cache-pull _prepare: title: Prepare fastlane steps: - script: inputs: -

    content: |- bundle install --path vendor/bundle - cache-pull: {}
  12. cache-push _cache: title: Cache gradle and maven dependencies steps: -

    cache-push: inputs: - cache_paths: |- $HOME/.gradle ./.gradle $HOME/.m2 - ignore_check_on_paths: |- $HOME/.gradle/caches/*.lock ./.gradle/*.lock ./.gradle/*.bin
  13. cache-push _cache: title: Cache gradle and maven dependencies steps: -

    cache-push: inputs: - cache_paths: |- $HOME/.gradle ./.gradle $HOME/.m2 - ignore_check_on_paths: |- $HOME/.gradle/caches/*.lock ./.gradle/*.lock ./.gradle/*.bin
  14. Workflow test: title: Run unit test before_run: - _prepare after_run:

    - _cache steps: - script: inputs: - content: |- bundle exec fastlane test
  15. Workflow test: title: Run unit test before_run: - _prepare after_run:

    - _cache steps: - script: inputs: - content: |- bundle exec fastlane test
  16. None
  17. Try pushing library update

  18. Again, 
 cached gradle / maven data is used

  19. None
  20. Want to re-build if certain files are modified

  21. _parepareCacheEnv: title: Set environment variable if we can use cache

    or not steps: - script: inputs: - content: |- if [[ -n $(git diff-tree --no-commit-id —name-only -r $GIT_CLONE_COMMIT_HASH -- find -name 'versions.gradle' ‘app/build.gradle') ]] then envman add --key USE_CACHE --value "false" echo "_parepareCacheEnv result: USE_CACHE == false" else envman add --key USE_CACHE --value "true" echo "_parepareCacheEnv result: USE_CACHE == true" fi
  22. _parepareCacheEnv: title: Set environment variable if we can use cache

    or not steps: - script: inputs: - content: |- if [[ -n $(git diff-tree --no-commit-id —name-only -r $GIT_CLONE_COMMIT_HASH -- find -name 'versions.gradle' ‘app/build.gradle') ]] then envman add --key USE_CACHE --value "false" echo "_parepareCacheEnv result: USE_CACHE == false" else envman add --key USE_CACHE --value "true" echo "_parepareCacheEnv result: USE_CACHE == true" fi
  23. _parepareCacheEnv: title: Set environment variable if we can use cache

    or not steps: - script: inputs: - content: |- if [[ -n $(git diff-tree --no-commit-id —name-only -r $GIT_CLONE_COMMIT_HASH -- find -name 'versions.gradle' ‘app/build.gradle') ]] then envman add --key USE_CACHE --value "false" echo "_parepareCacheEnv result: USE_CACHE == false" else envman add --key USE_CACHE --value "true" echo "_parepareCacheEnv result: USE_CACHE == true" fi
  24. _parepareCacheEnv: title: Set environment variable if we can use cache

    or not steps: - script: inputs: - content: |- if [[ -n $(git diff-tree --no-commit-id —name-only -r $GIT_CLONE_COMMIT_HASH -- find -name 'versions.gradle' ‘app/build.gradle') ]] then envman add --key USE_CACHE --value "false" echo "_parepareCacheEnv result: USE_CACHE == false" else envman add --key USE_CACHE --value "true" echo "_parepareCacheEnv result: USE_CACHE == true" fi
  25. _parepareCacheEnv: title: Set environment variable if we can use cache

    or not steps: - script: inputs: - content: |- if [[ -n $(git diff-tree --no-commit-id —name-only -r $GIT_CLONE_COMMIT_HASH -- find -name 'versions.gradle' ‘app/build.gradle') ]] then envman add --key USE_CACHE --value "false" echo "_parepareCacheEnv result: USE_CACHE == false" else envman add --key USE_CACHE --value "true" echo "_parepareCacheEnv result: USE_CACHE == true" fi
  26. test: title: Run unit test before_run: - _parepareCacheEnv - _prepare

    after_run: - _cache steps: - script: inputs: - content: |- bundle exec fastlane test
  27. test: title: Run unit test before_run: - _parepareCacheEnv - _prepare

    after_run: - _cache steps: - script: inputs: - content: |- bundle exec fastlane test
  28. test: title: Run unit test before_run: - _parepareCacheEnv - _prepare

    after_run: - _cache steps: - script: inputs: - content: |- bundle exec fastlane test
  29. _prepare: title: Prepare fastlane steps: - script: inputs: - content:

    |- bundle install --path vendor/bundle - cache-pull: run_if: '{{getenv "USE_CACHE" | eq "true"}}'
  30. _prepare: title: Prepare fastlane steps: - script: inputs: - content:

    |- bundle install --path vendor/bundle - cache-pull: run_if: '{{getenv "USE_CACHE" | eq "true"}}'
  31. Bitrise re-built without cache successfully!

  32. None
  33. Summary

  34. •Use cache-pull & cache-push steps for enabling caching on Bitrise

    •Configuration may be required •Ask Bitrise team for help :) Summary
  35. Caching on Bitrise @shaunkawano Thank you!