-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Separate CircleCI cache between main
and pull
or other branches
#24886
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,11 @@ def __post_init__(self): | |
def to_dict(self): | ||
env = COMMON_ENV_VARIABLES.copy() | ||
env.update(self.additional_env) | ||
|
||
cache_branch_prefix = os.environ.get("CIRCLE_BRANCH", "pull") | ||
if cache_branch_prefix != "main": | ||
cache_branch_prefix = "pull" | ||
|
||
job = { | ||
"working_directory": self.working_directory, | ||
"docker": self.docker_image, | ||
|
@@ -101,16 +106,21 @@ def to_dict(self): | |
{ | ||
"restore_cache": { | ||
"keys": [ | ||
f"v{self.cache_version}-{self.cache_name}-pip-" + '{{ checksum "setup.py" }}', | ||
f"v{self.cache_version}-{self.cache_name}-pip-", | ||
# check the fully-matched cache first | ||
f"v{self.cache_version}-{self.cache_name}-{cache_branch_prefix}-pip-" + '{{ checksum "setup.py" }}', | ||
# try the partially-matched cache from `main` | ||
f"v{self.cache_version}-{self.cache_name}-main-pip-", | ||
Comment on lines
+111
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to We can be confident to use the cache used in |
||
# try the general partially-matched cache | ||
f"v{self.cache_version}-{self.cache_name}-{cache_branch_prefix}-pip-", | ||
] | ||
} | ||
}, | ||
{ | ||
"restore_cache": { | ||
"keys": [ | ||
f"v{self.cache_version}-{self.cache_name}-site-packages-" + '{{ checksum "setup.py" }}', | ||
f"v{self.cache_version}-{self.cache_name}-site-packages-", | ||
f"v{self.cache_version}-{self.cache_name}-{cache_branch_prefix}-site-packages-" + '{{ checksum "setup.py" }}', | ||
f"v{self.cache_version}-{self.cache_name}-main-site-packages-", | ||
f"v{self.cache_version}-{self.cache_name}-{cache_branch_prefix}-site-packages-", | ||
] | ||
} | ||
}, | ||
|
@@ -119,15 +129,15 @@ def to_dict(self): | |
steps.append( | ||
{ | ||
"save_cache": { | ||
"key": f"v{self.cache_version}-{self.cache_name}-pip-" + '{{ checksum "setup.py" }}', | ||
"key": f"v{self.cache_version}-{self.cache_name}-{cache_branch_prefix}-pip-" + '{{ checksum "setup.py" }}', | ||
"paths": ["~/.cache/pip"], | ||
} | ||
} | ||
) | ||
steps.append( | ||
{ | ||
"save_cache": { | ||
"key": f"v{self.cache_version}-{self.cache_name}-site-packages-" + '{{ checksum "setup.py" }}', | ||
"key": f"v{self.cache_version}-{self.cache_name}-{cache_branch_prefix}-site-packages-" + '{{ checksum "setup.py" }}', | ||
"paths": ["~/.pyenv/versions/"], | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far I only worked on
.circleci/create_circleci_config.py
.For
.circleci/config.yml
, it needs somehow a bit more work (as it's not a python file)