Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dependency Cache] Dependency Cache on CI per Project [without GRADLE_RO_DEP_CACHE] #135

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from

Conversation

ParaskP7
Copy link

@ParaskP7 ParaskP7 commented Dec 19, 2024

Project Thread: paaHJt-7CE-p2
Related: #134 + buildkite-ci#570
(Softly) Depends On:

Description

This change:

  1. Adds a project prefix (BUILDKITE_PIPELINE_SLUG) to the existing gradle dependency cache key to enable dependency cache per project. (3b051ba)
  2. Enhances save_cache and restore_cache logging by:
    1. Echoing how long it takes to save/restore the cache. (f777f02)
    2. Echoing the (un)compressed cache size during save/restore. (938009b + fb579e8)
  3. Replaces the read-only GRADLE_RO_DEP_CACHE dependency cache mechanism (using the $GRADLE_HOME/read-only-dependency-cache directory), with the more basic GRADLE_DEP_CACHE dependency cache mechanism (using $GRADLE_HOME/dependency-cache directory), for save/restore. (61b1d9d)
  4. Adds a version suffix (V2) to the existing gradle dependency cache key to differentiate between the two, the previous GRADLE_RO_DEP_CACHE and the new GRADLE_DEP_CACHE dependency cache mechanisms. This was purely done for testing purposes, but I think it might be wise for us to keep this versioning system in place, just in case we update the mechanism again in the future and want to effectively test, then utilize that new change. PS: I am very open to feedback on that. (94d9f7a)

Note

Enhancing the save_cache and restore_cache scripts (2.) will positively affect all clients of these scripts, mainly improve things by logging some more information. But, do think if there is going to be a case when these changes might negatively effect some or all those other clients (`I couldn't).


Testing Instructions

This GRADLE_DEP_CACHE version of a8c-ci-toolkit was thoroughly tested via the below test-only PRs, via the help of the android-staging agents (see buildkite-ci#570):

To help you assessing that this change is safe use to use and will not cause any trouble for any project, try and follow the below:

Note

The GRADLE_RO_DEP_CACHE version of a8c-ci-toolkit was also tested via the below test-only PRs:


Merge Instructions

Note

These WCAndroid#13288 + FluxC#3125 + ADC#39 PRs are not necessarily needed prior to merging this change, but it is better to clean things up and avoid any confusion with relation to having save/restore working on client/libraries projects, while it is actually not (and shouldn't be as of yet).


  • I have considered if this change warrants release notes and have added them to the appropriate section in the CHANGELOG.md if necessary.

@dangermattic
Copy link

dangermattic commented Dec 19, 2024

1 Error
🚫 This PR is tagged with do not merge label(s).
1 Warning
⚠️ Please add an entry in the CHANGELOG.md file to describe the changes made by this PR

Generated by 🚫 Danger

@ParaskP7 ParaskP7 force-pushed the gradle/isolate-dependency-cache-per-project-v2 branch 9 times, most recently from 5fef742 to 84a1cb6 Compare December 20, 2024 15:20
This is done in order to avoid having each client project adding its own
project prefix to distinguish the Gradle dependency cache key.

Test Only PRs:
- WCAndroid: https://github.com/woocommerce/woocommerce-android/
pull/13122
- JP/WPAndroid: https://github.com/wordpress-mobile/WordPress-Android/
pull/21540

For example, for WCAndroid, this would mean that instead of using this
'WOOCOMMERCE' value via this 'GRADLE_DEPENDENCY_CACHE_PROJECT_PREFIX'
environment variable, which ultimately is creating the below
'WOOCOMMERCE_GRADLE_DEPENDENCY_CACHE' key, instead, with this change the
'woocommerce-android_GRADLE_DEPENDENCY_CACHE' key will be
automatically created, taking the 'woocommerce-android' value from the
standard 'BUILDKITE_PIPELINE_SLUG' environment variable.

For more info see: p1734350857095859-slack-C020Q0Z579V
This is done in order for us to be able to output the uncompressed cache
size during cache restoration, just as it is being done during the cache
saving process, for consistency purposes.

But, given the fact that are also other clients of this 'restore_cache'
script, keeping this parameter optional was the preferred approach in
order to not affect, or need to update, any of those other clients of
this specific script.
1. On saving, the script will create a new folder, within the
'GRADLE_HOME' space, named 'dependency-cache', where all the contents
from 'caches/modules-2' will be copied after the build finishes
(minus '*.lock' and 'gc.properties' files, as per the documentation).
2. On restoring, the script will create the 'caches/modules-2' folder,
within the 'GRADLE_HOME' space, and extract the saved contents into it
and before the build starts.
3. On restoring, the script will also check if 'modules-2' directory
exists prior to placing cache. This check is necessary because during
'restore_cache' it might happen that the dependency cache based on this
key is not available for download. Thus, no 'dependency-cache/module-2'
folder will exist to be copied into the 'caches/modules-2' folder, which
will break the script.
This is done in order to differentiate between the 'GRADLE_RO_DEP_CACHE'
and the 'GRADLE_DEP_CACHE' caches, and thus be able to test both caching
strategies in-parallel, without one overwriting the other during save,
or one reusing the other's cache during restore.

Test Only PRs:
- WCAndroid: https://github.com/woocommerce/woocommerce-android/
pull/13170
- JP/WPAndroid: https://github.com/wordpress-mobile/WordPress-Android/
pull/21550
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants