grab / cocoapods-binary-cache

MIT License
478 stars 69 forks source link

Support diversified remote cache with hash value(like PODFILE CHECKSUM in Podfile.lock) #86

Closed wooseongkim-29cm closed 1 year ago

wooseongkim-29cm commented 3 years ago

Checklist

Description

(Related Issue : https://github.com/grab/cocoapods-binary-cache/issues/46)

Remote cache is very useful to sync pods among developer machines & build machines, but there is a problem when we needs various cache.

Swift versions can be various(like 5.3.1 & 5.4), Pod composition or prebuild setup can be various between master and other branches. That's why we needs diversified remote caches for seamless adoption of this library for multi environment and machines.

actions/cache in GitHub Actions support this feature with key like below and it's useful.

- name: Cache Ruby Dependencies
  uses: actions/cache@v2.1.3
  id: ruby-bundle-cache-step
  with:
    path: ruby-bundle-cache
    key: ${{ env.machine_name }}-${{ env.ruby_version }}-ruby-bundle-cache-${{ hashFiles('Gemfile.lock') }}

With this change, user programmers can cache specific state with composited key with hash value like PODFILE CHECKSUM in Podfile.lock which is used for remote branch name like below:

# Makefile

# Mostly for build machine
project:
  make xcodegen_generate
  make pod_install

# For daily development for developer
project_fast:
  make xcodegen_generate
  bundle exec pod install

...

podfile_lock_checksum:
  @echo `grep "PODFILE CHECKSUM: " Podfile.lock | awk '{print $$3}'`

# Need to execute on Podfile changes
# Branch name would be 'swift5.4-PODFILE_CHECKSUM'
pod_install:
  bundle exec pod binary prebuild "swift$$(make swift_version)-$$(make podfile_lock_checksum)" --no-fetch # Previous CHECKSUM
  bundle exec pod binary fetch "swift$$(make swift_version)-$$(make podfile_lock_checksum)" # Needs to create new branch if needed (I found `pod binary fetch` handle this)
  bundle exec pod binary push "swift$$(make swift_version)-$$(make podfile_lock_checksum)" # with new CHECKSUM if it is changed after prebuild

...

Changes

wooseongkim-29cm commented 3 years ago

@trinhngocthuyen It would be grateful if you review this when you available 🙏